diff --git a/.gitmodules b/.gitmodules
index 1bc68ff..85f4dcb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
-[submodule "Carthage/Checkouts/Argo"]
- path = Carthage/Checkouts/Argo
- url = https://github.com/thoughtbot/Argo.git
[submodule "Carthage/Checkouts/Nimble"]
path = Carthage/Checkouts/Nimble
url = https://github.com/Quick/Nimble.git
diff --git a/Cartfile b/Cartfile
index 8acdc39..830560f 100644
--- a/Cartfile
+++ b/Cartfile
@@ -1,6 +1,5 @@
# Core
github "antitypical/Result" ~> 2.0
-github "thoughtbot/Argo" ~> 3.0
# ReactiveCocoa
github "ReactiveCocoa/ReactiveCocoa" ~> 4.0
diff --git a/Cartfile.resolved b/Cartfile.resolved
index 467fe7a..c7d85a0 100644
--- a/Cartfile.resolved
+++ b/Cartfile.resolved
@@ -1,7 +1,6 @@
-github "thoughtbot/Argo" "v3.0.1"
-github "Quick/Nimble" "v4.0.1"
+github "Quick/Nimble" "v4.1.0"
github "AliSoftware/OHHTTPStubs" "4.8.0"
github "Quick/Quick" "v0.9.2"
-github "antitypical/Result" "2.0.0"
+github "antitypical/Result" "2.1.3"
github "jspahrsummers/xcconfigs" "0.9"
-github "ReactiveCocoa/ReactiveCocoa" "v4.1.0"
+github "ReactiveCocoa/ReactiveCocoa" "v4.2.2"
diff --git a/Carthage/Checkouts/Argo b/Carthage/Checkouts/Argo
deleted file mode 160000
index be127e5..0000000
--- a/Carthage/Checkouts/Argo
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit be127e583674ff8e92653c9bbd0328ab55daebc7
diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble
index 0cf1291..b4a0f9d 160000
--- a/Carthage/Checkouts/Nimble
+++ b/Carthage/Checkouts/Nimble
@@ -1 +1 @@
-Subproject commit 0cf12916a276ba7bc7a66ded95bd8f7e77ca7f6b
+Subproject commit b4a0f9d6ee6b89f0e2f9ee8fa32aaa7200b1e27c
diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa
index fdbd367..f214c9d 160000
--- a/Carthage/Checkouts/ReactiveCocoa
+++ b/Carthage/Checkouts/ReactiveCocoa
@@ -1 +1 @@
-Subproject commit fdbd3676cc4305c48e53bc25aebdb0eb607cdc2b
+Subproject commit f214c9d508db77f751c3af5be967c4cb235fc0a1
diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result
index 5dec9cf..9b5e373 160000
--- a/Carthage/Checkouts/Result
+++ b/Carthage/Checkouts/Result
@@ -1 +1 @@
-Subproject commit 5dec9cf225d5fa3b0602679fb2638e40191da46b
+Subproject commit 9b5e373891dfe0de11ba2a8e9a5cafd570b858c4
diff --git a/Heimdallr.podspec b/Heimdallr.podspec
index e074e2b..152ea49 100644
--- a/Heimdallr.podspec
+++ b/Heimdallr.podspec
@@ -23,7 +23,6 @@ Pod::Spec.new do |spec|
spec.default_subspec = 'Core'
spec.subspec 'Core' do |subspec|
- subspec.dependency 'Argo', '~> 3.0'
subspec.dependency 'Result', '~> 2.0'
subspec.framework = 'Foundation'
diff --git a/Heimdallr.xcodeproj/project.pbxproj b/Heimdallr.xcodeproj/project.pbxproj
index e541702..4058787 100644
--- a/Heimdallr.xcodeproj/project.pbxproj
+++ b/Heimdallr.xcodeproj/project.pbxproj
@@ -7,10 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
- DC209CCD1C845F9500C43C75 /* Argo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CC51C845F1900C43C75 /* Argo.framework */; };
- DC209CCE1C845F9600C43C75 /* Argo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CC51C845F1900C43C75 /* Argo.framework */; };
- DC209CCF1C845F9700C43C75 /* Argo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CC51C845F1900C43C75 /* Argo.framework */; };
- DC209CD01C845F9800C43C75 /* Argo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CC51C845F1900C43C75 /* Argo.framework */; };
DC209CD31C845FA100C43C75 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CCB1C845F1900C43C75 /* Result.framework */; };
DC209CD61C845FA300C43C75 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CCB1C845F1900C43C75 /* Result.framework */; };
DC209CD81C845FA400C43C75 /* ReactiveCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC209CCA1C845F1900C43C75 /* ReactiveCocoa.framework */; };
@@ -244,7 +240,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- DC209CCD1C845F9500C43C75 /* Argo.framework in Frameworks */,
DC209CD31C845FA100C43C75 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -264,7 +259,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- DC209CCE1C845F9600C43C75 /* Argo.framework in Frameworks */,
DC209CD61C845FA300C43C75 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -284,7 +278,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- DC209CCF1C845F9700C43C75 /* Argo.framework in Frameworks */,
DC209CD81C845FA400C43C75 /* ReactiveCocoa.framework in Frameworks */,
DC209CD91C845FA400C43C75 /* Result.framework in Frameworks */,
);
@@ -305,7 +298,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- DC209CD01C845F9800C43C75 /* Argo.framework in Frameworks */,
DC209CDB1C845FA400C43C75 /* ReactiveCocoa.framework in Frameworks */,
DC209CDC1C845FA400C43C75 /* Result.framework in Frameworks */,
);
diff --git a/Heimdallr.xcworkspace/contents.xcworkspacedata b/Heimdallr.xcworkspace/contents.xcworkspacedata
index f784804..76bb79c 100644
--- a/Heimdallr.xcworkspace/contents.xcworkspacedata
+++ b/Heimdallr.xcworkspace/contents.xcworkspacedata
@@ -4,9 +4,6 @@
-
-
diff --git a/Heimdallr/Core/Heimdallr.swift b/Heimdallr/Core/Heimdallr.swift
index ef7cddd..47fa0dc 100644
--- a/Heimdallr/Core/Heimdallr.swift
+++ b/Heimdallr/Core/Heimdallr.swift
@@ -155,10 +155,9 @@ public let HeimdallrErrorNotAuthorized = 2
completion(.Failure(error))
}
} else {
- switch OAuthError.decode(data!) {
- case let .Success(error):
+ if let data = data, error = OAuthError.decode(data: data) {
completion(.Failure(error.nsError))
- default:
+ } else {
let userInfo = [
NSLocalizedDescriptionKey: NSLocalizedString("Could not authorize grant", comment: ""),
NSLocalizedFailureReasonErrorKey: String(format: NSLocalizedString("Expected error, got: %@.", comment: ""), NSString(data: data!, encoding: NSUTF8StringEncoding) ?? "nil")
diff --git a/Heimdallr/Core/OAuthAccessToken.swift b/Heimdallr/Core/OAuthAccessToken.swift
index cc235b3..5769054 100644
--- a/Heimdallr/Core/OAuthAccessToken.swift
+++ b/Heimdallr/Core/OAuthAccessToken.swift
@@ -1,4 +1,3 @@
-import Argo
import Result
/// An access token is used for authorizing requests to the resource endpoint.
@@ -56,34 +55,32 @@ public func == (lhs: OAuthAccessToken, rhs: OAuthAccessToken) -> Bool {
&& lhs.refreshToken == rhs.refreshToken
}
-extension OAuthAccessToken: Decodable {
- public class func create(accessToken: String) -> String -> NSDate? -> String? -> OAuthAccessToken {
- return
- { tokenType in
- { expiresAt in
- { refreshToken in
- OAuthAccessToken(accessToken: accessToken, tokenType: tokenType, expiresAt: expiresAt, refreshToken: refreshToken)
- }
- }
+extension OAuthAccessToken {
+ public class func decode(json: [String: AnyObject]) -> OAuthAccessToken? {
+ func toNSDate(timeIntervalSinceNow: NSTimeInterval?) -> NSDate? {
+ return timeIntervalSinceNow.map { timeIntervalSinceNow in
+ return NSDate(timeIntervalSinceNow: timeIntervalSinceNow)
}
- }
+ }
- public class func decode(json: JSON) -> Decoded {
- func toNSDate(timeIntervalSinceNow: NSTimeInterval?) -> Decoded {
- return pure(timeIntervalSinceNow.map { timeIntervalSinceNow in
- return NSDate(timeIntervalSinceNow: timeIntervalSinceNow)
- } ?? .None)
+ guard let accessToken = json["access_token"] as? String,
+ tokenType = json["token_type"] as? String else {
+ return nil
}
- return create
- <^> json <| "access_token"
- <*> json <| "token_type"
- <*> (json <|? "expires_in").flatMap(toNSDate)
- <*> json <|? "refresh_token"
+ let expiresAt = (json["expires_in"] as? NSTimeInterval).flatMap(toNSDate)
+ let refreshToken = json["refresh_token"] as? String
+
+ return OAuthAccessToken(accessToken: accessToken, tokenType: tokenType,
+ expiresAt: expiresAt, refreshToken: refreshToken)
}
- public class func decode(data: NSData) -> Decoded {
- let json: AnyObject? = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0))
- return Decoded.fromOptional(json).flatMap(Argo.decode)
+ public class func decode(data data: NSData) -> OAuthAccessToken? {
+ guard let json = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)),
+ jsonDictionary = json as? [String: AnyObject] else {
+ return nil
+ }
+
+ return decode(jsonDictionary)
}
}
diff --git a/Heimdallr/Core/OAuthAccessTokenDefaultParser.swift b/Heimdallr/Core/OAuthAccessTokenDefaultParser.swift
index a8aeab2..8db8942 100644
--- a/Heimdallr/Core/OAuthAccessTokenDefaultParser.swift
+++ b/Heimdallr/Core/OAuthAccessTokenDefaultParser.swift
@@ -1,17 +1,13 @@
import Foundation
import Result
-import Argo
@objc
public class OAuthAccessTokenDefaultParser: NSObject, OAuthAccessTokenParser {
public func parse(data: NSData) -> Result {
- let decoded = OAuthAccessToken.decode(data)
-
- switch decoded {
- case .Success(let token):
+ if let token = OAuthAccessToken.decode(data: data) {
return .Success(token)
- case .Failure:
+ } else {
let error = NSError(domain: HeimdallrErrorDomain, code: HeimdallrErrorInvalidData, userInfo: nil)
return .Failure(error)
}
diff --git a/Heimdallr/Core/OAuthError.swift b/Heimdallr/Core/OAuthError.swift
index a0ced6e..e3ede5a 100644
--- a/Heimdallr/Core/OAuthError.swift
+++ b/Heimdallr/Core/OAuthError.swift
@@ -1,5 +1,3 @@
-import Argo
-
/// See: The OAuth 2.0 Authorization Framework, 5.2 Error Response
///
@@ -41,10 +39,10 @@ public extension OAuthErrorCode {
}
}
-extension OAuthErrorCode: Decodable {
- public static func decode(json: JSON) -> Decoded {
- return String.decode(json).flatMap { code in
- return .fromOptional(OAuthErrorCode(rawValue: code))
+extension OAuthErrorCode {
+ public static func decode(json: AnyObject?) -> OAuthErrorCode? {
+ return json.flatMap { $0 as? String }.flatMap { code in
+ return OAuthErrorCode(rawValue: code)
}
}
}
@@ -77,25 +75,24 @@ public extension OAuthError {
}
}
-extension OAuthError: Decodable {
- public class func create(code: OAuthErrorCode) -> String? -> String? -> OAuthError {
- return
- { description in
- { uri in
- OAuthError(code: code, description: description, uri: uri)
- }
- }
- }
+extension OAuthError {
+ public class func decode(json: [String: AnyObject]) -> OAuthError? {
+ guard let code = json["error"].flatMap(OAuthErrorCode.decode) else {
+ return nil
+ }
- public class func decode(json: JSON) -> Decoded {
- return create
- <^> json <| "error"
- <*> json <|? "error_description"
- <*> json <|? "error_uri"
+ let description = json["error_description"] as? String
+ let uri = json["error_uri"] as? String
+
+ return OAuthError(code: code, description: description, uri: uri)
}
- public class func decode(data: NSData) -> Decoded {
- let json: AnyObject? = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0))
- return Decoded.fromOptional(json).flatMap(Argo.decode)
+ public class func decode(data data: NSData) -> OAuthError? {
+ guard let json: AnyObject? = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)),
+ jsonDictionary = json as? [String: AnyObject] else {
+ return nil
+ }
+
+ return decode(jsonDictionary)
}
}
diff --git a/HeimdallrTests/Core/OAuthAccessTokenSpec.swift b/HeimdallrTests/Core/OAuthAccessTokenSpec.swift
index 2e728fe..1a34971 100644
--- a/HeimdallrTests/Core/OAuthAccessTokenSpec.swift
+++ b/HeimdallrTests/Core/OAuthAccessTokenSpec.swift
@@ -1,4 +1,3 @@
-import Argo
import Heimdallr
import Nimble
import Quick
@@ -139,16 +138,16 @@ class OAuthAccessTokenSpec: QuickSpec {
describe("+decode") {
context("without an expiration date") {
it("creates a valid access token") {
- let accessToken = OAuthAccessToken.decode(.Object([
- "access_token": .String("accessToken"),
- "token_type": .String("tokenType")
- ]))
-
- expect(accessToken.value).toNot(beNil())
- expect(accessToken.value?.accessToken).to(equal("accessToken"))
- expect(accessToken.value?.tokenType).to(equal("tokenType"))
- expect(accessToken.value?.expiresAt).to(beNil())
- expect(accessToken.value?.refreshToken).to(beNil())
+ let accessToken = OAuthAccessToken.decode([
+ "access_token": "accessToken",
+ "token_type": "tokenType"
+ ])
+
+ expect(accessToken).toNot(beNil())
+ expect(accessToken?.accessToken).to(equal("accessToken"))
+ expect(accessToken?.tokenType).to(equal("tokenType"))
+ expect(accessToken?.expiresAt).to(beNil())
+ expect(accessToken?.refreshToken).to(beNil())
}
}
}