https://github.com/oauthswift/oauthswiftfutures
Use Future with OAuthSwift
https://github.com/oauthswift/oauthswiftfutures
Last synced: 4 months ago
JSON representation
Use Future with OAuthSwift
- Host: GitHub
- URL: https://github.com/oauthswift/oauthswiftfutures
- Owner: OAuthSwift
- License: mit
- Created: 2015-12-18T22:10:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-08-16T12:28:44.000Z (almost 8 years ago)
- Last Synced: 2025-06-05T04:28:39.411Z (about 1 year ago)
- Language: Swift
- Size: 19.5 KB
- Stars: 20
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OAuthSwiftFutures
OAuthSwiftFutures bring you [futures/promises](https://en.wikipedia.org/wiki/Futures_and_promises) to OAuthSwift.
It's build on top [BrightFutures](https://github.com/Thomvis/BrightFutures) to achieve great asynchronous code.
## Installation
### Support CocoaPods
* Podfile
```ruby
use_frameworks!
pod 'OAuthSwiftFutures', '~> 1.0.0'
```
### Support Carthage
* 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.
## How to use
### OAuth1.0
```swift
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
```swift
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
```swift
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
```swift
// 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](https://github.com/Thomvis/BrightFutures)
## License
OAuthSwiftFutures is available under the MIT license. See the LICENSE file for more info.
[](https://gitter.im/dongri/OAuthSwift?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](http://mit-license.org)
[](https://developer.apple.com/resources/)
[](https://developer.apple.com/swift)
[](http://cocoadocs.org/docsets/OAuthSwiftFutures/)