Home

Awesome

OAuthSwiftFutures

<img align="left" src="https://raw.githubusercontent.com/OAuthSwift/OAuthSwift/master/Assets/OAuthSwift-icon.png" alt="OAuthSwiftFutures" hspace="20" /> OAuthSwiftFutures bring you [futures/promises](https://en.wikipedia.org/wiki/Futures_and_promises) to OAuthSwift.

It's build on top BrightFutures to achieve great asynchronous code.

<br><br> <br><br>

Installation

Support CocoaPods

use_frameworks!

pod 'OAuthSwiftFutures', '~> 1.0.0'

Support Carthage

github "OAuthSwift/OAuthSwiftFutures" ~> 1.0.0

How to use

OAuth1.0

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)
}

OAuth2.0

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)")
}

Request

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)")
}

Playing with Future

// 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

License

OAuthSwiftFutures is available under the MIT license. See the LICENSE file for more info.

Join the chat at https://gitter.im/dongri/OAuthSwift License Platform Language Cocoapod