All Projects → zokioki → fitbit_api

zokioki / fitbit_api

Licence: MIT License
A Ruby interface to the Fitbit Web API, supports OAuth2.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to fitbit api

fitbit-web-api-demo
Quick and dirty demo
Stars: ✭ 18 (+0%)
Mutual labels:  fitbit
keyring-social-importers
A collection of importers which pull your content back from social networks, and into your own WordPress install.
Stars: ✭ 26 (+44.44%)
Mutual labels:  fitbit
webpack-cluster
Helps to make parallel webpack compilation easily
Stars: ✭ 32 (+77.78%)
Mutual labels:  fitbit
zeit
A Fitbit clock face for learners of the German language
Stars: ✭ 41 (+127.78%)
Mutual labels:  fitbit
ossapps
A non-exhaustive list of open sourced clock faces, applications and modules from the community.
Stars: ✭ 393 (+2083.33%)
Mutual labels:  fitbit
fitnotifications
Fit Notifications allows you to view all your Android notifications on your Fitbit device, as long as it supports at least "Text Notifications" natively.
Stars: ✭ 18 (+0%)
Mutual labels:  fitbit
ts4health
Time Series Data Analysis, Visualization and Forecasting with Python for Health and Self
Stars: ✭ 17 (-5.56%)
Mutual labels:  fitbit
data-at-hand-mobile
Mobile application for exploring fitness data using both speech and touch interaction.
Stars: ✭ 50 (+177.78%)
Mutual labels:  fitbit
sdk-design-assets
Downloadable design assets for the Fitbit SDK.
Stars: ✭ 75 (+316.67%)
Mutual labels:  fitbit
angular-translate-loader
"angular-translate" loader for webpack
Stars: ✭ 15 (-16.67%)
Mutual labels:  fitbit
fitbit-googlefit
Export Fitbit data to Google Fit. Unlike the alternatives such as fitnessyncer.com, this offers very fine intraday granularity (every minute/second data).
Stars: ✭ 433 (+2305.56%)
Mutual labels:  fitbit
sdk-oauth
Fitbit SDK example application.
Stars: ✭ 66 (+266.67%)
Mutual labels:  fitbit
helvetic
Hacking / reverse engineering the Fitbit Aria (WiFi enabled bathroom scales)
Stars: ✭ 40 (+122.22%)
Mutual labels:  fitbit
lifebot
Use Google Sheets to log your life by texting it Emojis and pulling in data from Fitbit automatically.
Stars: ✭ 15 (-16.67%)
Mutual labels:  fitbit

FitbitAPI

Gem Version Build Status

FitbitAPI provides a Ruby interface to the Fitbit Web API.

Installation

To install the latest release:

$ gem install fitbit_api

To include in a Rails project, add it to the Gemfile:

gem 'fitbit_api'

Getting Started

To use the Fitbit API, you must register your application at dev.fitbit.com. After registering, you should have access to the CLIENT ID and CLIENT SECRET values for use in instantiating a FitbitAPI::Client object.

Rails

You can reference the fitbit_api_rails repo as a simple example of how to use this gem within a Rails project.

Quickstart

If you already have a user's token data and Fitbit user_id:

client = FitbitAPI::Client.new(client_id: 'XXXXXX',
                               client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                               access_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                               refresh_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                               expires_at: 1234567890,
                               user_id: 'XXXXXX')

OAuth 2.0 Authorization Flow

  • Create a client instance (ensure that redirect_uri is passed in):
client = FitbitAPI::Client.new(client_id: 'XXXXXX',
                               client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                               redirect_uri: 'http://example.com/handle/callback')
  • Generate a link for your app's Fitbit authorization page:
client.auth_url
# => https://fitbit.com/oauth2/authorize?client_id=123XYZ&redirect_uri=...
  • Follow the generated link to Fitbit's authorization page. After granting permission for your app, you're sent to the redirect_uri, with an appended authorization code param, which you'll exchange for an access token:
client.get_token(auth_code)

You're now authorized and can make calls to Fitbit's API.

Interacting with the API

Once a valid token has been generated, you're able to make API calls via the client object:

client.food_logs Date.today
# => { "foods" => [{ "isFavorite" => true, "logDate" => "2015-06-26", "logId" => 1820, "loggedFood" => { "accessLevel" => "PUBLIC", "amount" => 132.57, "brand" => "", "calories" => 752, ...}] }

To make responses more easily suited for attribute-assignment, they can be parsed to return a hash whose keys are in snake_case format. This can be done by setting the client's snake_case_keys option to true:

client.snake_case_keys = true
client.food_logs Date.today
# => { "foods" => [{ "is_favorite" => true, "log_date" => "2015-06-26", "log_id" => 1820, "logged_food" => { "access_level" => "PUBLIC", "amount" => 132.57, "brand" => "", "calories" => 752, ...}] }

Similarly, all arguments passed in through a POST request are automatically converted to camelCase before they hit Fitbit's API, making it easy to keep your codebase stylistically consistent. For example, all of the following would result in valid API calls:

# options with snake_cased keys
client.log_activity activity_id: 12345, duration_millis: '50000'
# options with camelCased keys
client.log_activity activityId: 54321, durationMillis: '44100'
# options with mixed snake and camel cased keys
client.log_activity activity_id: 12345, durationMillis: '683300'

Options

When initializing a FitbitAPI::Client instance, you're given access to a handful of options:

  • :api_version - API version to be used when making requests (default: "1")

  • :unit_system - The measurement unit system to use for response values (default: "en_US" | available: "en_US", "en_GB", and "any" for metric)

  • :locale - The locale to use for response values (default: "en_US" | available: "en_US", "fr_FR", "de_DE", "es_ES", "en_GB", "en_AU", "en_NZ" and "ja_JP")

  • :scope - A space-delimited list of the permissions you are requesting (default: "activity nutrition profile settings sleep social weight heartrate" | available: "activity", "heartrate", "location", "nutrition", "profile", "settings" "sleep", "social" and "weight")

  • :snake_case_keys - Transform returned object's keys to snake case format (default: false)

  • :symbolize_keys - Transform returned object's keys to symbols (default: false)

If using this library in Rails, you can configure your options using an initializer:

# config/initializers/fitbit_api.rb

FitbitAPI.configure do |config|
  config.client_id       = 'XXXX'
  config.client_secret   = 'xxxx'
  config.snake_case_keys = true
  config.symbolize_keys  = true
end

License

This gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].