Latest 0.1.0
Homepage https://github.com/albertjo/SwiftBit
License MIT
Platforms ios 8.0, requires ARC
Dependencies SwiftyJSON, Alamofire, Locksmith
Authors

Version
License
Platform

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.

Latest podspec

{
    "name": "SwiftBit",
    "version": "0.1.0",
    "summary": "Fitbit API wrapper",
    "description": "Fitbit API wrapper in Swift 2.0",
    "homepage": "https://github.com/albertjo/SwiftBit",
    "license": "MIT",
    "authors": {
        "Albert Jo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/albertjo/SwiftBit.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SwiftBit/Classes/**/*",
    "requires_arc": true,
    "dependencies": {
        "SwiftyJSON": [],
        "Alamofire": [
            "~> 3.0"
        ],
        "Locksmith": []
    }
}

Pin It on Pinterest

Share This