Files
1f067df924 Create request (#2466)
* Create request

* GH-2460 WIP: fetch mocked response with fake sender

* GH-2460 Only mock async call

* GH-2460 Better comment

* GH-2460 Only async method is mocked

* GH-2460 typo

* GH-2460 Use String as an Error

Co-authored-by: Dirk Jäckel <[email protected]>
2022-07-14 23:09:08 +02:00

41 lines
1.3 KiB
Swift

//
// SafeClientGatewayService.swift
// Multisig
//
// Created by Dmitry Bespalov on 13.08.20.
// Copyright © 2020 Gnosis Ltd. All rights reserved.
//
import Foundation
class SafeClientGatewayService {
var url: URL
private let httpClient: JSONHTTPClient
private let mockHttpClient: MockJSONHttpClient
var jsonDecoder: JSONDecoder {
httpClient.jsonDecoder
}
init(url: URL, logger: Logger) {
self.url = url
httpClient = JSONHTTPClient(url: url, logger: logger)
httpClient.jsonDecoder.dateDecodingStrategy = .millisecondsSince1970
mockHttpClient = MockJSONHttpClient()
}
@discardableResult
func execute<T: JSONRequest>(request: T) throws -> T.ResponseType {
try httpClient.execute(request: request)
}
func asyncExecute<T: JSONRequest>(request: T, completion: @escaping (Result<T.ResponseType, Error>) -> Void) -> URLSessionTask? {
httpClient.asyncExecute(request: request, completion: completion)
}
// Returns mocked response in completion
func asyncExecuteMock<T: JSONRequest>(request: T, completion: @escaping (Result<T.ResponseType, Error>) -> Void) -> URLSessionTask? {
mockHttpClient.asyncExecute(request: request, completion: completion)
}
}