From 2c97276768cafa389bc86cba6d5457de7473129a Mon Sep 17 00:00:00 2001 From: Ozgur Vatansever Date: Mon, 23 Sep 2019 16:24:41 +0300 Subject: [PATCH 01/30] made Swift 5.0 compatible with Alamofire 5.0.0-rc2 --- Cartfile | 4 +-- Cartfile.private | 2 +- Cartfile.resolved | 6 ++--- PMKAlamofire.xcodeproj/project.pbxproj | 10 ++++--- Sources/Alamofire+Promise.swift | 36 ++++++++------------------ Tests/TestAlamofire.swift | 6 ++--- 6 files changed, 26 insertions(+), 38 deletions(-) mode change 100644 => 100755 Cartfile mode change 100644 => 100755 Cartfile.private mode change 100644 => 100755 PMKAlamofire.xcodeproj/project.pbxproj mode change 100644 => 100755 Sources/Alamofire+Promise.swift diff --git a/Cartfile b/Cartfile old mode 100644 new mode 100755 index 14c7c12..4ba58f0 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "mxcl/PromiseKit" ~> 6.8.4 -github "Alamofire/Alamofire" ~> 4.0 +github "mxcl/PromiseKit" ~> 6.11.0 +github "Alamofire/Alamofire" ~> 5.0.0-rc.2 diff --git a/Cartfile.private b/Cartfile.private old mode 100644 new mode 100755 index 7ad353e..203f6cf --- a/Cartfile.private +++ b/Cartfile.private @@ -1 +1 @@ -github "AliSoftware/OHHTTPStubs" ~> 7.0 +github "AliSoftware/OHHTTPStubs" ~> 8.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 10b37bd..98c060e 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Alamofire/Alamofire" "4.8.2" -github "AliSoftware/OHHTTPStubs" "7.0.0" -github "mxcl/PromiseKit" "6.8.4" +github "Alamofire/Alamofire" "5.0.0-rc.2" +github "AliSoftware/OHHTTPStubs" "8.0.0" +github "mxcl/PromiseKit" "6.11.0" diff --git a/PMKAlamofire.xcodeproj/project.pbxproj b/PMKAlamofire.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 45ae8f7..b9431bf --- a/PMKAlamofire.xcodeproj/project.pbxproj +++ b/PMKAlamofire.xcodeproj/project.pbxproj @@ -279,7 +279,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -287,7 +287,7 @@ SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -342,13 +342,13 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = org.promisekit.Foundation; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos watchsimulator watchos macosx appletvsimulator appletvos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; @@ -373,6 +373,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_TREAT_WARNINGS_AS_ERRORS = NO; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -390,6 +391,7 @@ PRODUCT_MODULE_NAME = "${TARGET_NAME}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_TREAT_WARNINGS_AS_ERRORS = NO; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift old mode 100644 new mode 100755 index f5f7b59..b9e9659 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -16,7 +16,7 @@ import PromiseKit */ extension Alamofire.DataRequest { /// Adds a handler to be called once the request has finished. - public func response(_: PMKNamespacer, queue: DispatchQueue? = nil) -> Promise<(URLRequest, HTTPURLResponse, Data)> { + public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise<(URLRequest, HTTPURLResponse, Data)> { return Promise { seal in response(queue: queue) { rsp in if let error = rsp.error { @@ -31,7 +31,7 @@ extension Alamofire.DataRequest { } /// Adds a handler to be called once the request has finished. - public func responseData(queue: DispatchQueue? = nil) -> Promise<(data: Data, response: PMKAlamofireDataResponse)> { + public func responseData(queue: DispatchQueue = .main) -> Promise<(data: Data, response: PMKAlamofireDataResponse)> { return Promise { seal in responseData(queue: queue) { response in switch response.result { @@ -45,7 +45,7 @@ extension Alamofire.DataRequest { } /// Adds a handler to be called once the request has finished. - public func responseString(queue: DispatchQueue? = nil) -> Promise<(string: String, response: PMKAlamofireDataResponse)> { + public func responseString(queue: DispatchQueue = .main) -> Promise<(string: String, response: PMKAlamofireDataResponse)> { return Promise { seal in responseString(queue: queue) { response in switch response.result { @@ -59,7 +59,7 @@ extension Alamofire.DataRequest { } /// Adds a handler to be called once the request has finished. - public func responseJSON(queue: DispatchQueue? = nil, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> { + public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> { return Promise { seal in responseJSON(queue: queue, options: options) { response in switch response.result { @@ -72,20 +72,6 @@ extension Alamofire.DataRequest { } } - /// Adds a handler to be called once the request has finished. - public func responsePropertyList(queue: DispatchQueue? = nil, options: PropertyListSerialization.ReadOptions = PropertyListSerialization.ReadOptions()) -> Promise<(plist: Any, response: PMKAlamofireDataResponse)> { - return Promise { seal in - responsePropertyList(queue: queue, options: options) { response in - switch response.result { - case .success(let value): - seal.fulfill((value, PMKAlamofireDataResponse(response))) - case .failure(let error): - seal.reject(error) - } - } - } - } - #if swift(>=3.2) /** Returns a Promise for a Decodable @@ -94,7 +80,7 @@ extension Alamofire.DataRequest { - Parameter queue: DispatchQueue, by default nil - Parameter decoder: JSONDecoder, by default JSONDecoder() */ - public func responseDecodable(queue: DispatchQueue? = nil, decoder: JSONDecoder = JSONDecoder()) -> Promise { + public func responseDecodable(queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { return Promise { seal in responseData(queue: queue) { response in switch response.result { @@ -118,7 +104,7 @@ extension Alamofire.DataRequest { - Parameter queue: DispatchQueue, by default nil - Parameter decoder: JSONDecoder, by default JSONDecoder() */ - public func responseDecodable(_ type: T.Type, queue: DispatchQueue? = nil, decoder: JSONDecoder = JSONDecoder()) -> Promise { + public func responseDecodable(_ type: T.Type, queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { return Promise { seal in responseData(queue: queue) { response in switch response.result { @@ -138,7 +124,7 @@ extension Alamofire.DataRequest { } extension Alamofire.DownloadRequest { - public func response(_: PMKNamespacer, queue: DispatchQueue? = nil) -> Promise { + public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise> { return Promise { seal in response(queue: queue) { response in if let error = response.error { @@ -151,7 +137,7 @@ extension Alamofire.DownloadRequest { } /// Adds a handler to be called once the request has finished. - public func responseData(queue: DispatchQueue? = nil) -> Promise> { + public func responseData(queue: DispatchQueue = .main) -> Promise> { return Promise { seal in responseData(queue: queue) { response in switch response.result { @@ -168,11 +154,11 @@ extension Alamofire.DownloadRequest { /// Alamofire.DataResponse, but without the `result`, since the Promise represents the `Result` public struct PMKAlamofireDataResponse { - public init(_ rawrsp: Alamofire.DataResponse) { + public init(_ rawrsp: Alamofire.AFDataResponse) { request = rawrsp.request response = rawrsp.response data = rawrsp.data - timeline = rawrsp.timeline + metrics = rawrsp.metrics } /// The URL request sent to the server. @@ -185,5 +171,5 @@ public struct PMKAlamofireDataResponse { public let data: Data? /// The timeline of the complete lifecycle of the request. - public let timeline: Timeline + public let metrics: URLSessionTaskMetrics? } diff --git a/Tests/TestAlamofire.swift b/Tests/TestAlamofire.swift index 043ee8a..62f4536 100644 --- a/Tests/TestAlamofire.swift +++ b/Tests/TestAlamofire.swift @@ -13,7 +13,7 @@ class AlamofireTests: XCTestCase { let ex = expectation(description: "") - let rq = Alamofire.request("http://example.com", method: .get).responseJSON().done { rsp in + let rq = AF.request("http://example.com", method: .get).responseJSON().done { rsp in XCTAssertEqual(json, rsp.json as? NSDictionary) ex.fulfill() } @@ -33,7 +33,7 @@ class AlamofireTests: XCTestCase { func testDecodable1() { func getFixture() -> Promise { - return Alamofire.request("http://example.com", method: .get).responseDecodable(queue: nil) + return AF.request("http://example.com", method: .get).responseDecodable() } let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]] @@ -62,7 +62,7 @@ class AlamofireTests: XCTestCase { let ex = expectation(description: "") firstly { - Alamofire.request("http://example.com", method: .get).responseDecodable(Fixture.self) + AF.request("http://example.com", method: .get).responseDecodable(Fixture.self) }.done { fixture in XCTAssert(fixture.key1 == "value1", "Value1 found") ex.fulfill() From 458d118968873488a88c6d3a95fa48c11045d2a6 Mon Sep 17 00:00:00 2001 From: Ozgur Vatansever Date: Sun, 21 Jun 2020 12:44:13 +0300 Subject: [PATCH 02/30] made Swift 5.2 compatible with Alamofire 5.2.1 --- Cartfile | 4 ++-- Cartfile.resolved | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cartfile b/Cartfile index 4ba58f0..caf0197 100755 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "mxcl/PromiseKit" ~> 6.11.0 -github "Alamofire/Alamofire" ~> 5.0.0-rc.2 +github "mxcl/PromiseKit" ~> 6.13.0 +github "Alamofire/Alamofire" ~> 5.2.1 diff --git a/Cartfile.resolved b/Cartfile.resolved index 98c060e..7208e8d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Alamofire/Alamofire" "5.0.0-rc.2" +github "Alamofire/Alamofire" "5.2.1" github "AliSoftware/OHHTTPStubs" "8.0.0" -github "mxcl/PromiseKit" "6.11.0" +github "mxcl/PromiseKit" "6.13.1" From 5a374bda16fc24ecf94b98e4ea1a6554c2d33116 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:47:07 +0300 Subject: [PATCH 03/30] Update README.markdown --- README.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.markdown b/README.markdown index ced03e0..8bc756c 100644 --- a/README.markdown +++ b/README.markdown @@ -2,8 +2,6 @@ This project adds promises to [Alamofire](https://github.com/Alamofire/Alamofire). -This project supports Swift 3.1, 3.2, 4.0 and 4.1. - ## Usage ```swift From 6f34620578244e323e1da3dd945bf446c8f45bbd Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:47:26 +0300 Subject: [PATCH 04/30] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 2e0d331..4f05f24 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ let package = Package( name: "PMKAlamofire", dependencies: [ .Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), - .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 4) + .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5) ], exclude: ["Tests"] ) From ed210ee91b037b22df27ad06598fe5beb7301136 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:48:15 +0300 Subject: [PATCH 05/30] Update Package@swift-4.2.swift --- Package@swift-4.2.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift index d6ab721..8493db2 100644 --- a/Package@swift-4.2.swift +++ b/Package@swift-4.2.swift @@ -7,7 +7,7 @@ pkg.products = [ .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]), ] pkg.dependencies = [ - .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "4.0.0")), + .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) ] pkg.swiftLanguageVersions = [.v3, .v4, .v4_2] From 0062384f9cdf079e8b808ac96ad00ead830ca7c9 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:48:57 +0300 Subject: [PATCH 06/30] Update Package@swift-4.2.swift --- Package@swift-4.2.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift index 8493db2..b3ed326 100644 --- a/Package@swift-4.2.swift +++ b/Package@swift-4.2.swift @@ -10,7 +10,7 @@ pkg.dependencies = [ .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) ] -pkg.swiftLanguageVersions = [.v3, .v4, .v4_2] +pkg.swiftLanguageVersions = [.v3, .v4, .v4_2, .v5] let target: Target = .target(name: "PMKAlamofire") target.path = "Sources" From a41937342d473d8005656479e4da8e1491ce3c74 Mon Sep 17 00:00:00 2001 From: Radu Ursache Date: Mon, 7 Sep 2020 20:50:41 +0300 Subject: [PATCH 07/30] - bump version --- PMKAlamofire.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PMKAlamofire.xcodeproj/project.pbxproj b/PMKAlamofire.xcodeproj/project.pbxproj index b9431bf..ce5c702 100755 --- a/PMKAlamofire.xcodeproj/project.pbxproj +++ b/PMKAlamofire.xcodeproj/project.pbxproj @@ -364,6 +364,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; + CURRENT_PROJECT_VERSION = 1.0.7; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -383,6 +384,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; + CURRENT_PROJECT_VERSION = 1.0.7; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; From 36e3299430ae2bab03c9562a6dc1f4542201ac86 Mon Sep 17 00:00:00 2001 From: Radu Ursache Date: Mon, 7 Sep 2020 20:52:59 +0300 Subject: [PATCH 08/30] - added package.swift for 5.3 --- Package@swift-5.3.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Package@swift-5.3.swift diff --git a/Package@swift-5.3.swift b/Package@swift-5.3.swift new file mode 100644 index 0000000..f7d16a4 --- /dev/null +++ b/Package@swift-5.3.swift @@ -0,0 +1,23 @@ +// swift-tools-version:5.3 + +import PackageDescription + +let pkg = Package(name: "PMKAlamofire") +pkg.products = [ + .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]), +] +pkg.dependencies = [ + .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), + .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) +] +pkg.swiftLanguageVersions = [.v5, .v5_3] + +let target: Target = .target(name: "PMKAlamofire") +target.path = "Sources" +target.exclude = ["Tests"] +target.dependencies = [ + "PromiseKit", + "Alamofire" +] + +pkg.targets = [target] From 1a46c82120864c0025e470a49155ecee0bd7b39f Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:55:18 +0300 Subject: [PATCH 09/30] Update Package@swift-4.2.swift --- Package@swift-4.2.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift index b3ed326..8493db2 100644 --- a/Package@swift-4.2.swift +++ b/Package@swift-4.2.swift @@ -10,7 +10,7 @@ pkg.dependencies = [ .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) ] -pkg.swiftLanguageVersions = [.v3, .v4, .v4_2, .v5] +pkg.swiftLanguageVersions = [.v3, .v4, .v4_2] let target: Target = .target(name: "PMKAlamofire") target.path = "Sources" From 1e35df75f1f5f6eb9f09c375088294b58180cf66 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:01:33 +0300 Subject: [PATCH 10/30] Update Package.swift --- Package.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Package.swift b/Package.swift index 4f05f24..2108855 100644 --- a/Package.swift +++ b/Package.swift @@ -6,5 +6,11 @@ let package = Package( .Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5) ], + platforms: [ + .macOS(.v10_12), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v3) + ], exclude: ["Tests"] ) From e278a3e2f42bdd5457167a1deb732a503c5edafd Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:09:25 +0300 Subject: [PATCH 11/30] Update Package.swift --- Package.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Package.swift b/Package.swift index 2108855..cdb9693 100644 --- a/Package.swift +++ b/Package.swift @@ -1,16 +1,16 @@ +// swift-tools-version:5.1 import PackageDescription -let package = Package( - name: "PMKAlamofire", - dependencies: [ - .Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), - .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5) - ], - platforms: [ - .macOS(.v10_12), - .iOS(.v10), - .tvOS(.v10), - .watchOS(.v3) - ], - exclude: ["Tests"] -) +let package = Package(name: "PMKAlamofire", + platforms: [.macOS(.v10_12), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v3)], + products: [.library(name: "PMKAlamofire", + targets: ["PMKAlamofire"])], + targets: [.target(name: "PMKAlamofire", + path: "Source"], + dependencies: [.Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), + .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5)], + swiftLanguageVersions: [.v5], + exclude: ["Tests"]) From 24476c1fa559cfb7c08ed616c5d93edd06b02741 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:09:50 +0300 Subject: [PATCH 12/30] Delete Package@swift-4.2.swift --- Package@swift-4.2.swift | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Package@swift-4.2.swift diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift deleted file mode 100644 index 8493db2..0000000 --- a/Package@swift-4.2.swift +++ /dev/null @@ -1,23 +0,0 @@ -// swift-tools-version:4.2 - -import PackageDescription - -let pkg = Package(name: "PMKAlamofire") -pkg.products = [ - .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]), -] -pkg.dependencies = [ - .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), - .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) -] -pkg.swiftLanguageVersions = [.v3, .v4, .v4_2] - -let target: Target = .target(name: "PMKAlamofire") -target.path = "Sources" -target.exclude = ["Tests"] -target.dependencies = [ - "PromiseKit", - "Alamofire" -] - -pkg.targets = [target] From 56da616cc569ef34001da2f537a4606a83904a53 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:09:52 +0300 Subject: [PATCH 13/30] Delete Package@swift-5.3.swift --- Package@swift-5.3.swift | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Package@swift-5.3.swift diff --git a/Package@swift-5.3.swift b/Package@swift-5.3.swift deleted file mode 100644 index f7d16a4..0000000 --- a/Package@swift-5.3.swift +++ /dev/null @@ -1,23 +0,0 @@ -// swift-tools-version:5.3 - -import PackageDescription - -let pkg = Package(name: "PMKAlamofire") -pkg.products = [ - .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]), -] -pkg.dependencies = [ - .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")), - .package(url: "https://github.com/mxcl/PromiseKit.git", .upToNextMajor(from: "6.0.0")) -] -pkg.swiftLanguageVersions = [.v5, .v5_3] - -let target: Target = .target(name: "PMKAlamofire") -target.path = "Sources" -target.exclude = ["Tests"] -target.dependencies = [ - "PromiseKit", - "Alamofire" -] - -pkg.targets = [target] From 9ee64f7c05d8846428460fbbc6eef3ff049e6afb Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:14:30 +0300 Subject: [PATCH 14/30] Update Package.swift --- Package.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index cdb9693..d048928 100644 --- a/Package.swift +++ b/Package.swift @@ -2,14 +2,9 @@ import PackageDescription let package = Package(name: "PMKAlamofire", - platforms: [.macOS(.v10_12), - .iOS(.v10), - .tvOS(.v10), - .watchOS(.v3)], - products: [.library(name: "PMKAlamofire", - targets: ["PMKAlamofire"])], - targets: [.target(name: "PMKAlamofire", - path: "Source"], + platforms: [.macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3)], + products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], + targets: [.target(name: "PMKAlamofire", path: "Source")], dependencies: [.Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5)], swiftLanguageVersions: [.v5], From 78d82fa4cc96aa614c537d57fec3605f7c714022 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:17:44 +0300 Subject: [PATCH 15/30] Update Package.swift --- Package.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index d048928..5b15c86 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,6 @@ let package = Package(name: "PMKAlamofire", platforms: [.macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], targets: [.target(name: "PMKAlamofire", path: "Source")], - dependencies: [.Package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), - .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5)], - swiftLanguageVersions: [.v5], - exclude: ["Tests"]) + dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), + .package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5)], + swiftLanguageVersions: [.v5]) From c5dbb054d32ed55e23671348828b6a45daf5f481 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:18:56 +0300 Subject: [PATCH 16/30] Update Package.swift --- Package.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 5b15c86..651d235 100644 --- a/Package.swift +++ b/Package.swift @@ -1,8 +1,12 @@ // swift-tools-version:5.1 + import PackageDescription let package = Package(name: "PMKAlamofire", - platforms: [.macOS(.v10_12), .iOS(.v10), .tvOS(.v10), .watchOS(.v3)], + platforms: [.macOS(.v10_12), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], targets: [.target(name: "PMKAlamofire", path: "Source")], dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), From af34b9a9a068b4759c939f5f82465b77f8a89a9f Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:28:36 +0300 Subject: [PATCH 17/30] Update Package.swift --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 651d235..d46e4d6 100644 --- a/Package.swift +++ b/Package.swift @@ -9,6 +9,6 @@ let package = Package(name: "PMKAlamofire", .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], targets: [.target(name: "PMKAlamofire", path: "Source")], - dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", majorVersion: 6), - .package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 5)], + dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), + .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")], swiftLanguageVersions: [.v5]) From 1973b633cb41ce83ec053d9c1e1182b5f44c6000 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:33:00 +0300 Subject: [PATCH 18/30] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index d46e4d6..5bd5980 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ let package = Package(name: "PMKAlamofire", .tvOS(.v10), .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], - targets: [.target(name: "PMKAlamofire", path: "Source")], dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")], + targets: [.target(name: "PMKAlamofire", path: "Source")], swiftLanguageVersions: [.v5]) From c8f7d2adfd4816f84d231b32223d1353870ccaa0 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 21:34:46 +0300 Subject: [PATCH 19/30] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 5bd5980..0242ab7 100644 --- a/Package.swift +++ b/Package.swift @@ -10,5 +10,5 @@ let package = Package(name: "PMKAlamofire", products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")], - targets: [.target(name: "PMKAlamofire", path: "Source")], + targets: [.target(name: "PMKAlamofire", path: "Sources")], swiftLanguageVersions: [.v5]) From 533ce7f49b4d8f577df22f80f83e78cf16891078 Mon Sep 17 00:00:00 2001 From: Radu Ursache Date: Mon, 7 Sep 2020 21:38:31 +0300 Subject: [PATCH 20/30] - fixed alamofire classes --- Sources/Alamofire+Promise.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift index b9e9659..8722af9 100755 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -124,7 +124,7 @@ extension Alamofire.DataRequest { } extension Alamofire.DownloadRequest { - public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise> { + public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise> { return Promise { seal in response(queue: queue) { response in if let error = response.error { @@ -137,7 +137,7 @@ extension Alamofire.DownloadRequest { } /// Adds a handler to be called once the request has finished. - public func responseData(queue: DispatchQueue = .main) -> Promise> { + public func responseData(queue: DispatchQueue = .main) -> Promise> { return Promise { seal in responseData(queue: queue) { response in switch response.result { @@ -154,11 +154,10 @@ extension Alamofire.DownloadRequest { /// Alamofire.DataResponse, but without the `result`, since the Promise represents the `Result` public struct PMKAlamofireDataResponse { - public init(_ rawrsp: Alamofire.AFDataResponse) { + public init(_ rawrsp: Alamofire.DataResponse) { request = rawrsp.request response = rawrsp.response data = rawrsp.data - metrics = rawrsp.metrics } /// The URL request sent to the server. @@ -169,7 +168,4 @@ public struct PMKAlamofireDataResponse { /// The data returned by the server. public let data: Data? - - /// The timeline of the complete lifecycle of the request. - public let metrics: URLSessionTaskMetrics? } From e62972a2f17e80dd8a0228bf7f95f588b2df6ae7 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:03:18 +0300 Subject: [PATCH 21/30] Update Alamofire+Promise.swift --- Sources/Alamofire+Promise.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift index 8722af9..8889475 100755 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -1,4 +1,4 @@ -@_exported import Alamofire +import Alamofire import Foundation #if !PMKCocoaPods import PromiseKit From 53c3592214eeea59732bf94ea304a8ab64312e7a Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:08:19 +0300 Subject: [PATCH 22/30] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 0242ab7..91563f7 100644 --- a/Package.swift +++ b/Package.swift @@ -10,5 +10,5 @@ let package = Package(name: "PMKAlamofire", products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")], - targets: [.target(name: "PMKAlamofire", path: "Sources")], + targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: ["PromiseKit", "Alamofire"])], swiftLanguageVersions: [.v5]) From 1cf269d65f8cf8d60d81075a74836c15395ce227 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:11:09 +0300 Subject: [PATCH 23/30] Update Alamofire+Promise.swift --- Sources/Alamofire+Promise.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift index 8889475..8a4489d 100755 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -1,6 +1,6 @@ -import Alamofire import Foundation #if !PMKCocoaPods +import Alamofire import PromiseKit #endif From 08dfd4d33c913e4c2943a34e91bc5706520ce5f2 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:14:02 +0300 Subject: [PATCH 24/30] Update Package.swift --- Package.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 91563f7..92dd727 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,6 @@ let package = Package(name: "PMKAlamofire", .tvOS(.v10), .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], - dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), - .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")], - targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: ["PromiseKit", "Alamofire"])], + targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), + .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")])], swiftLanguageVersions: [.v5]) From 66aa3230a14802917c966561960ca77c3f95ce1c Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:16:27 +0300 Subject: [PATCH 25/30] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 92dd727..232dff3 100644 --- a/Package.swift +++ b/Package.swift @@ -8,6 +8,6 @@ let package = Package(name: "PMKAlamofire", .tvOS(.v10), .watchOS(.v3)], products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], - targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), + targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")])], swiftLanguageVersions: [.v5]) From 8e6c5fd71fd4e67e3564b532a9f96652db5acbde Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:22:59 +0300 Subject: [PATCH 26/30] Update Package.swift --- Package.swift | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 232dff3..ac9fbf7 100644 --- a/Package.swift +++ b/Package.swift @@ -3,11 +3,18 @@ import PackageDescription let package = Package(name: "PMKAlamofire", - platforms: [.macOS(.v10_12), - .iOS(.v10), - .tvOS(.v10), - .watchOS(.v3)], - products: [.library(name: "PMKAlamofire", targets: ["PMKAlamofire"])], - targets: [.target(name: "PMKAlamofire", path: "Sources", dependencies: [.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), - .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2")])], - swiftLanguageVersions: [.v5]) + platforms: [.macOS(.v10_12), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v3)], + dependencies: [ + .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), + .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2") + ], + products: [ + .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]) + ], + targets: [ + .target(name: "PMKAlamofire", path: "Sources") + ], + swiftLanguageVersions: [.v5]) From ec2530fb305086f496c9e00332c65ec4c25f3a88 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 7 Sep 2020 22:25:36 +0300 Subject: [PATCH 27/30] Update Package.swift --- Package.swift | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Package.swift b/Package.swift index ac9fbf7..ed0cc5a 100644 --- a/Package.swift +++ b/Package.swift @@ -2,19 +2,23 @@ import PackageDescription -let package = Package(name: "PMKAlamofire", - platforms: [.macOS(.v10_12), - .iOS(.v10), - .tvOS(.v10), - .watchOS(.v3)], - dependencies: [ - .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), - .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2") - ], - products: [ - .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]) - ], - targets: [ - .target(name: "PMKAlamofire", path: "Sources") - ], - swiftLanguageVersions: [.v5]) +let package = Package( + name: "PMKAlamofire", + platforms: [.macOS(.v10_12), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v3)], + products: [ + .library(name: "PMKAlamofire", targets: ["PMKAlamofire"]) + ], + dependencies: [ + .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.13.2"), + .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2") + ], + targets: [ + .target(name: "PMKAlamofire", path: "Sources", dependencies: [ + .product(name: "PromiseKit"), + .product(name: "Alamofire"), + ]) + ], + swiftLanguageVersions: [.v5]) From f14feea2af83fd2c7e82e67a5116584b9df9dbe4 Mon Sep 17 00:00:00 2001 From: Radu Ursache Date: Mon, 7 Sep 2020 22:27:46 +0300 Subject: [PATCH 28/30] - updated package.swift --- Package.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index ed0cc5a..9dd8471 100644 --- a/Package.swift +++ b/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( - name: "PMKAlamofire", + name: "PMKAlamofire", platforms: [.macOS(.v10_12), .iOS(.v10), .tvOS(.v10), @@ -16,9 +16,9 @@ let package = Package( .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.2.2") ], targets: [ - .target(name: "PMKAlamofire", path: "Sources", dependencies: [ + .target(name: "PMKAlamofire", dependencies: [ .product(name: "PromiseKit"), .product(name: "Alamofire"), - ]) + ], path: "Sources") ], - swiftLanguageVersions: [.v5]) + swiftLanguageVersions: [.v5]) \ No newline at end of file From d6ec200a89c3dff0536a3c60b13cc0dc6dddd48a Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Fri, 25 Feb 2022 18:16:20 +0200 Subject: [PATCH 29/30] Alamofire 6 fixes Fixed "responseJSON(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:completionHandler:)' is deprecated: responseJSON deprecated and will be removed in Alamofire 6" --- Sources/Alamofire+Promise.swift | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift index 8a4489d..f93c3d8 100755 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -59,18 +59,22 @@ extension Alamofire.DataRequest { } /// Adds a handler to be called once the request has finished. - public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> { - return Promise { seal in - responseJSON(queue: queue, options: options) { response in - switch response.result { - case .success(let value): - seal.fulfill((value, PMKAlamofireDataResponse(response))) - case .failure(let error): - seal.reject(error) - } - } - } - } + public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> { + return Promise { seal in + responseData(queue: queue) { response in + switch response.result { + case .success(let dataValue): + do { + let json = try JSONSerialization.jsonObject(with: dataValue, options: options) + seal.fulfill((json, PMKAlamofireDataResponse(response))) + } catch { + seal.reject(error) + } + case .failure(let error): + seal.reject(error) + } + } + } #if swift(>=3.2) /** From 51bdde5b403ed754e6c65f372a5fa65b03ce73c7 Mon Sep 17 00:00:00 2001 From: Radu Ursache <3800336+rursache@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:09:34 +0200 Subject: [PATCH 30/30] Update Alamofire+Promise.swift --- Sources/Alamofire+Promise.swift | 263 ++++++++++++++++---------------- 1 file changed, 132 insertions(+), 131 deletions(-) diff --git a/Sources/Alamofire+Promise.swift b/Sources/Alamofire+Promise.swift index f93c3d8..528a9b6 100755 --- a/Sources/Alamofire+Promise.swift +++ b/Sources/Alamofire+Promise.swift @@ -7,66 +7,91 @@ import PromiseKit /** To import the `Alamofire` category: - use_frameworks! - pod "PromiseKit/Alamofire" + use_frameworks! + pod "PromiseKit/Alamofire" And then in your sources: - import PromiseKit + import PromiseKit */ extension Alamofire.DataRequest { - /// Adds a handler to be called once the request has finished. - public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise<(URLRequest, HTTPURLResponse, Data)> { - return Promise { seal in - response(queue: queue) { rsp in - if let error = rsp.error { - seal.reject(error) - } else if let a = rsp.request, let b = rsp.response, let c = rsp.data { - seal.fulfill((a, b, c)) - } else { - seal.reject(PMKError.invalidCallingConvention) - } - } - } - } + /// Adds a handler to be called once the request has finished. + public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise<(URLRequest, HTTPURLResponse, Data)> { + return Promise { seal in + response(queue: queue) { rsp in + if let error = rsp.error { + seal.reject(error) + } else if let a = rsp.request, let b = rsp.response, let c = rsp.data { + seal.fulfill((a, b, c)) + } else { + seal.reject(PMKError.invalidCallingConvention) + } + } + } + } - /// Adds a handler to be called once the request has finished. - public func responseData(queue: DispatchQueue = .main) -> Promise<(data: Data, response: PMKAlamofireDataResponse)> { - return Promise { seal in - responseData(queue: queue) { response in - switch response.result { - case .success(let value): - seal.fulfill((value, PMKAlamofireDataResponse(response))) - case .failure(let error): - seal.reject(error) - } - } - } - } + /// Adds a handler to be called once the request has finished. + public func responseData(queue: DispatchQueue = .main) -> Promise<(data: Data, response: PMKAlamofireDataResponse)> { + return Promise { seal in + responseData(queue: queue) { response in + switch response.result { + case .success(let value): + seal.fulfill((value, PMKAlamofireDataResponse(response))) + case .failure(let error): + seal.reject(error) + } + } + } + } - /// Adds a handler to be called once the request has finished. - public func responseString(queue: DispatchQueue = .main) -> Promise<(string: String, response: PMKAlamofireDataResponse)> { - return Promise { seal in - responseString(queue: queue) { response in - switch response.result { - case .success(let value): - seal.fulfill((value, PMKAlamofireDataResponse(response))) - case .failure(let error): - seal.reject(error) - } - } - } - } + /// Adds a handler to be called once the request has finished. + public func responseString(queue: DispatchQueue = .main) -> Promise<(string: String, response: PMKAlamofireDataResponse)> { + return Promise { seal in + responseString(queue: queue) { response in + switch response.result { + case .success(let value): + seal.fulfill((value, PMKAlamofireDataResponse(response))) + case .failure(let error): + seal.reject(error) + } + } + } + } - /// Adds a handler to be called once the request has finished. + /// Adds a handler to be called once the request has finished. public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> { return Promise { seal in responseData(queue: queue) { response in switch response.result { - case .success(let dataValue): + case .success(let dataValue): + do { + let json = try JSONSerialization.jsonObject(with: dataValue, options: options) + seal.fulfill((json, PMKAlamofireDataResponse(response))) + } catch { + seal.reject(error) + } + case .failure(let error): + seal.reject(error) + } + } + } + } + +#if swift(>=3.2) + /** + Returns a Promise for a Decodable + Adds a handler to be called once the request has finished. + + - Parameter queue: DispatchQueue, by default nil + - Parameter decoder: JSONDecoder, by default JSONDecoder() + */ + public func responseDecodable(queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { + return Promise { seal in + responseData(queue: queue) { response in + switch response.result { + case .success(let value): do { - let json = try JSONSerialization.jsonObject(with: dataValue, options: options) - seal.fulfill((json, PMKAlamofireDataResponse(response))) + seal.fulfill(try decoder.decode(T.self, from: value)) } catch { seal.reject(error) } @@ -74,102 +99,78 @@ extension Alamofire.DataRequest { seal.reject(error) } } - } - -#if swift(>=3.2) - /** - Returns a Promise for a Decodable - Adds a handler to be called once the request has finished. - - - Parameter queue: DispatchQueue, by default nil - - Parameter decoder: JSONDecoder, by default JSONDecoder() - */ - public func responseDecodable(queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { - return Promise { seal in - responseData(queue: queue) { response in - switch response.result { - case .success(let value): - do { - seal.fulfill(try decoder.decode(T.self, from: value)) - } catch { - seal.reject(error) - } - case .failure(let error): - seal.reject(error) - } - } - } - } + } + } - /** - Returns a Promise for a Decodable - Adds a handler to be called once the request has finished. - - - Parameter queue: DispatchQueue, by default nil - - Parameter decoder: JSONDecoder, by default JSONDecoder() - */ - public func responseDecodable(_ type: T.Type, queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { - return Promise { seal in - responseData(queue: queue) { response in - switch response.result { - case .success(let value): - do { - seal.fulfill(try decoder.decode(type, from: value)) - } catch { - seal.reject(error) - } - case .failure(let error): - seal.reject(error) - } - } - } - } + /** + Returns a Promise for a Decodable + Adds a handler to be called once the request has finished. + + - Parameter queue: DispatchQueue, by default nil + - Parameter decoder: JSONDecoder, by default JSONDecoder() + */ + public func responseDecodable(_ type: T.Type, queue: DispatchQueue = .main, decoder: JSONDecoder = JSONDecoder()) -> Promise { + return Promise { seal in + responseData(queue: queue) { response in + switch response.result { + case .success(let value): + do { + seal.fulfill(try decoder.decode(type, from: value)) + } catch { + seal.reject(error) + } + case .failure(let error): + seal.reject(error) + } + } + } + } #endif } extension Alamofire.DownloadRequest { - public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise> { - return Promise { seal in - response(queue: queue) { response in - if let error = response.error { - seal.reject(error) - } else { - seal.fulfill(response) - } - } - } - } + public func response(_: PMKNamespacer, queue: DispatchQueue = .main) -> Promise> { + return Promise { seal in + response(queue: queue) { response in + if let error = response.error { + seal.reject(error) + } else { + seal.fulfill(response) + } + } + } + } - /// Adds a handler to be called once the request has finished. - public func responseData(queue: DispatchQueue = .main) -> Promise> { - return Promise { seal in - responseData(queue: queue) { response in - switch response.result { - case .success: - seal.fulfill(response) - case .failure(let error): - seal.reject(error) - } - } - } - } + /// Adds a handler to be called once the request has finished. + public func responseData(queue: DispatchQueue = .main) -> Promise> { + return Promise { seal in + responseData(queue: queue) { response in + switch response.result { + case .success: + seal.fulfill(response) + case .failure(let error): + seal.reject(error) + } + } + } + } } /// Alamofire.DataResponse, but without the `result`, since the Promise represents the `Result` public struct PMKAlamofireDataResponse { - public init(_ rawrsp: Alamofire.DataResponse) { - request = rawrsp.request - response = rawrsp.response - data = rawrsp.data - } + public init(_ rawrsp: Alamofire.DataResponse) { + request = rawrsp.request + response = rawrsp.response + data = rawrsp.data + } - /// The URL request sent to the server. - public let request: URLRequest? + /// The URL request sent to the server. + public let request: URLRequest? - /// The server's response to the URL request. - public let response: HTTPURLResponse? + /// The server's response to the URL request. + public let response: HTTPURLResponse? - /// The data returned by the server. - public let data: Data? + /// The data returned by the server. + public let data: Data? }