SwiftBit 0.1.0

SwiftBit 0.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2016
SPMSupports SPM

Maintained by Albert Jo.



 
Depends on:
SwiftyJSON>= 0
Alamofire~> 3.0
Locksmith>= 0
 

SwiftBit 0.1.0

  • By
  • Albert Jo

SwiftBit

About

Swiftbit is an API wrapper for Fitbit written in Swift 2 and uses Alamofire, Locksmith, and SwiftyJSON. Swiftbit provides OAuth2.0 authorization and manages refreshing and revoking access tokens.

How to Use

Register your application on Fitbit. Remember to provide a callback url for your application and add a url scheme for your app. myimage-alt-tag

Add the following code to your app delegate.

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
        if (url.host == "YOUR_CALL_BACK") {
            SwiftBit.handleRedirectUrl(url)
        }
        return true
    }

This is an example to retrieve an array of recent activities.

let clientID = "CLIENT_ID"
let clientSecret = "CLIENT_SECRET"
let redirectUrl = "SwiftBitExample://oauth-callback"

// you must call setUp before attempting to log in or use the shared client
SwiftBit.setUp(clientID, clientSecret: clientSecret, redirectUrl: redirectUrl, scope: nil)
SwiftBit.logIn { (error) in
  if (error == nil) {
    SwiftBit.client().getRecentActivities({ (array, _error) in
      print(array)
    })
  }
}

To create a custom authenticated request, you can do the following:

// GET
SwiftBit.client().URLRequestWithMethod(.GET, url: url, optionalHeaders: optionalHeaders, parameters: parameters) {
  (json, error) in
  if (error == nil) {
    print(json)
}

// POST
SwiftBit.client().URLRequestWithMethod(.POST, url: url, optionalHeaders: optionalHeaders, parameters: parameters) {
  (json, error) in
  if (error == nil) {
    print(json)
}

To logout, simply call

SwiftBit.logOut()

Installation

pod "SwiftBit"

Author

Albert Jo

License

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