fitbit_api 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/fitbit_api/activities.rb +37 -43
- data/lib/fitbit_api/alarms.rb +26 -22
- data/lib/fitbit_api/body.rb +15 -14
- data/lib/fitbit_api/client.rb +16 -13
- data/lib/fitbit_api/devices.rb +2 -2
- data/lib/fitbit_api/food.rb +13 -12
- data/lib/fitbit_api/friends.rb +4 -4
- data/lib/fitbit_api/goals.rb +26 -26
- data/lib/fitbit_api/heart_rate.rb +3 -2
- data/lib/fitbit_api/sleep.rb +5 -4
- data/lib/fitbit_api/subscriptions.rb +38 -0
- data/lib/fitbit_api/user.rb +6 -6
- data/lib/fitbit_api/version.rb +1 -1
- data/lib/fitbit_api/water.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0199cc0ea15375afa47467c885ccf179c73955116fb9edf4a8f21bdfc4087867'
|
4
|
+
data.tar.gz: a394ad4302abe48783bc0bec9217a4132e5939cd067fc922d4e571cac7ea527e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 112c2fa3669262d9e86b09a356147ba6665f768b16a7fc096beb1a36de39350c2c79c5258b850fbe0027bab8a78bf5de2c237d79311406f3c537fd0d82a8f83d
|
7
|
+
data.tar.gz: fc9c32427092a0f4f3ccafe15c2a53c486bf7d0e67810bb957d384bb1a83bcc899615bbcf63d9ad881fa30ddbdc1bd7b1cc555ac4246c5c9c5f89bb074cfe9d6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
0.11.0
|
2
|
+
------
|
3
|
+
- Add support for subscriptions endpoints.
|
4
|
+
- Make `get` and `post` methods more ergonomic (can pass params & body directly instead of via nested object).
|
5
|
+
- Allow `delete` request method to specify query params.
|
6
|
+
- Remove per-request response payload transformations (can be set per-client).
|
7
|
+
|
8
|
+
0.10.2
|
9
|
+
------
|
10
|
+
- Fix docs for examples
|
11
|
+
|
12
|
+
0.10.1
|
13
|
+
------
|
14
|
+
- Fix docs for listed options
|
15
|
+
|
1
16
|
0.10.0
|
2
17
|
------
|
3
18
|
- Add `auto_refresh_token` config to make token auto-refreshing configurable (defaults to true).
|
@@ -20,32 +20,32 @@ module FitbitAPI
|
|
20
20
|
#
|
21
21
|
# @param date [Date] The date for which to retrieve the activity data.
|
22
22
|
|
23
|
-
def daily_activity_summary(date=Date.today
|
24
|
-
get("user/#{user_id}/activities/date/#{format_date(date)}.json"
|
23
|
+
def daily_activity_summary(date=Date.today)
|
24
|
+
get("user/#{user_id}/activities/date/#{format_date(date)}.json")
|
25
25
|
end
|
26
26
|
|
27
27
|
# Retrieves a list of a user's frequent activities in the format requested using
|
28
28
|
# units in the unit system which corresponds to the Accept-Language header provided.
|
29
29
|
|
30
|
-
def frequent_activities
|
31
|
-
get("user/#{user_id}/activities/frequent.json"
|
30
|
+
def frequent_activities
|
31
|
+
get("user/#{user_id}/activities/frequent.json")
|
32
32
|
end
|
33
33
|
|
34
|
-
def recent_activities
|
35
|
-
get("user/#{user_id}/activities/recent.json"
|
34
|
+
def recent_activities
|
35
|
+
get("user/#{user_id}/activities/recent.json")
|
36
36
|
end
|
37
37
|
|
38
38
|
# Returns a list of a user's favorite activities.
|
39
39
|
|
40
|
-
def favorite_activities
|
41
|
-
get("user/#{user_id}/activities/favorite.json"
|
40
|
+
def favorite_activities
|
41
|
+
get("user/#{user_id}/activities/favorite.json")
|
42
42
|
end
|
43
43
|
|
44
|
-
# Gets a
|
44
|
+
# Gets a list of all valid Fitbit public activities from the activities catalog
|
45
45
|
# as well as private custom activities the user created.
|
46
46
|
|
47
|
-
def all_activities
|
48
|
-
get('activities.json'
|
47
|
+
def all_activities
|
48
|
+
get('activities.json')
|
49
49
|
end
|
50
50
|
|
51
51
|
# Retrieves a list of a user's activity log entries before or after a given day
|
@@ -54,22 +54,15 @@ module FitbitAPI
|
|
54
54
|
#
|
55
55
|
# activity_logs_list(before_date: Date.parse('2021-05-24'), limit: 5)
|
56
56
|
#
|
57
|
-
# @
|
58
|
-
# @
|
59
|
-
# @
|
60
|
-
# @
|
61
|
-
# @
|
62
|
-
|
63
|
-
def activity_logs_list(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# move param values from top-level opts into :params sub-hash
|
68
|
-
param_defaults.each do |key, default_val|
|
69
|
-
opts[:params][key] = opts.delete(key) || default_val
|
70
|
-
end
|
71
|
-
|
72
|
-
get("user/#{user_id}/activities/list.json", opts)
|
57
|
+
# @param before_date [Date] Specify when filtering entries that occured before the given date
|
58
|
+
# @param after_date [Date] Specify when filtering entries that occured after the given date
|
59
|
+
# @param sort [String] the Sort order of entries by date (asc or desc)
|
60
|
+
# @param offset [Integer] The offset number of entries. Must always be 0
|
61
|
+
# @param limit [Integer] The max of the number of entries returned (max: 20)
|
62
|
+
|
63
|
+
def activity_logs_list(params={})
|
64
|
+
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
|
65
|
+
get("user/#{user_id}/activities/list.json", default_params.merge(params))
|
73
66
|
end
|
74
67
|
|
75
68
|
# Returns the details of a specific activity in the Fitbit activities database in the format requested.
|
@@ -86,8 +79,8 @@ module FitbitAPI
|
|
86
79
|
# Activity statistics includes Lifetime and Best achievement values from the
|
87
80
|
# My Achievements tile on the website dashboard.
|
88
81
|
|
89
|
-
def lifetime_stats
|
90
|
-
get("user/#{user_id}/activities.json"
|
82
|
+
def lifetime_stats
|
83
|
+
get("user/#{user_id}/activities.json")
|
91
84
|
end
|
92
85
|
|
93
86
|
def activity_time_series(resource, opts={})
|
@@ -108,10 +101,11 @@ module FitbitAPI
|
|
108
101
|
end
|
109
102
|
|
110
103
|
if period
|
111
|
-
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
104
|
+
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
112
105
|
else
|
113
|
-
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
106
|
+
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
114
107
|
end
|
108
|
+
|
115
109
|
# remove root key from response
|
116
110
|
result.values[0]
|
117
111
|
end
|
@@ -151,19 +145,19 @@ module FitbitAPI
|
|
151
145
|
# Creates log entry for an activity or user's private custom activity using units
|
152
146
|
# in the unit system which corresponds to the Accept-Language header provided.
|
153
147
|
#
|
154
|
-
# log_activity(
|
148
|
+
# log_activity(activity_id: 90013, manual_calories: 300, duration_millis: 6000000)
|
155
149
|
#
|
156
|
-
# @
|
157
|
-
# @
|
158
|
-
# @
|
159
|
-
# @
|
160
|
-
# @
|
161
|
-
# @
|
162
|
-
# @
|
163
|
-
# @
|
164
|
-
|
165
|
-
def log_activity(
|
166
|
-
post("user/#{user_id}/activities.json",
|
150
|
+
# @param activity_id [Integer, String] The activity ID
|
151
|
+
# @param activity_name [String] Custom activity name. Either activity ID or activity_name must be provided
|
152
|
+
# @param manual_calories [Integer] Calories burned, specified manually. Required with activity_name, otherwise optional
|
153
|
+
# @param start_time [String] Activity start time; formatted in HH:mm:ss
|
154
|
+
# @param duration_millis [Integer] Duration in milliseconds
|
155
|
+
# @param date [String] Log entry date; formatted in yyyy-MM-dd
|
156
|
+
# @param distance [Integer] Distance; required for logging directory activity
|
157
|
+
# @param distance_unit [String] Distance measurement unit
|
158
|
+
|
159
|
+
def log_activity(body)
|
160
|
+
post("user/#{user_id}/activities.json", body)
|
167
161
|
end
|
168
162
|
|
169
163
|
# Adds the activity with the given ID to user's list of favorite activities.
|
data/lib/fitbit_api/alarms.rb
CHANGED
@@ -7,8 +7,8 @@ module FitbitAPI
|
|
7
7
|
#
|
8
8
|
# @params tracker_id [Integer] The ID of the tracker for which the data is returned
|
9
9
|
|
10
|
-
def alarms(tracker_id
|
11
|
-
get("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json"
|
10
|
+
def alarms(tracker_id)
|
11
|
+
get("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json")
|
12
12
|
end
|
13
13
|
|
14
14
|
# POST Alarms
|
@@ -16,35 +16,37 @@ module FitbitAPI
|
|
16
16
|
|
17
17
|
# Adds the alarm settings to a given ID for a given device.
|
18
18
|
#
|
19
|
-
# add_alarm(
|
19
|
+
# add_alarm(123, time: "07:15-08:00", recurring: true, week_days: "MONDAY,FRIDAY,SATURDAY")
|
20
20
|
#
|
21
21
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is created
|
22
22
|
#
|
23
|
-
# @
|
24
|
-
# @
|
25
|
-
# @
|
26
|
-
# @
|
23
|
+
# @param time [String] Time of day that the alarm vibrates with a UTC timezone offset, e.g. 07:15-08:00
|
24
|
+
# @param enabled [Boolean] If false, alarm does not vibrate until enabled is set to true
|
25
|
+
# @param recurring [Boolean] If false, the alarm is a single event
|
26
|
+
# @param week_days [String] Comma separated list of days of the week on which the alarm vibrates (MONDAY,TUESDAY)
|
27
27
|
|
28
|
-
def add_alarm(tracker_id,
|
29
|
-
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json",
|
28
|
+
def add_alarm(tracker_id, body={})
|
29
|
+
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", body)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Updates the alarm entry with a given ID for a given device.
|
33
33
|
#
|
34
|
+
# update_alarm(123, 987, week_days: "TUESDAY,SUNDAY")
|
35
|
+
#
|
34
36
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is created
|
35
37
|
# @param alarm_id [Integer] The ID of the alarm to be updated
|
36
38
|
#
|
37
|
-
# @
|
38
|
-
# @
|
39
|
-
# @
|
40
|
-
# @
|
41
|
-
# @
|
42
|
-
# @
|
43
|
-
# @
|
44
|
-
# @
|
45
|
-
|
46
|
-
def update_alarm(tracker_id, alarm_id,
|
47
|
-
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json",
|
39
|
+
# @param time [String] Time of day that the alarm vibrates with a UTC timezone offset, e.g. 07:15-08:00
|
40
|
+
# @param enabled [Boolean] If false, alarm does not vibrate until enabled is set to true
|
41
|
+
# @param recurring [Boolean] If false, the alarm is a single event
|
42
|
+
# @param week_days [String] Comma separated list of days of the week on which the alarm vibrates (MONDAY,TUESDAY)
|
43
|
+
# @param snooze_length [Integer] Minutes between alarms
|
44
|
+
# @param snooze_count [Integer] Maximum snooze count
|
45
|
+
# @param label [String] Label for alarm
|
46
|
+
# @param vibe [String] Vibe pattern; only one value for now (DEFAULT)
|
47
|
+
|
48
|
+
def update_alarm(tracker_id, alarm_id, body={})
|
49
|
+
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", body)
|
48
50
|
end
|
49
51
|
|
50
52
|
# DELETE Alarms
|
@@ -52,11 +54,13 @@ module FitbitAPI
|
|
52
54
|
|
53
55
|
# Deletes the user's device alarm entry with the given ID for a given device.
|
54
56
|
#
|
57
|
+
# delete_alarm(123, 987)
|
58
|
+
#
|
55
59
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is to be deleted
|
56
60
|
# @param alarm_id [Integer] The ID of the alarm to be deleted
|
57
61
|
|
58
|
-
def delete_alarm(tracker_id, alarm_id
|
59
|
-
delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json"
|
62
|
+
def delete_alarm(tracker_id, alarm_id)
|
63
|
+
delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
data/lib/fitbit_api/body.rb
CHANGED
@@ -2,12 +2,12 @@ module FitbitAPI
|
|
2
2
|
class Client
|
3
3
|
BODY_RESOURCES = %w(bmi fat weight)
|
4
4
|
|
5
|
-
def weight_logs(date=Date.today
|
6
|
-
get("user/-/body/log/weight/date/#{format_date(date)}.json"
|
5
|
+
def weight_logs(date=Date.today)
|
6
|
+
get("user/-/body/log/weight/date/#{format_date(date)}.json")
|
7
7
|
end
|
8
8
|
|
9
|
-
def body_fat_logs(date=Date.today
|
10
|
-
get("user/-/body/log/fat/date/#{format_date(date)}.json"
|
9
|
+
def body_fat_logs(date=Date.today)
|
10
|
+
get("user/-/body/log/fat/date/#{format_date(date)}.json")
|
11
11
|
end
|
12
12
|
|
13
13
|
def body_time_series(resource, opts={})
|
@@ -28,28 +28,29 @@ module FitbitAPI
|
|
28
28
|
end
|
29
29
|
|
30
30
|
if period
|
31
|
-
result = get("user/#{user_id}/body/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
31
|
+
result = get("user/#{user_id}/body/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
32
32
|
else
|
33
|
-
result = get("user/#{user_id}/body/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
33
|
+
result = get("user/#{user_id}/body/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
34
34
|
end
|
35
|
+
|
35
36
|
# remove root key from response
|
36
37
|
result.values[0]
|
37
38
|
end
|
38
39
|
|
39
|
-
def log_weight(
|
40
|
-
post("user/#{user_id}/body/log/weight.json",
|
40
|
+
def log_weight(body)
|
41
|
+
post("user/#{user_id}/body/log/weight.json", body)
|
41
42
|
end
|
42
43
|
|
43
|
-
def delete_weight_log(weight_log_id
|
44
|
-
delete("user/#{user_id}/body/log/weight/#{weight_log_id}.json"
|
44
|
+
def delete_weight_log(weight_log_id)
|
45
|
+
delete("user/#{user_id}/body/log/weight/#{weight_log_id}.json")
|
45
46
|
end
|
46
47
|
|
47
|
-
def log_body_fat(
|
48
|
-
post("user/#{user_id}/body/log/fat.json",
|
48
|
+
def log_body_fat(body)
|
49
|
+
post("user/#{user_id}/body/log/fat.json", body)
|
49
50
|
end
|
50
51
|
|
51
|
-
def delete_body_fat_log(body_fat_log_id
|
52
|
-
delete("user/#{user_id}/body/log/fat/#{body_fat_log_id}.json"
|
52
|
+
def delete_body_fat_log(body_fat_log_id)
|
53
|
+
delete("user/#{user_id}/body/log/fat/#{body_fat_log_id}.json")
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
data/lib/fitbit_api/client.rb
CHANGED
@@ -8,6 +8,7 @@ require 'fitbit_api/devices'
|
|
8
8
|
require 'fitbit_api/food'
|
9
9
|
require 'fitbit_api/friends'
|
10
10
|
require 'fitbit_api/sleep'
|
11
|
+
require 'fitbit_api/subscriptions'
|
11
12
|
require 'fitbit_api/user'
|
12
13
|
require 'fitbit_api/water'
|
13
14
|
|
@@ -46,16 +47,16 @@ module FitbitAPI
|
|
46
47
|
@token
|
47
48
|
end
|
48
49
|
|
49
|
-
def get(path, opts={})
|
50
|
-
request(:get, path, opts)
|
50
|
+
def get(path, params={}, opts={})
|
51
|
+
request(:get, path, opts.merge(params: params))
|
51
52
|
end
|
52
53
|
|
53
|
-
def post(path, opts={})
|
54
|
-
request(:post, path, opts)
|
54
|
+
def post(path, body={}, opts={})
|
55
|
+
request(:post, path, opts.merge(body: body))
|
55
56
|
end
|
56
57
|
|
57
|
-
def delete(path, opts={})
|
58
|
-
request(:delete, path, opts)
|
58
|
+
def delete(path, params={}, opts={})
|
59
|
+
request(:delete, path, opts.merge(params: params))
|
59
60
|
end
|
60
61
|
|
61
62
|
private
|
@@ -116,6 +117,7 @@ module FitbitAPI
|
|
116
117
|
|
117
118
|
def request(verb, path, opts={})
|
118
119
|
request_path = "#{@api_version}/#{path}"
|
120
|
+
request_headers = default_request_headers.merge(opts[:headers] || {})
|
119
121
|
request_options = opts.merge(headers: request_headers)
|
120
122
|
|
121
123
|
deep_keys_to_camel_case!(request_options[:params])
|
@@ -124,16 +126,16 @@ module FitbitAPI
|
|
124
126
|
refresh_token! if auto_refresh_token && token.expired?
|
125
127
|
|
126
128
|
response = token.public_send(verb, request_path, request_options).response
|
127
|
-
|
129
|
+
response_body = MultiJson.load(response.body) unless response.status == 204
|
128
130
|
|
129
|
-
process_keys!(
|
131
|
+
process_keys!(response_body)
|
130
132
|
end
|
131
133
|
|
132
134
|
def auth_headers
|
133
135
|
{ 'Authorization' => ('Basic ' + Base64.encode64(@client_id + ':' + @client_secret)) }
|
134
136
|
end
|
135
137
|
|
136
|
-
def
|
138
|
+
def default_request_headers
|
137
139
|
{
|
138
140
|
'User-Agent' => "fitbit_api gem (v#{FitbitAPI::VERSION})",
|
139
141
|
'Accept-Language' => @unit_system,
|
@@ -141,10 +143,11 @@ module FitbitAPI
|
|
141
143
|
}
|
142
144
|
end
|
143
145
|
|
144
|
-
def process_keys!(object
|
145
|
-
deep_keys_to_snake_case!(object) if
|
146
|
-
deep_symbolize_keys!(object) if
|
147
|
-
|
146
|
+
def process_keys!(object)
|
147
|
+
deep_keys_to_snake_case!(object) if snake_case_keys
|
148
|
+
deep_symbolize_keys!(object) if symbolize_keys
|
149
|
+
|
150
|
+
object
|
148
151
|
end
|
149
152
|
end
|
150
153
|
end
|
data/lib/fitbit_api/devices.rb
CHANGED
data/lib/fitbit_api/food.rb
CHANGED
@@ -2,24 +2,24 @@ module FitbitAPI
|
|
2
2
|
class Client
|
3
3
|
FOOD_RESOURCES = %w(caloriesIn water)
|
4
4
|
|
5
|
-
def food_logs(date=Date.today
|
6
|
-
get("user/#{user_id}/foods/log/date/#{format_date(date)}.json"
|
5
|
+
def food_logs(date=Date.today)
|
6
|
+
get("user/#{user_id}/foods/log/date/#{format_date(date)}.json")
|
7
7
|
end
|
8
8
|
|
9
|
-
def recent_foods
|
10
|
-
get("user/#{user_id}/foods/log/recent.json"
|
9
|
+
def recent_foods
|
10
|
+
get("user/#{user_id}/foods/log/recent.json")
|
11
11
|
end
|
12
12
|
|
13
|
-
def frequent_foods
|
14
|
-
get("user/#{user_id}/foods/log/frequent.json"
|
13
|
+
def frequent_foods
|
14
|
+
get("user/#{user_id}/foods/log/frequent.json")
|
15
15
|
end
|
16
16
|
|
17
|
-
def favorite_foods
|
18
|
-
get("user/#{user_id}/foods/log/favorite.json"
|
17
|
+
def favorite_foods
|
18
|
+
get("user/#{user_id}/foods/log/favorite.json")
|
19
19
|
end
|
20
20
|
|
21
|
-
def food_goals
|
22
|
-
get("user/#{user_id}/foods/log/goal.json"
|
21
|
+
def food_goals
|
22
|
+
get("user/#{user_id}/foods/log/goal.json")
|
23
23
|
end
|
24
24
|
|
25
25
|
def food_time_series(resource, opts={})
|
@@ -40,10 +40,11 @@ module FitbitAPI
|
|
40
40
|
end
|
41
41
|
|
42
42
|
if period
|
43
|
-
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
43
|
+
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
44
44
|
else
|
45
|
-
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
45
|
+
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
46
46
|
end
|
47
|
+
|
47
48
|
# remove root key from response
|
48
49
|
result.values[0]
|
49
50
|
end
|
data/lib/fitbit_api/friends.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
def friends
|
4
|
-
get("user/#{user_id}/friends.json"
|
3
|
+
def friends
|
4
|
+
get("user/#{user_id}/friends.json")
|
5
5
|
end
|
6
6
|
|
7
|
-
def friends_leaderboard
|
8
|
-
get("user/#{user_id}/friends/leaderboard.json"
|
7
|
+
def friends_leaderboard
|
8
|
+
get("user/#{user_id}/friends/leaderboard.json")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/fitbit_api/goals.rb
CHANGED
@@ -5,26 +5,26 @@ module FitbitAPI
|
|
5
5
|
|
6
6
|
# Retrieves a user's current weight goal.
|
7
7
|
|
8
|
-
def weight_goal
|
9
|
-
get("user/-/body/log/weight/goal.json"
|
8
|
+
def weight_goal
|
9
|
+
get("user/-/body/log/weight/goal.json")
|
10
10
|
end
|
11
11
|
|
12
12
|
# Retrieves a user's current body fat percentage goal.
|
13
13
|
|
14
|
-
def body_fat_goal
|
15
|
-
get("user/-/body/log/fat/goal.json"
|
14
|
+
def body_fat_goal
|
15
|
+
get("user/-/body/log/fat/goal.json")
|
16
16
|
end
|
17
17
|
|
18
18
|
# Retrieves a user's current daily activity goals.
|
19
19
|
|
20
|
-
def daily_goals
|
21
|
-
get("user/#{user_id}/activities/goals/daily.json"
|
20
|
+
def daily_goals
|
21
|
+
get("user/#{user_id}/activities/goals/daily.json")
|
22
22
|
end
|
23
23
|
|
24
24
|
# Retrieves a user's current weekly activity goals.
|
25
25
|
|
26
|
-
def weekly_goals
|
27
|
-
get("user/#{user_id}/activities/goals/weekly.json"
|
26
|
+
def weekly_goals
|
27
|
+
get("user/#{user_id}/activities/goals/weekly.json")
|
28
28
|
end
|
29
29
|
|
30
30
|
# POST Goals
|
@@ -33,31 +33,31 @@ module FitbitAPI
|
|
33
33
|
# Creates or updates a user's daily activity goals and returns a response using units
|
34
34
|
# in the unit system which corresponds to the Accept-Language header provided.
|
35
35
|
#
|
36
|
-
# create_or_update_daily_goals(
|
36
|
+
# create_or_update_daily_goals(calories_out: 2000, active_minutes: 90, floors: 5)
|
37
37
|
#
|
38
|
-
# @
|
39
|
-
# @
|
40
|
-
# @
|
41
|
-
# @
|
42
|
-
# @
|
43
|
-
|
44
|
-
def create_or_update_daily_goals(
|
45
|
-
post("user/#{user_id}/activities/goals/daily.json",
|
38
|
+
# @param calories_out [Integer] Calories output goal value
|
39
|
+
# @param active_minutes [Integer] Active minutes goal value
|
40
|
+
# @param floors [Integer] Floor goal value
|
41
|
+
# @param distance [Integer, Float] Distance goal value
|
42
|
+
# @param steps [Integer] Steps goal value
|
43
|
+
|
44
|
+
def create_or_update_daily_goals(body={})
|
45
|
+
post("user/#{user_id}/activities/goals/daily.json", body)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Creates or updates a user's weekly activity goals and returns a response using units
|
49
49
|
# in the unit system which corresponds to the Accept-Language header provided.
|
50
50
|
#
|
51
|
-
# create_or_update_weekly_goals(
|
51
|
+
# create_or_update_weekly_goals(active_minutes: 300, floors: 20)
|
52
52
|
#
|
53
|
-
# @
|
54
|
-
# @
|
55
|
-
# @
|
56
|
-
# @
|
57
|
-
# @
|
58
|
-
|
59
|
-
def create_or_update_weekly_goals(
|
60
|
-
post("user/#{user_id}/activities/goals/weekly.json",
|
53
|
+
# @param calories_out [Integer] Calories output goal value
|
54
|
+
# @param active_minutes [Integer] Active minutes goal value
|
55
|
+
# @param floors [Integer] Floor goal value
|
56
|
+
# @param distance [Integer, Float] Distance goal value
|
57
|
+
# @param steps [Integer] Steps goal value
|
58
|
+
|
59
|
+
def create_or_update_weekly_goals(body={})
|
60
|
+
post("user/#{user_id}/activities/goals/weekly.json", body)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -14,10 +14,11 @@ module FitbitAPI
|
|
14
14
|
end
|
15
15
|
|
16
16
|
if period
|
17
|
-
result = get("user/#{user_id}/activities/heart/date/#{format_date(end_date)}/#{period}.json"
|
17
|
+
result = get("user/#{user_id}/activities/heart/date/#{format_date(end_date)}/#{period}.json")
|
18
18
|
else
|
19
|
-
result = get("user/#{user_id}/activities/heart/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
19
|
+
result = get("user/#{user_id}/activities/heart/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
20
20
|
end
|
21
|
+
|
21
22
|
# remove root key from response
|
22
23
|
result.values[0]
|
23
24
|
end
|
data/lib/fitbit_api/sleep.rb
CHANGED
@@ -3,8 +3,8 @@ module FitbitAPI
|
|
3
3
|
SLEEP_RESOURCES = %w(startTime timeInBed minutesAsleep awakeningsCount
|
4
4
|
minutesAwake minutesToFallAsleep minutesAfterWakeup efficiency)
|
5
5
|
|
6
|
-
def sleep_logs(date=Date.today
|
7
|
-
get("user/#{user_id}/sleep/date/#{format_date(date)}.json"
|
6
|
+
def sleep_logs(date=Date.today)
|
7
|
+
get("user/#{user_id}/sleep/date/#{format_date(date)}.json")
|
8
8
|
end
|
9
9
|
|
10
10
|
def sleep_time_series(resource, opts={})
|
@@ -25,10 +25,11 @@ module FitbitAPI
|
|
25
25
|
end
|
26
26
|
|
27
27
|
if period
|
28
|
-
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
28
|
+
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
29
29
|
else
|
30
|
-
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
30
|
+
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
31
31
|
end
|
32
|
+
|
32
33
|
# remove root key from response
|
33
34
|
result.values[0]
|
34
35
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FitbitAPI
|
2
|
+
class Client
|
3
|
+
# Retrieves a list of subscriptions created by your application for a specific user.
|
4
|
+
# You can either fetch subscriptions for a specific collection or the entire list
|
5
|
+
# of subscriptions for the user.
|
6
|
+
#
|
7
|
+
# @param collection_path [String] Collection of data to retrieve notifications
|
8
|
+
|
9
|
+
def subscriptions(collection_path=nil)
|
10
|
+
get("#{subscriptions_path(collection_path)}.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
# Creates a subscription to notify the application when a user has new data available.
|
14
|
+
#
|
15
|
+
# @param collection_path [String] Collection of data to retrieve notifications
|
16
|
+
# @param subscription_id [Integer] The unique ID of the subscription created by the API client application
|
17
|
+
|
18
|
+
def create_subscription(collection_path=nil, subscription_id)
|
19
|
+
post("#{subscriptions_path(collection_path)}/#{subscription_id}.json")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Deletes a subscription for a specific user.
|
23
|
+
#
|
24
|
+
# @param collection_path [String] Collection of data to retrieve notifications
|
25
|
+
# @param subscription_id [Integer] The unique ID of the subscription created by the API client application
|
26
|
+
|
27
|
+
def delete_subscription(collection_path=nil, subscription_id)
|
28
|
+
delete("#{subscriptions_path(collection_path)}/#{subscription_id}.json")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def subscriptions_path(collection_path=nil)
|
34
|
+
collection_path = "#{collection_path}/" if collection_path
|
35
|
+
"user/#{user_id}/#{collection_path}apiSubscriptions"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/fitbit_api/user.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
def profile
|
4
|
-
get("user/#{user_id}/profile.json"
|
3
|
+
def profile
|
4
|
+
get("user/#{user_id}/profile.json")
|
5
5
|
end
|
6
6
|
|
7
|
-
def badges
|
8
|
-
get("user/#{user_id}/badges.json"
|
7
|
+
def badges
|
8
|
+
get("user/#{user_id}/badges.json")
|
9
9
|
end
|
10
10
|
|
11
|
-
def update_profile(
|
12
|
-
post("user/#{user_id}/profile.json",
|
11
|
+
def update_profile(body)
|
12
|
+
post("user/#{user_id}/profile.json", body)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/fitbit_api/version.rb
CHANGED
data/lib/fitbit_api/water.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
def water_logs(date=Date.today
|
4
|
-
get("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json"
|
3
|
+
def water_logs(date=Date.today)
|
4
|
+
get("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json")
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbit_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/fitbit_api/helpers/exceptions.rb
|
111
111
|
- lib/fitbit_api/helpers/utils.rb
|
112
112
|
- lib/fitbit_api/sleep.rb
|
113
|
+
- lib/fitbit_api/subscriptions.rb
|
113
114
|
- lib/fitbit_api/user.rb
|
114
115
|
- lib/fitbit_api/version.rb
|
115
116
|
- lib/fitbit_api/water.rb
|