It's build on top BrightFutures to achieve great asynchronous code.
- Podfile
use_frameworks!
pod 'OAuthSwiftFutures', '~> 1.0.0'
- Install Carthage (https://github.com/Carthage/Carthage)
- Create Cartfile file
github "OAuthSwift/OAuthSwiftFutures" ~> 1.0.0
- Run
carthage update
. - On your application targets’ “General” settings tab, in the “Embedded Binaries” section, drag and drop OAuthSwift.framework and the dependencies from the Carthage/Build/"OSNAME" folder on disk.
let (authorize, handle) = oauthswift.authorizeFuture(withCallbackURL: "oauth-swift://oauth-callback/twitter")
authorize.onSuccess { credential, response, parameters in
print(credential.oauth_token)
print(credential.oauth_token_secret)
print(parameters["user_id"])
}
authorizeFuture.onFailure { error in
print(error.localizedDescription)
}
let (authorize, handle) = oauthswift.authorizeFuture(withCallbackURL: "oauth-swift://oauth-callback/facebook",
scope: "likes+comments", state:"generatedone")
authorize.onSuccess { credential, response, parameters in
print(credential.oauth_token)
}
authorize.onFailure { error in
print("\(error)")
}
Use one the client new functions
let (authorize, handle) = oauthswift.client.getFuture("https://api.linkedin.com/v1/people/~")
authorize.onSuccess { data, response in
let dataString = String(data: data, encoding: String.Encoding.utf8)
print(dataString)
}
authorize.onFailure { error in
print("\(error)")
}
// after created
let requestFuture = authorize.flatMap { tuple -> Future<(data: Data, response: HTTPURLResponse), OAuthSwiftError> in
// will be executed only if authorization succeed
let (future, _) = oauthswift.client.getFuture("https://api.linkedin.com/v1/people/~")
return future
}
requestFuture.onSuccess { data, response in
print(data)
}
You can learn more at BrightFutures
OAuthSwiftFutures is available under the MIT license. See the LICENSE file for more info.