fitgem_oauth2 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fitgem_oauth2/activity.rb +42 -3
- data/lib/fitgem_oauth2/body_measurements.rb +28 -1
- data/lib/fitgem_oauth2/devices.rb +15 -0
- data/lib/fitgem_oauth2/friends.rb +9 -0
- data/lib/fitgem_oauth2/heartrate.rb +2 -0
- data/lib/fitgem_oauth2/sleep.rb +14 -0
- data/lib/fitgem_oauth2/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1852c3213510047e298bee0f2c887227a4d4b0bc
|
4
|
+
data.tar.gz: ca21defb34de418a6449654c5e080deb417174ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61604a94c8b95c1c38c2b33cf695b5dc1c9e3cd2dc42fc1694f055ed78e5481e13c012ecad21f0b092d6ab84aee31e1ee1d13a82e5460c0ee0c0b8e0a9415244
|
7
|
+
data.tar.gz: 78aca4f698224ea58dfe1c43e1a925c7a26d40559c6b2e8ac324c904889f30aa0d9346e0a91f8ae855376cf1ca57620adf7b1caa0216bc25b4a2af1c25c594ab
|
@@ -5,6 +5,8 @@ module FitgemOauth2
|
|
5
5
|
|
6
6
|
ACTIVITY_PERIODS = %w(1d 7d 30d 1w 1m 3m 6m 1y max)
|
7
7
|
|
8
|
+
# retrieves daily activity summary for a date
|
9
|
+
# @param date the date for which the summary is retrieved
|
8
10
|
def daily_activity_summary(date)
|
9
11
|
get_call("user/#{user_id}/activities/date/#{format_date(date)}.json")
|
10
12
|
end
|
@@ -13,6 +15,12 @@ module FitgemOauth2
|
|
13
15
|
# Activity Time Series
|
14
16
|
# ==================================
|
15
17
|
|
18
|
+
# retrieves activity time series, based on the arguments provided
|
19
|
+
# @param resource the resource for which the series needs to be retrieved. one of ALLOWED_RESOURCES
|
20
|
+
# @param start_date the start date for the series
|
21
|
+
# @param end_date the end date for the series. If specifying end_date, do not specify period
|
22
|
+
# @param period the period starting from start_date for which the series needs to be retrieved. If specifying period,
|
23
|
+
# do not use end_date
|
16
24
|
def activity_time_series(resource: nil, start_date: nil, end_date: nil, period: nil)
|
17
25
|
|
18
26
|
unless resource && ACTIVITY_RESOURCES.include?(resource)
|
@@ -37,8 +45,13 @@ module FitgemOauth2
|
|
37
45
|
get_call(url + '.json')
|
38
46
|
end
|
39
47
|
|
40
|
-
|
41
|
-
|
48
|
+
# retrieves intraday activity time series.
|
49
|
+
# @param resource (required) for which the intrady series is retrieved. one of 'calories', 'steps', 'distance', 'floors', 'elevation'
|
50
|
+
# @param start_date (required) start date for the series
|
51
|
+
# @param end_date (optional) end date for the series, if not specified, the series is for 1 day
|
52
|
+
# @param detail_level (required) level of detail for the series
|
53
|
+
# @param start_time (optional)start time for the series
|
54
|
+
# @param end_time the (optional)end time for the series. specify both start_time and end_time, if using either
|
42
55
|
def intraday_activity_time_series(resource: nil, start_date: nil, end_date: nil, detail_level: nil,
|
43
56
|
start_time: nil, end_time: nil)
|
44
57
|
|
@@ -82,18 +95,25 @@ module FitgemOauth2
|
|
82
95
|
# Activity Logging Methods
|
83
96
|
# ======================================
|
84
97
|
|
98
|
+
# logs activity using the params.
|
99
|
+
# @param params Hash to be posted. Refer https://dev.fitbit.com/docs/activity/#activity-logging for accepted
|
100
|
+
# POST parameters
|
85
101
|
def log_activity(params)
|
86
102
|
post_call("user/#{user_id}/activities.json", params)
|
87
103
|
end
|
88
104
|
|
105
|
+
# deletes a logged activity
|
106
|
+
# @param id id of the activity log to be deleted
|
89
107
|
def delete_logged_activity(id)
|
90
108
|
delete_call("user/#{user_id}/activities/#{id}.json")
|
91
109
|
end
|
92
110
|
|
111
|
+
# retrieves activity list for the user
|
93
112
|
def activity_list
|
94
113
|
get_call("user/#{user_id}/activities/list.json")
|
95
114
|
end
|
96
115
|
|
116
|
+
# retrieves activity list in the tcx format
|
97
117
|
def activity_tcx(id)
|
98
118
|
get_call("user/#{user_id}/activities/#{id}.tcx")
|
99
119
|
end
|
@@ -102,30 +122,43 @@ module FitgemOauth2
|
|
102
122
|
# ======================================
|
103
123
|
# Activity Types
|
104
124
|
# ======================================
|
125
|
+
|
126
|
+
# Get a tree of all valid Fitbit public activities from the activities catalog as well
|
127
|
+
# as private custom activities the user created in the format requested. If the activity
|
128
|
+
# has levels, also get a list of activity level details
|
105
129
|
def activities
|
106
|
-
get_call(
|
130
|
+
get_call('activities.json')
|
107
131
|
end
|
108
132
|
|
133
|
+
# Returns the details of a specific activity in the Fitbit activities database in the format requested.
|
134
|
+
# @param id id of the activity for which the details need to be retrieved
|
109
135
|
def activity(id)
|
110
136
|
get_call("activities/#{id}.json")
|
111
137
|
end
|
112
138
|
|
139
|
+
# gets frequent activities
|
113
140
|
def frequent_activities
|
114
141
|
get_call("user/#{user_id}/activities/frequent.json")
|
115
142
|
end
|
116
143
|
|
144
|
+
# gets recent activities
|
117
145
|
def recent_activities
|
118
146
|
get_call("user/#{user_id}/activities/recent.json")
|
119
147
|
end
|
120
148
|
|
149
|
+
# gets favorite activities
|
121
150
|
def favorite_activities
|
122
151
|
get_call("user/#{user_id}/activities/favorite.json")
|
123
152
|
end
|
124
153
|
|
154
|
+
# adds the activity with the given ID to user's list of favorite activities.
|
155
|
+
# @param activity_id ID of the activity to be added to the list of favorite activities
|
125
156
|
def add_favorite_activity(activity_id)
|
126
157
|
post_call("user/#{user_id}/activities/log/favorite/#{activity_id}.json")
|
127
158
|
end
|
128
159
|
|
160
|
+
# removes the activity with given ID from list of favorite activities.
|
161
|
+
# @param activity_id ID of the activity to be removed from favorite activity
|
129
162
|
def remove_favorite_activity(activity_id)
|
130
163
|
delete_call("user/#{user_id}/activities/log/favorite/#{activity_id}.json")
|
131
164
|
end
|
@@ -134,6 +167,8 @@ module FitgemOauth2
|
|
134
167
|
# Activity Goals
|
135
168
|
# ======================================
|
136
169
|
|
170
|
+
# retrieve activity goals for a period
|
171
|
+
# @period the period for which the goals need to be retrieved. either 'weekly' or 'daily'
|
137
172
|
def goals(period)
|
138
173
|
unless period && %w(daily weekly).include?(period)
|
139
174
|
raise FitgemOauth2::InvalidArgumentError, "Goal period should either be 'daily' or 'weekly'"
|
@@ -141,6 +176,9 @@ module FitgemOauth2
|
|
141
176
|
get_call("user/#{user_id}/activities/goals/#{period}.json")
|
142
177
|
end
|
143
178
|
|
179
|
+
# update activity goals
|
180
|
+
# @param period period for the goal ('weekly' or 'daily')
|
181
|
+
# @param params the POST params for the request. Refer to Fitbit documentation for accepted format
|
144
182
|
def update_activity_goals(period, params)
|
145
183
|
unless period && %w(daily weekly).include?(period)
|
146
184
|
raise FitgemOauth2::InvalidArgumentError, "Goal period should either be 'daily' or 'weekly'"
|
@@ -148,6 +186,7 @@ module FitgemOauth2
|
|
148
186
|
post_call("user/#{user_id}/activities/goals/#{period}.json", params)
|
149
187
|
end
|
150
188
|
|
189
|
+
# retrieves lifetime statistics for the user
|
151
190
|
def lifetime_stats
|
152
191
|
get_call("user/#{user_id}/activities.json")
|
153
192
|
end
|
@@ -9,6 +9,11 @@ module FitgemOauth2
|
|
9
9
|
# Boday Fat
|
10
10
|
# ======================================
|
11
11
|
|
12
|
+
# retrieves a list of all user's body fat log entries
|
13
|
+
# note: provide either end_date or period
|
14
|
+
# @param start_date start date for the logs
|
15
|
+
# @param end_date (optional)end date for the logs
|
16
|
+
# @param period (optional) period for the logs
|
12
17
|
def body_fat_logs(start_date: nil, end_date: nil, period: nil)
|
13
18
|
unless start_date
|
14
19
|
raise FitgemOauth2::InvalidArgumentError, 'must specify start_date'
|
@@ -31,10 +36,14 @@ module FitgemOauth2
|
|
31
36
|
get_call(url)
|
32
37
|
end
|
33
38
|
|
39
|
+
# logs body fat
|
40
|
+
# @param params POST parameters for logging body fat
|
34
41
|
def log_body_fat(params)
|
35
42
|
post_call("user/#{user_id}/body/log/fat.json", params)
|
36
43
|
end
|
37
44
|
|
45
|
+
# delete logged body fat
|
46
|
+
# @param id ID of the log to be deleted.
|
38
47
|
def delete_logged_body_fat(id)
|
39
48
|
delete_call("user/#{user_id}/body/log/fat/#{id}.json")
|
40
49
|
end
|
@@ -44,6 +53,11 @@ module FitgemOauth2
|
|
44
53
|
# Body Time Series
|
45
54
|
# ==================================
|
46
55
|
|
56
|
+
# retrieve body time series for the user; provide at least one of end_date and period
|
57
|
+
# @param resource (required)the resource requested ['bmi', 'fat', or 'weight']
|
58
|
+
# @param start_date (required)the start date for the series
|
59
|
+
# @param end_date (optional)the end date for the series
|
60
|
+
# @param period (optional)period for the time series. valid periods are BODY_TIME_SERIES_PERIODS
|
47
61
|
def body_time_series(resource: nil, start_date: nil, end_date: nil, period: nil)
|
48
62
|
unless resource && start_date
|
49
63
|
raise FitgemOauth2::InvalidArgumentError, 'resource and start_date are required parameters. Please specify both.'
|
@@ -78,6 +92,8 @@ module FitgemOauth2
|
|
78
92
|
# Body Goals
|
79
93
|
# ======================================
|
80
94
|
|
95
|
+
# retrieves body goals based on the type specified
|
96
|
+
# @param type 'fat' or 'weight'
|
81
97
|
def body_goals(type)
|
82
98
|
if type && BODY_GOALS.include?(type)
|
83
99
|
get_call("user/#{user_id}/body/log/#{type}/goal.json")
|
@@ -86,10 +102,14 @@ module FitgemOauth2
|
|
86
102
|
end
|
87
103
|
end
|
88
104
|
|
105
|
+
# update body fat goal
|
106
|
+
# @param params POST params for updating body fat goal
|
89
107
|
def update_body_fat_goal(params)
|
90
108
|
post_call("user/#{user_id}/body/log/fat/goal.json", params)
|
91
109
|
end
|
92
110
|
|
111
|
+
# update weight goal
|
112
|
+
# @param params POST params for updating weight goal
|
93
113
|
def update_weight_goal(params)
|
94
114
|
post_call("user/#{user_id}/body/log/weight/goal.json", params)
|
95
115
|
end
|
@@ -98,6 +118,10 @@ module FitgemOauth2
|
|
98
118
|
# Body Weight
|
99
119
|
# ======================================
|
100
120
|
|
121
|
+
# retrieve weight logs; specify either the end_date or period
|
122
|
+
# @param start_date start date for the logs
|
123
|
+
# @param end_date (optional)end_date for the logs
|
124
|
+
# @param period (optional)period for the logs
|
101
125
|
def weight_logs(start_date: nil, end_date: nil, period: nil)
|
102
126
|
unless start_date
|
103
127
|
raise FitgemOauth2::InvalidArgumentError, 'start_date not specified.'
|
@@ -123,11 +147,14 @@ module FitgemOauth2
|
|
123
147
|
get_call(url + '.json')
|
124
148
|
end
|
125
149
|
|
126
|
-
|
150
|
+
# logs weight for the user
|
151
|
+
# @param params POST message for logging weight
|
127
152
|
def log_weight(params)
|
128
153
|
post_call("user/#{user_id}/body/log/weight.json", params)
|
129
154
|
end
|
130
155
|
|
156
|
+
# delete logged weight
|
157
|
+
# @param id ID of the weight log to be deleted
|
131
158
|
def delete_logged_weight(id)
|
132
159
|
delete_call("user/#{user_id}/body/log/weight/#{id}.json")
|
133
160
|
end
|
@@ -4,6 +4,8 @@ module FitgemOauth2
|
|
4
4
|
# ==================================
|
5
5
|
# Devices
|
6
6
|
# ==================================
|
7
|
+
|
8
|
+
# return list of Fitbit devices linked to the account
|
7
9
|
def devices
|
8
10
|
get_call("user/#{user_id}/devices.json")
|
9
11
|
end
|
@@ -11,18 +13,31 @@ module FitgemOauth2
|
|
11
13
|
# ==================================
|
12
14
|
# Alarams
|
13
15
|
# ==================================
|
16
|
+
|
17
|
+
# returns list of alarams for the tracker ID
|
18
|
+
# @param tracker_id ID for the tracker for which alarams need to be retrieved
|
14
19
|
def alarms(tracker_id)
|
15
20
|
get_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json")
|
16
21
|
end
|
17
22
|
|
23
|
+
# adds an alaram
|
24
|
+
# @param tracker_id ID of the tracker to which the alaram needs to be added
|
25
|
+
# @param params POST parameters for adding the alarm
|
18
26
|
def add_alarm(tracker_id, params)
|
19
27
|
post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", params)
|
20
28
|
end
|
21
29
|
|
30
|
+
# update an existing alarm
|
31
|
+
# @param tracker_id ID of the tracker to which alaram needs to be added.
|
32
|
+
# @param alarm_id ID of the alarm that needs to be updated
|
33
|
+
# @param params POST parameters for updating the alarm
|
22
34
|
def update_alarm(tracker_id, alarm_id, params)
|
23
35
|
post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", params)
|
24
36
|
end
|
25
37
|
|
38
|
+
# removes an existing alaram
|
39
|
+
# @param tracker_id ID of the tracker from which alaram needs to be removed
|
40
|
+
# @params alarm_id ID of the alaram that needs to be removed
|
26
41
|
def remove_alarm(tracker_id, alarm_id)
|
27
42
|
delete_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
|
28
43
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module FitgemOauth2
|
2
2
|
class Client
|
3
|
+
# retrieves list of friends for the current user
|
3
4
|
def friends
|
4
5
|
get_call("user/#{user_id}/friends.json")
|
5
6
|
end
|
6
7
|
|
8
|
+
# retrieves leaderboard for the user
|
7
9
|
def friends_leaderboard
|
8
10
|
get_call("user/#{user_id}/friends/leaderboard.json")
|
9
11
|
end
|
@@ -12,14 +14,20 @@ module FitgemOauth2
|
|
12
14
|
# Friend Invitations
|
13
15
|
# ==================================
|
14
16
|
|
17
|
+
# send an invitation to a friend
|
18
|
+
# @param params POST parameters for sending friend invite.
|
15
19
|
def invite_friend(params)
|
16
20
|
post_call("user/#{user_id}/friends/invitations.json", params)
|
17
21
|
end
|
18
22
|
|
23
|
+
# retrieve list of friend invitations
|
19
24
|
def friend_invitations
|
20
25
|
get_call("user/#{user_id}/friends/invitations.json")
|
21
26
|
end
|
22
27
|
|
28
|
+
# respond to a friend invite
|
29
|
+
# @param from_user_id the ID of the friend
|
30
|
+
# @param params POST parameters for responding to the invite.
|
23
31
|
def respond_to_invitation(from_user_id, params)
|
24
32
|
post_call("user/#{user_id}/friends/invitations/#{from_user_id}.json", params)
|
25
33
|
end
|
@@ -28,6 +36,7 @@ module FitgemOauth2
|
|
28
36
|
# Badges
|
29
37
|
# ==================================
|
30
38
|
|
39
|
+
# retrieve badges for the user
|
31
40
|
def badges
|
32
41
|
get_call("user/#{user_id}/badges.json")
|
33
42
|
end
|
@@ -4,6 +4,7 @@ module FitgemOauth2
|
|
4
4
|
HR_PERIODS = %w(1d 7d 30d 1w 1m)
|
5
5
|
HR_DETAIL_LEVELS = %w(1sec 1min)
|
6
6
|
|
7
|
+
# retrieve heartrate time series
|
7
8
|
def heartrate_time_series(start_date: nil, end_date: nil, period: nil)
|
8
9
|
unless start_date
|
9
10
|
raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.'
|
@@ -28,6 +29,7 @@ module FitgemOauth2
|
|
28
29
|
get_call(url + '.json')
|
29
30
|
end
|
30
31
|
|
32
|
+
# retrieve intraday series for heartrate
|
31
33
|
def intraday_heartrate_time_series(start_date: nil, end_date: nil, detail_level: nil, start_time: nil, end_time: nil)
|
32
34
|
unless start_date
|
33
35
|
raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.'
|
data/lib/fitgem_oauth2/sleep.rb
CHANGED
@@ -5,18 +5,28 @@ module FitgemOauth2
|
|
5
5
|
SLEEP_RESOURCES = %w(startTime timeInBed minutesAsleep awakeningsCount minutesAwake minutesToFallAsleep minutesAfterWakeup efficiency)
|
6
6
|
SLEEP_PERIODS = %w(1d 7d 30d 1w 1m 3m 6m 1y max)
|
7
7
|
|
8
|
+
# retrieve sleep logs for a date
|
9
|
+
# @param date date for which sleep logs needs to be accessed
|
8
10
|
def sleep_logs(date)
|
9
11
|
get_call("user/#{user_id}/sleep/date/#{format_date(date)}.json")
|
10
12
|
end
|
11
13
|
|
14
|
+
# retrieve sleep goal for the user
|
12
15
|
def sleep_goal
|
13
16
|
get_call("user/#{user_id}/sleep/goal.json")
|
14
17
|
end
|
15
18
|
|
19
|
+
# update sleep goal
|
20
|
+
# @param params POST parameters for updating sleep goal
|
16
21
|
def update_sleep_goal(params)
|
17
22
|
post_call("user/#{user_id}/sleep/goal.json", params)
|
18
23
|
end
|
19
24
|
|
25
|
+
# retrieve time series data for sleep
|
26
|
+
# @param resource sleep resource to be requested
|
27
|
+
# @param start_date starting date for sleep time series
|
28
|
+
# @param end_date ending date for sleep time series
|
29
|
+
# @param period period for sleep time series
|
20
30
|
def sleep_time_series(resource: nil, start_date: nil, end_date: nil, period: nil)
|
21
31
|
unless start_date
|
22
32
|
raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.'
|
@@ -41,10 +51,14 @@ module FitgemOauth2
|
|
41
51
|
get_call(url + '.json')
|
42
52
|
end
|
43
53
|
|
54
|
+
# log sleep
|
55
|
+
# @param params POST params for creating sleep log
|
44
56
|
def log_sleep(params)
|
45
57
|
post_call("user/#{user_id}/sleep.json", params)
|
46
58
|
end
|
47
59
|
|
60
|
+
# deleted sleep log
|
61
|
+
# @param log_id ID of the sleep log that needs to be removed.
|
48
62
|
def delete_logged_sleep(log_id)
|
49
63
|
delete_call("user/#{user_id}/sleep/#{log_id}.json")
|
50
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitgem_oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Gupta
|
@@ -112,3 +112,4 @@ signing_key:
|
|
112
112
|
specification_version: 4
|
113
113
|
summary: Fitbit API client library
|
114
114
|
test_files: []
|
115
|
+
has_rdoc:
|