From 86c62fcff78f3d5e615f24e1449fe22950274f89 Mon Sep 17 00:00:00 2001 From: Robin Malhotra Date: Mon, 11 Feb 2019 11:51:07 +0530 Subject: [PATCH 1/4] Make URLSession injectable into `Networking` for easy mocking. Signed-off-by: Robin Malhotra --- Sources/Networking.swift | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Sources/Networking.swift b/Sources/Networking.swift index 69547da..be70c49 100644 --- a/Sources/Networking.swift +++ b/Sources/Networking.swift @@ -34,24 +34,15 @@ public final class Networking: NSObject, URLSessionDelega promise.resolve(Void()) } - let sessionConfiguration: SessionConfiguration let mockProvider: MockProvider? let queue: OperationQueue + let session: URLSession + var customHeaders = [String: String]() var requestStorage = RequestStorage() var mode: NetworkingMode = .async - weak var sessionDelegate: URLSessionDelegate? - - lazy var session: URLSession = { [unowned self] in - let session = URLSession( - configuration: self.sessionConfiguration.value, - delegate: self.sessionDelegate ?? self, - delegateQueue: nil) - return session - }() - var requestHeaders: [String: String] { var headers = customHeaders headers["Accept-Language"] = Header.acceptLanguage @@ -68,12 +59,10 @@ public final class Networking: NSObject, URLSessionDelega public init(mode: NetworkingMode = .async, mockProvider: MockProvider? = nil, - sessionConfiguration: SessionConfiguration = SessionConfiguration.default, - sessionDelegate: URLSessionDelegate? = nil) { + session: URLSession = .shared) { self.mockProvider = mockProvider - self.sessionConfiguration = sessionConfiguration - self.sessionDelegate = sessionDelegate queue = OperationQueue() + self.session = session super.init() reset(mode: mode) } From 8514f5dad19f687889567827095ab561dff054c6 Mon Sep 17 00:00:00 2001 From: Robin Malhotra Date: Tue, 19 Feb 2019 15:14:37 +0530 Subject: [PATCH 2/4] Add initializers for `URLSession` and `SessionConfiguration` Signed-off-by: Robin Malhotra --- Sources/Networking.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/Networking.swift b/Sources/Networking.swift index be70c49..c4c0dd7 100644 --- a/Sources/Networking.swift +++ b/Sources/Networking.swift @@ -59,7 +59,7 @@ public final class Networking: NSObject, URLSessionDelega public init(mode: NetworkingMode = .async, mockProvider: MockProvider? = nil, - session: URLSession = .shared) { + session: URLSession) { self.mockProvider = mockProvider queue = OperationQueue() self.session = session @@ -67,6 +67,16 @@ public final class Networking: NSObject, URLSessionDelega reset(mode: mode) } + public init(mode: NetworkingMode = .async, + mockProvider: MockProvider? = nil, + configuration: SessionConfiguration = .default) { + self.mockProvider = mockProvider + queue = OperationQueue() + self.session = URLSession(configuration: configuration.value) + super.init() + reset(mode: mode) + } + public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling var credential: URLCredential? From 7ceb80d88df158f206fffc6f2c7e8bc8f29a1d63 Mon Sep 17 00:00:00 2001 From: Robin Malhotra Date: Fri, 26 Apr 2019 16:12:49 +0530 Subject: [PATCH 3/4] Merge upstream changes --- Cartfile.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 6a0d62c..159e604 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Quick/Nimble" "v7.3.1" -github "Quick/Quick" "v1.3.2" +github "Quick/Nimble" "v8.0.1" +github "Quick/Quick" "v2.1.0" github "vadymmarkov/When" "4.0.0" From 234a5e77b48c15fb7e1ee8b61615d831a03f36ac Mon Sep 17 00:00:00 2001 From: Robin Malhotra Date: Fri, 26 Apr 2019 16:19:39 +0530 Subject: [PATCH 4/4] Fix macOS @available check --- Sources/Request/RequestStorage.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Request/RequestStorage.swift b/Sources/Request/RequestStorage.swift index 5201eef..3497364 100644 --- a/Sources/Request/RequestStorage.swift +++ b/Sources/Request/RequestStorage.swift @@ -25,9 +25,13 @@ final class RequestStorage { } func saveAll() { - let data = NSKeyedArchiver.archivedData(withRootObject: requests) - userDefaults.set(data, forKey: key) - userDefaults.synchronize() + if #available(OSX 10.11, *) { + let data = NSKeyedArchiver.archivedData(withRootObject: requests) + userDefaults.set(data, forKey: key) + userDefaults.synchronize() + } else { + // Fallback on earlier versions + } } // MARK: - Remove