Skip to content

Commit 8ecab2b

Browse files
authored
Merge pull request orcasgit#114 from orcasgit/docs
Docs
2 parents 5f345ff + 3f57e17 commit 8ecab2b

3 files changed

Lines changed: 121 additions & 3 deletions

File tree

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.3.0 (2017-01-24)
2+
==================
3+
* Surface errors better
4+
* Use requests-oauthlib auto refresh to automatically refresh tokens if possible
5+
16
0.2.4 (2016-11-10)
27
==================
38
* Call a hook if it exists when tokens are refreshed

docs/index.rst

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,90 @@ either ``None`` or a ``date`` or ``datetime`` object
4040
as ``%Y-%m-%d``.
4141

4242
.. autoclass:: fitbit.Fitbit
43-
:private-members:
4443
:members:
4544

45+
.. method:: body(date=None, user_id=None, data=None)
46+
47+
Get body data: https://dev.fitbit.com/docs/body/
48+
49+
.. method:: activities(date=None, user_id=None, data=None)
50+
51+
Get body data: https://dev.fitbit.com/docs/activity/
52+
53+
.. method:: foods_log(date=None, user_id=None, data=None)
54+
55+
Get food logs data: https://dev.fitbit.com/docs/food-logging/#get-food-logs
56+
57+
.. method:: foods_log_water(date=None, user_id=None, data=None)
58+
59+
Get water logs data: https://dev.fitbit.com/docs/food-logging/#get-water-logs
60+
61+
.. method:: sleep(date=None, user_id=None, data=None)
62+
63+
Get sleep data: https://dev.fitbit.com/docs/sleep/
64+
65+
.. method:: heart(date=None, user_id=None, data=None)
66+
67+
Get heart rate data: https://dev.fitbit.com/docs/heart-rate/
68+
69+
.. method:: bp(date=None, user_id=None, data=None)
70+
71+
Get blood pressure data: https://dev.fitbit.com/docs/heart-rate/
72+
73+
.. method:: delete_body(log_id)
74+
75+
Delete a body log, given a log id
76+
77+
.. method:: delete_activities(log_id)
78+
79+
Delete an activity log, given a log id
80+
81+
.. method:: delete_foods_log(log_id)
82+
83+
Delete a food log, given a log id
84+
85+
.. method:: delete_foods_log_water(log_id)
86+
87+
Delete a water log, given a log id
88+
89+
.. method:: delete_sleep(log_id)
90+
91+
Delete a sleep log, given a log id
92+
93+
.. method:: delete_heart(log_id)
94+
95+
Delete a heart log, given a log id
96+
97+
.. method:: delete_bp(log_id)
98+
99+
Delete a blood pressure log, given a log id
100+
101+
.. method:: recent_foods(user_id=None, qualifier='')
102+
103+
Get recently logged foods: https://dev.fitbit.com/docs/food-logging/#get-recent-foods
104+
105+
.. method:: frequent_foods(user_id=None, qualifier='')
106+
107+
Get frequently logged foods: https://dev.fitbit.com/docs/food-logging/#get-frequent-foods
108+
109+
.. method:: favorite_foods(user_id=None, qualifier='')
110+
111+
Get favorited foods: https://dev.fitbit.com/docs/food-logging/#get-favorite-foods
112+
113+
.. method:: recent_activities(user_id=None, qualifier='')
114+
115+
Get recently logged activities: https://dev.fitbit.com/docs/activity/#get-recent-activity-types
116+
117+
.. method:: frequent_activities(user_id=None, qualifier='')
118+
119+
Get frequently logged activities: https://dev.fitbit.com/docs/activity/#get-frequent-activities
120+
121+
.. method:: favorite_activities(user_id=None, qualifier='')
122+
123+
Get favorited foods: https://dev.fitbit.com/docs/activity/#get-favorite-activities
124+
125+
126+
46127
Indices and tables
47128
==================
48129

fitbit/api.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ def refresh_token(self):
162162

163163

164164
class Fitbit(object):
165+
"""
166+
Before using this class, create a Fitbit app
167+
`here <https://dev.fitbit.com/apps/new>`_. There you will get the client id
168+
and secret needed to instantiate this class. When first authorizing a user,
169+
make sure to pass the `redirect_uri` keyword arg so fitbit will know where
170+
to return to when the authorization is complete. See
171+
`gather_keys_oauth2.py <https://github.com/orcasgit/python-fitbit/blob/master/gather_keys_oauth2.py>`_
172+
for a reference implementation of the authorization process. You should
173+
save ``access_token``, ``refresh_token``, and ``expires_at`` from the
174+
returned token for each user you authorize.
175+
176+
When instantiating this class for use with an already authorized user, pass
177+
in the ``access_token``, ``refresh_token``, and ``expires_at`` keyword
178+
arguments. We also strongly recommend passing in a ``refresh_cb`` keyword
179+
argument, which should be a function taking one argument: a token dict.
180+
When that argument is present, we will automatically refresh the access
181+
token when needed and call this function so that you can save the updated
182+
token data. If you don't save the updated information, then you could end
183+
up with invalid access and refresh tokens, and the only way to recover from
184+
that is to reauthorize the user.
185+
"""
165186
US = 'en_US'
166187
METRIC = 'en_UK'
167188

@@ -187,12 +208,23 @@ class Fitbit(object):
187208
'frequent',
188209
]
189210

190-
def __init__(self, client_id, client_secret, system=US, **kwargs):
211+
def __init__(self, client_id, client_secret, access_token=None,
212+
refresh_token=None, expires_at=None, refresh_cb=None,
213+
redirect_uri=None, system=US, **kwargs):
191214
"""
192215
Fitbit(<id>, <secret>, access_token=<token>, refresh_token=<token>)
193216
"""
194217
self.system = system
195-
self.client = FitbitOauth2Client(client_id, client_secret, **kwargs)
218+
self.client = FitbitOauth2Client(
219+
client_id,
220+
client_secret,
221+
access_token=access_token,
222+
refresh_token=refresh_token,
223+
expires_at=expires_at,
224+
refresh_cb=refresh_cb,
225+
redirect_uri=redirect_uri,
226+
**kwargs
227+
)
196228

197229
# All of these use the same patterns, define the method for accessing
198230
# creating and deleting records once, and use curry to make individual

0 commit comments

Comments
 (0)