Skip to content

Latest commit

 

History

History
99 lines (77 loc) · 3.18 KB

README.md

File metadata and controls

99 lines (77 loc) · 3.18 KB

OAuthSwiftFutures

OAuthSwiftFutures

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.





Installation

Support CocoaPods

  • Podfile
use_frameworks!

pod 'OAuthSwiftFutures', '~> 1.0.0'

Support Carthage

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.

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