mirror of
https://github.com/twofas/2fas-ios.git
synced 2024-11-22 18:29:56 +01:00
[TF-1592] add notificationsURL
This commit is contained in:
parent
41e3780f2c
commit
278b39f475
@ -29,6 +29,7 @@ public enum Config {
|
||||
|
||||
public enum API {
|
||||
public static let baseURL = URL(string: "https://api2.2fas.com")!
|
||||
public static let notificationsURL = URL(string: "https://notifications.2fas.com")!
|
||||
}
|
||||
|
||||
public enum TokenConsts {
|
||||
|
@ -45,7 +45,10 @@ final class MainRepositoryImpl: MainRepository {
|
||||
let userDefaultsRepository: UserDefaultsRepository
|
||||
let storageRepository: StorageRepository
|
||||
let logDataChange: LogDataChange
|
||||
let networkStack = NetworkStack(baseURL: Config.API.baseURL)
|
||||
let networkStack = NetworkStack(
|
||||
baseURL: Config.API.baseURL,
|
||||
notificationsBaseURL: Config.API.notificationsURL
|
||||
)
|
||||
let iconDatabase: IconDescriptionDatabase = IconDescriptionDatabaseImpl()
|
||||
let serviceDefinitionDatabase: ServiceDefinitionDatabase = ServiceDefinitionDatabaseImpl()
|
||||
let iconDescriptionDatabase: IconDescriptionDatabase = IconDescriptionDatabaseImpl()
|
||||
|
@ -25,6 +25,7 @@ final class NetworkCall {
|
||||
var noError: (() -> Void)?
|
||||
|
||||
private let baseURL: URL
|
||||
private let notificationsBaseURL: URL
|
||||
private let jsonDecoder: JSONDecoder = {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||
@ -60,8 +61,9 @@ final class NetworkCall {
|
||||
}()
|
||||
private let session: URLSession
|
||||
|
||||
init(baseURL: URL) {
|
||||
init(baseURL: URL, notificationsBaseURL: URL) {
|
||||
self.baseURL = baseURL
|
||||
self.notificationsBaseURL = notificationsBaseURL
|
||||
self.session = URLSession(configuration: configuration)
|
||||
}
|
||||
|
||||
@ -80,6 +82,21 @@ final class NetworkCall {
|
||||
}
|
||||
}
|
||||
|
||||
func handleNotificationsCall<T: Decodable>(
|
||||
with request: NetworkRequestFormat,
|
||||
completion: @escaping (Result<T, NetworkError>) -> Void
|
||||
) {
|
||||
queue.async { [weak self] in
|
||||
guard let self else { return }
|
||||
let dataTask = self.session.dataTask(
|
||||
with: self.notificationsUrlRequest(for: request)
|
||||
) { [weak self] data, response, error in
|
||||
self?.completionHandler(data, response as? HTTPURLResponse, error, completion: completion)
|
||||
}
|
||||
dataTask.resume()
|
||||
}
|
||||
}
|
||||
|
||||
func handleCall(with request: NetworkRequestFormat, completion: @escaping (Result<Void, NetworkError>) -> Void) {
|
||||
queue.async { [weak self] in
|
||||
guard let self else { return }
|
||||
@ -247,6 +264,17 @@ private extension NetworkCall {
|
||||
return urlRequest
|
||||
}
|
||||
|
||||
func notificationsUrlRequest(for request: NetworkRequestFormat) -> URLRequest {
|
||||
let path = notificationsBaseURL.absoluteString + "/" + request.path
|
||||
guard
|
||||
let url = URL(string: path)
|
||||
else { fatalError("Network Stack: Can't create path for url: \(request.path)") }
|
||||
var urlRequest = URLRequest(url: url)
|
||||
urlRequest.httpMethod = request.method.rawValue
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
|
||||
func urlRequest<P: Encodable>(for request: NetworkRequestFormat, data: P) -> URLRequest {
|
||||
let path = baseURL.absoluteString + "/" + request.path
|
||||
guard
|
||||
|
@ -28,8 +28,11 @@ public final class NetworkStack {
|
||||
private let appVersionHandler = AppVersionHandler()
|
||||
private let networkHandler: NetworkStackRepositoryImpl
|
||||
|
||||
public init(baseURL: URL) {
|
||||
networkHandler = NetworkStackRepositoryImpl(baseURL: baseURL)
|
||||
public init(baseURL: URL, notificationsBaseURL: URL) {
|
||||
networkHandler = NetworkStackRepositoryImpl(
|
||||
baseURL: baseURL,
|
||||
notificationsBaseURL: notificationsBaseURL
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,11 @@ import Foundation
|
||||
public final class NetworkStackRepositoryImpl {
|
||||
private let platform = "ios"
|
||||
private let networkCall: NetworkCall
|
||||
init(baseURL: URL) {
|
||||
self.networkCall = NetworkCall(baseURL: baseURL)
|
||||
init(baseURL: URL, notificationsBaseURL: URL) {
|
||||
self.networkCall = NetworkCall(
|
||||
baseURL: baseURL,
|
||||
notificationsBaseURL: notificationsBaseURL
|
||||
)
|
||||
networkCall.sslError = {
|
||||
NotificationCenter.default.post(name: .SSLNetworkErrorNotificationKey, object: nil)
|
||||
}
|
||||
@ -134,7 +137,7 @@ extension NetworkStackRepositoryImpl: NetworkStackRepository {
|
||||
completion: @escaping (Result<[ListNews.NewsEntry], NetworkError>) -> Void
|
||||
) {
|
||||
let req = ListNews.Request(platform: "ios", publishedAfter: publishedAfter)
|
||||
networkCall.handleCall(with: req, completion: completion)
|
||||
networkCall.handleNotificationsCall(with: req, completion: completion)
|
||||
}
|
||||
|
||||
public func uploadLogs(
|
||||
|
@ -26,7 +26,10 @@ import Protection
|
||||
import TimeVerification
|
||||
|
||||
final class MainRepositoryImpl {
|
||||
let network = NetworkStack(baseURL: Config.API.baseURL)
|
||||
let network = NetworkStack(
|
||||
baseURL: Config.API.baseURL,
|
||||
notificationsBaseURL: Config.API.notificationsURL
|
||||
)
|
||||
let protectionModule = Protection()
|
||||
let storageRepository: StorageRepository
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user