Welcome to django-fitbit’s documentation!¶
Contents:
Getting started¶
- Add django-fitbit to your Django site’s requirements, however you prefer, and install it. It’s installable from PyPI.
Add fitapp to your INSTALLED_APPS setting:
INSTALLED_APPS += ['fitapp']
Add the django-fitbit URLs to your URLconf:
url(r'^fitbit/', include('fitapp.urls')),
Register your site at the Fitbit developer site to get a key and secret.
Add settings for FITAPP_CONSUMER_KEY and FITAPP_CONSUMER_SECRET:
FITAPP_CONSUMER_KEY = '9898XH' FITAPP_CONSUMER_SECRET = 'abcdefg123456'
If you need to change the defaults, add settings for FITAPP_LOGIN_REDIRECT, FITAPP_LOGOUT_REDIRECT, and/or FITAPP_ERROR_TEMPLATE.
To display whether the user has integrated their Fitbit, or change a template behavior, use the is_integrated_with_fitbit template filter. Or in a view, call the
fitapp.utils.is_integrated()
function. You can also use the decoratorfitapp.decorators.fitbit_integration_warning()
to display a message to the user when they are not integrated with Fitbit.To send the user through authorization at the Fitbit site for your app to access their data, send them to the
fitapp.views.login()
view.To get step data for a user from a web page, use the AJAX
fitapp.views.get_steps()
view.If you are using sqlite, you will want to create a celery configuration that prevents the fitapp celery tasks from being executed concurrently. If you are using any other database type, you can skip this step.
Settings¶
FITAPP_CONSUMER_KEY¶
The OAuth 2.0 client id assigned to your app by Fitbit when you register your app at the Fitbit developer site. You must specify a non-null value for this setting.
FITAPP_CONSUMER_SECRET¶
The secret that goes with the FITAPP_CONSUMER_KEY. You must specify a non-null value for this setting.
FITAPP_VERIFICATION_CODE¶
The verification code fitbit assigns to your app for the purpose of verifying subscriber endpoints. This is optional, and is only needed if you plan on subscribing to user data updates. To use this feature, add a subscriber using the Fitbit developer interface. Fitbit will provide you with a verification code to use here. Once you have deployed the code, you can click “Verify” on Fitbit to verify it. We recommend you keep this verification code in place as long as you are using the subscriber so that if any changes are made, reverification happens automatically.
FITAPP_LOGIN_REDIRECT¶
Default: | '/' |
---|
The URL which to redirect the user to after successful Fitbit integration, if no forwarding URL is given in the ‘fitapp_next’ session variable.
FITAPP_LOGOUT_REDIRECT¶
Default: | '/' |
---|
The URL which to redirect the user to after removal of Fitbit account credentials, if no forwarding URL is given in the ‘next’ GET parameter.
FITAPP_SUBSCRIBE¶
Default: | False |
---|
When this setting is True, we will subscribe to user data. Fitbit will send notifications when the data changes and we will queue tasks to get the updated data. When requests for fitbit data are made to fitapp, we will always pull the latest data from our own database instead of getting it directly from Fitbit. To use this feature, you will need to setup a celery worker to handle the tasks. Following celery’s guide for Django will get you started.
FITAPP_SUBSCRIBER_ID¶
This setting is only applicable if FITAPP_SUBSCRIBE is True. This is the unique ID of the subscriber endpoint that was set up for your Fitbit app on their developer site.
FITAPP_ERROR_TEMPLATE¶
Default: | 'fitapp/error.html' |
---|
The template used to report an error integrating the user’s Fitbit.
FITAPP_DECORATOR_MESSAGE¶
Default: | 'This page requires Fitbit integration.' |
---|
The default message used by the
fitapp.decorators.fitbit_integration_warning()
decorator to inform
the user about Fitbit integration. If a callable is provided, it is called
with the request as the only parameter to get the final value for the message.
Views, decorators, and templates¶
There are several views and decorators your site will use to drive Fitbit integration.
Django-fitbit is a Django app for integrating a user’s Fitbit data into your site.
It handles the details of getting your app authorized to access your user’s Fitbit data via the Fitbit web API.
Testing¶
Please add tests for any changes you submit.
To install all the requirements for running the tests:
pip install -r requirements/dev.txt
To run the tests for specific python version (ie. py27-1.8.X):
tox -e py27-1.8.X
If you would like to run specific test you can bypass tox altogether and run:
python -m run_tests fitapp.tests.test_integration.TestLoginView.test_unauthenticated