fitbit_api 0.10.2 → 0.12.1
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/.github/workflows/test.yml +29 -0
- data/CHANGELOG.md +26 -0
- data/README.md +1 -1
- data/fitbit_api.gemspec +3 -3
- data/lib/fitbit_api/activities.rb +48 -59
- data/lib/fitbit_api/alarms.rb +26 -33
- data/lib/fitbit_api/body.rb +15 -14
- data/lib/fitbit_api/client.rb +19 -15
- data/lib/fitbit_api/devices.rb +4 -2
- data/lib/fitbit_api/food.rb +84 -12
- data/lib/fitbit_api/friends.rb +8 -4
- data/lib/fitbit_api/goals.rb +84 -29
- data/lib/fitbit_api/heart_rate.rb +5 -4
- data/lib/fitbit_api/helpers/utils.rb +0 -2
- data/lib/fitbit_api/meals.rb +42 -0
- data/lib/fitbit_api/sleep.rb +42 -4
- data/lib/fitbit_api/subscriptions.rb +38 -0
- data/lib/fitbit_api/user.rb +14 -6
- data/lib/fitbit_api/version.rb +1 -1
- data/lib/fitbit_api/water.rb +31 -2
- metadata +17 -15
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cced5004604fd14351b0539ffe29efc102d6297f0a73e6d64edd6e4f18b24975
|
4
|
+
data.tar.gz: 66a12b7d4b92c0c75e0958b5f69ddbb87f376bc4196bebd8884804df09bf33d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3b0ee2261afc4a254dc3673796198e9dc832e78a21241b84a7c11a0f39d396fc8647abf6826a0c4aa3a3be731a63b812dcf4d0de9a45c3fb6ccae9b9297612
|
7
|
+
data.tar.gz: 67526aba18a4fe518d5d0b05e8a48979009fc3435ed627c59bff341872e6917387c14ae83709d2ae84c0ff5e16000bf2fca55a89870a436f41b5a389b6b33a2a
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
permissions:
|
8
|
+
contents: read
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version:
|
16
|
+
- 2.6
|
17
|
+
- 2.7
|
18
|
+
- 3.0
|
19
|
+
- 3.1
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v3
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby-version }}
|
27
|
+
bundler-cache: true
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
0.12.1
|
2
|
+
------
|
3
|
+
- Some docs improvements
|
4
|
+
|
5
|
+
0.12.0
|
6
|
+
------
|
7
|
+
- Expand endpont support for foods (searching foods, creating custom foods, updating/deleting logs).
|
8
|
+
- Expand endpoint support for water logging (create, update, delete water logs).
|
9
|
+
- Expand endpoint support for sleep (list sleep logs, create/delete sleep logs).
|
10
|
+
- Expand endpoint support for goals (food, sleep, water goals).
|
11
|
+
- Add endpoint support for meals.
|
12
|
+
- Allow `get`, `post`, and `delete` methods to accept blocks.
|
13
|
+
- Switch to Github Actions for CI.
|
14
|
+
- Rename a few methods for better accuracy/clarity:
|
15
|
+
- daily_goals -> daily_activity_goals
|
16
|
+
- weekly_goals -> weekly_activity_goals
|
17
|
+
- create_or_update_daily_goals -> update_daily_activity_goals
|
18
|
+
- create_or_update_weekly_goals -> update_weekly_activity_goals
|
19
|
+
|
20
|
+
0.11.0
|
21
|
+
------
|
22
|
+
- Add support for subscriptions endpoints.
|
23
|
+
- Make `get` and `post` methods more ergonomic (can pass params & body directly instead of via nested object).
|
24
|
+
- Allow `delete` request method to specify query params.
|
25
|
+
- Remove per-request response payload transformations (can be set per-client).
|
26
|
+
|
1
27
|
0.10.2
|
2
28
|
------
|
3
29
|
- Fix docs for examples
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# FitbitAPI
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/fitbit_api)
|
4
|
-
[](https://github.com/zokioki/fitbit_api/actions/workflows/test.yml)
|
5
5
|
|
6
6
|
FitbitAPI provides a Ruby interface to the [Fitbit Web API](https://dev.fitbit.com/reference/web-api).
|
7
7
|
|
data/fitbit_api.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency 'oauth2', '~> 1.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'byebug'
|
24
|
+
spec.add_development_dependency 'byebug', '~> 11.0'
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2.3'
|
26
|
-
spec.add_development_dependency 'rake', '
|
27
|
-
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.11'
|
28
28
|
end
|
@@ -11,41 +11,38 @@ module FitbitAPI
|
|
11
11
|
|
12
12
|
ACTIVITY_INTRADAY_RESOURCES = %w(calories steps distance floors elevation)
|
13
13
|
|
14
|
-
#
|
15
|
-
# ==============
|
16
|
-
|
17
|
-
# Retrieves a summary and list of a user's activities and activity log entries
|
18
|
-
# for a given day in the format requested using units in the unit system which
|
19
|
-
# corresponds to the Accept-Language header provided.
|
14
|
+
# Retrieves a summary and list of a user's activities and activity log entries for a given day.
|
20
15
|
#
|
21
16
|
# @param date [Date] The date for which to retrieve the activity data.
|
22
17
|
|
23
|
-
def daily_activity_summary(date=Date.today
|
24
|
-
get("user/#{user_id}/activities/date/#{format_date(date)}.json"
|
18
|
+
def daily_activity_summary(date=Date.today)
|
19
|
+
get("user/#{user_id}/activities/date/#{format_date(date)}.json")
|
25
20
|
end
|
26
21
|
|
27
|
-
# Retrieves a list of a user's frequent activities
|
28
|
-
# units in the unit system which corresponds to the Accept-Language header provided.
|
22
|
+
# Retrieves a list of a user's frequent activities.
|
29
23
|
|
30
|
-
def frequent_activities
|
31
|
-
get("user/#{user_id}/activities/frequent.json"
|
24
|
+
def frequent_activities
|
25
|
+
get("user/#{user_id}/activities/frequent.json")
|
32
26
|
end
|
33
27
|
|
34
|
-
|
35
|
-
|
28
|
+
# Retrieves a list of a user's recent activities types logged with some details
|
29
|
+
# of the last activity log of that type.
|
30
|
+
|
31
|
+
def recent_activities
|
32
|
+
get("user/#{user_id}/activities/recent.json")
|
36
33
|
end
|
37
34
|
|
38
35
|
# Returns a list of a user's favorite activities.
|
39
36
|
|
40
|
-
def favorite_activities
|
41
|
-
get("user/#{user_id}/activities/favorite.json"
|
37
|
+
def favorite_activities
|
38
|
+
get("user/#{user_id}/activities/favorite.json")
|
42
39
|
end
|
43
40
|
|
44
|
-
# Gets a
|
41
|
+
# Gets a list of all valid Fitbit public activities from the activities catalog
|
45
42
|
# as well as private custom activities the user created.
|
46
43
|
|
47
|
-
def all_activities
|
48
|
-
get('activities.json'
|
44
|
+
def all_activities
|
45
|
+
get('activities.json')
|
49
46
|
end
|
50
47
|
|
51
48
|
# Retrieves a list of a user's activity log entries before or after a given day
|
@@ -54,22 +51,17 @@ module FitbitAPI
|
|
54
51
|
#
|
55
52
|
# activity_logs_list(before_date: Date.parse('2021-05-24'), limit: 5)
|
56
53
|
#
|
57
|
-
# @param
|
58
|
-
#
|
59
|
-
# @
|
60
|
-
# @
|
61
|
-
# @
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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)
|
54
|
+
# @param params [Hash] The request parameters
|
55
|
+
#
|
56
|
+
# @option params :before_date [Date] Specify when filtering entries that occured before the given date
|
57
|
+
# @option params :after_date [Date] Specify when filtering entries that occured after the given date
|
58
|
+
# @option params :sort [String] The Sort order of entries by date (asc or desc)
|
59
|
+
# @option params :offset [Integer] The offset number of entries. Must always be 0
|
60
|
+
# @option params :limit [Integer] The max of the number of entries returned (max: 20)
|
61
|
+
|
62
|
+
def activity_logs_list(params={})
|
63
|
+
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
|
64
|
+
get("user/#{user_id}/activities/list.json", default_params.merge(params))
|
73
65
|
end
|
74
66
|
|
75
67
|
# Returns the details of a specific activity in the Fitbit activities database in the format requested.
|
@@ -86,8 +78,8 @@ module FitbitAPI
|
|
86
78
|
# Activity statistics includes Lifetime and Best achievement values from the
|
87
79
|
# My Achievements tile on the website dashboard.
|
88
80
|
|
89
|
-
def lifetime_stats
|
90
|
-
get("user/#{user_id}/activities.json"
|
81
|
+
def lifetime_stats
|
82
|
+
get("user/#{user_id}/activities.json")
|
91
83
|
end
|
92
84
|
|
93
85
|
def activity_time_series(resource, opts={})
|
@@ -108,10 +100,11 @@ module FitbitAPI
|
|
108
100
|
end
|
109
101
|
|
110
102
|
if period
|
111
|
-
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
103
|
+
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
112
104
|
else
|
113
|
-
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
105
|
+
result = get("user/#{user_id}/activities/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
114
106
|
end
|
107
|
+
|
115
108
|
# remove root key from response
|
116
109
|
result.values[0]
|
117
110
|
end
|
@@ -139,31 +132,30 @@ module FitbitAPI
|
|
139
132
|
end
|
140
133
|
|
141
134
|
if (start_time && end_time)
|
142
|
-
get("user
|
135
|
+
get("user/#{user_id}/activities/#{resource}/date/#{format_date(date)}/1d/#{detail_level}/time/#{format_time(start_time)}/#{format_time(end_time)}.json")
|
143
136
|
else
|
144
|
-
get("user
|
137
|
+
get("user/#{user_id}/activities/#{resource}/date/#{format_date(date)}/1d/#{detail_level}.json")
|
145
138
|
end
|
146
139
|
end
|
147
140
|
|
148
|
-
# POST Activities
|
149
|
-
# ===============
|
150
|
-
|
151
141
|
# Creates log entry for an activity or user's private custom activity using units
|
152
142
|
# in the unit system which corresponds to the Accept-Language header provided.
|
153
143
|
#
|
154
|
-
# log_activity(
|
144
|
+
# log_activity(activity_id: 90013, manual_calories: 300, duration_millis: 6000000)
|
155
145
|
#
|
156
|
-
# @param
|
157
|
-
#
|
158
|
-
# @
|
159
|
-
# @
|
160
|
-
# @
|
161
|
-
# @
|
162
|
-
# @
|
163
|
-
# @
|
164
|
-
|
165
|
-
|
166
|
-
|
146
|
+
# @param body [Hash] The POST request body
|
147
|
+
#
|
148
|
+
# @option body :activity_id [Integer, String] The activity ID
|
149
|
+
# @option body :activity_name [String] Custom activity name. Either activity ID or activity_name must be provided
|
150
|
+
# @option body :manual_calories [Integer] Calories burned, specified manually. Required with activity_name, otherwise optional
|
151
|
+
# @option body :start_time [String] Activity start time; formatted in HH:mm:ss
|
152
|
+
# @option body :duration_millis [Integer] Duration in milliseconds
|
153
|
+
# @option body :date [String] Log entry date; formatted in yyyy-MM-dd
|
154
|
+
# @option body :distance [Integer] Distance; required for logging directory activity
|
155
|
+
# @option body :distance_unit [String] Distance measurement unit
|
156
|
+
|
157
|
+
def log_activity(body)
|
158
|
+
post("user/#{user_id}/activities.json", body)
|
167
159
|
end
|
168
160
|
|
169
161
|
# Adds the activity with the given ID to user's list of favorite activities.
|
@@ -174,9 +166,6 @@ module FitbitAPI
|
|
174
166
|
post("user/#{user_id}/activities/favorite/#{activity_id}.json")
|
175
167
|
end
|
176
168
|
|
177
|
-
# DELETE Activities
|
178
|
-
# =================
|
179
|
-
|
180
169
|
# Deletes a user's activity log entry with the given ID.
|
181
170
|
#
|
182
171
|
# @param activity_log_id [Integer] The ID of the activity log entry
|
data/lib/fitbit_api/alarms.rb
CHANGED
@@ -1,57 +1,50 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
# GET Alarms
|
4
|
-
# ==========
|
5
|
-
|
6
3
|
# Returns a list of the set alarms connected to a user's account.
|
7
4
|
#
|
8
5
|
# @params tracker_id [Integer] The ID of the tracker for which the data is returned
|
9
6
|
|
10
|
-
def alarms(tracker_id
|
11
|
-
get("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json"
|
7
|
+
def alarms(tracker_id)
|
8
|
+
get("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json")
|
12
9
|
end
|
13
10
|
|
14
|
-
# POST Alarms
|
15
|
-
# ===========
|
16
|
-
|
17
11
|
# Adds the alarm settings to a given ID for a given device.
|
18
12
|
#
|
19
|
-
# add_alarm(123,
|
13
|
+
# add_alarm(123, time: "07:15-08:00", recurring: true, week_days: "MONDAY,FRIDAY,SATURDAY")
|
20
14
|
#
|
21
15
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is created
|
16
|
+
# @param body [Hash] The POST request body
|
22
17
|
#
|
23
|
-
# @
|
24
|
-
# @
|
25
|
-
# @
|
26
|
-
# @
|
18
|
+
# @option body :time [String] Time of day that the alarm vibrates with a UTC timezone offset, e.g. 07:15-08:00
|
19
|
+
# @option body :enabled [Boolean] If false, alarm does not vibrate until enabled is set to true
|
20
|
+
# @option body :recurring [Boolean] If false, the alarm is a single event
|
21
|
+
# @option body :week_days [String] Comma separated list of days of the week on which the alarm vibrates (MONDAY,TUESDAY)
|
27
22
|
|
28
|
-
def add_alarm(tracker_id,
|
29
|
-
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json",
|
23
|
+
def add_alarm(tracker_id, body={})
|
24
|
+
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", body)
|
30
25
|
end
|
31
26
|
|
32
27
|
# Updates the alarm entry with a given ID for a given device.
|
33
28
|
#
|
34
|
-
# update_alarm(123, 987,
|
29
|
+
# update_alarm(123, 987, week_days: "TUESDAY,SUNDAY")
|
35
30
|
#
|
36
31
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is created
|
37
32
|
# @param alarm_id [Integer] The ID of the alarm to be updated
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# @
|
41
|
-
# @
|
42
|
-
# @
|
43
|
-
# @
|
44
|
-
# @
|
45
|
-
# @
|
46
|
-
# @
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
# @param body [Hash] The POST request body.
|
34
|
+
#
|
35
|
+
# @option body :time [String] Time of day that the alarm vibrates with a UTC timezone offset, e.g. 07:15-08:00
|
36
|
+
# @option body :enabled [Boolean] If false, alarm does not vibrate until enabled is set to true
|
37
|
+
# @option body :recurring [Boolean] If false, the alarm is a single event
|
38
|
+
# @option body :week_days [String] Comma separated list of days of the week on which the alarm vibrates (MONDAY,TUESDAY)
|
39
|
+
# @option body :snooze_length [Integer] Minutes between alarms
|
40
|
+
# @option body :snooze_count [Integer] Maximum snooze count
|
41
|
+
# @option body :label [String] Label for alarm
|
42
|
+
# @option body :vibe [String] Vibe pattern; only one value for now (DEFAULT)
|
43
|
+
|
44
|
+
def update_alarm(tracker_id, alarm_id, body={})
|
45
|
+
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", body)
|
50
46
|
end
|
51
47
|
|
52
|
-
# DELETE Alarms
|
53
|
-
# =============
|
54
|
-
|
55
48
|
# Deletes the user's device alarm entry with the given ID for a given device.
|
56
49
|
#
|
57
50
|
# delete_alarm(123, 987)
|
@@ -59,8 +52,8 @@ module FitbitAPI
|
|
59
52
|
# @param tracker_id [Integer] The ID of the tracker for which the alarm is to be deleted
|
60
53
|
# @param alarm_id [Integer] The ID of the alarm to be deleted
|
61
54
|
|
62
|
-
def delete_alarm(tracker_id, alarm_id
|
63
|
-
delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json"
|
55
|
+
def delete_alarm(tracker_id, alarm_id)
|
56
|
+
delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
|
64
57
|
end
|
65
58
|
end
|
66
59
|
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
|
5
|
+
def weight_logs(date=Date.today)
|
6
|
+
get("user/#{user_id}/body/log/weight/date/#{format_date(date)}.json")
|
7
7
|
end
|
8
8
|
|
9
|
-
def body_fat_logs(date=Date.today
|
10
|
-
get("user
|
9
|
+
def body_fat_logs(date=Date.today)
|
10
|
+
get("user/#{user_id}/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
@@ -7,7 +7,9 @@ require 'fitbit_api/body'
|
|
7
7
|
require 'fitbit_api/devices'
|
8
8
|
require 'fitbit_api/food'
|
9
9
|
require 'fitbit_api/friends'
|
10
|
+
require 'fitbit_api/meals'
|
10
11
|
require 'fitbit_api/sleep'
|
12
|
+
require 'fitbit_api/subscriptions'
|
11
13
|
require 'fitbit_api/user'
|
12
14
|
require 'fitbit_api/water'
|
13
15
|
|
@@ -46,16 +48,16 @@ module FitbitAPI
|
|
46
48
|
@token
|
47
49
|
end
|
48
50
|
|
49
|
-
def get(path, opts={})
|
50
|
-
request(:get, path, opts)
|
51
|
+
def get(path, params={}, opts={}, &block)
|
52
|
+
request(:get, path, opts.merge(params: params), &block)
|
51
53
|
end
|
52
54
|
|
53
|
-
def post(path, opts={})
|
54
|
-
request(:post, path, opts)
|
55
|
+
def post(path, body={}, opts={}, &block)
|
56
|
+
request(:post, path, opts.merge(body: body), &block)
|
55
57
|
end
|
56
58
|
|
57
|
-
def delete(path, opts={})
|
58
|
-
request(:delete, path, opts)
|
59
|
+
def delete(path, params={}, opts={}, &block)
|
60
|
+
request(:delete, path, opts.merge(params: params), &block)
|
59
61
|
end
|
60
62
|
|
61
63
|
private
|
@@ -114,8 +116,9 @@ module FitbitAPI
|
|
114
116
|
refresh_token! if @token.token.empty?
|
115
117
|
end
|
116
118
|
|
117
|
-
def request(verb, path, opts={})
|
119
|
+
def request(verb, path, opts={}, &block)
|
118
120
|
request_path = "#{@api_version}/#{path}"
|
121
|
+
request_headers = default_request_headers.merge(opts[:headers] || {})
|
119
122
|
request_options = opts.merge(headers: request_headers)
|
120
123
|
|
121
124
|
deep_keys_to_camel_case!(request_options[:params])
|
@@ -123,17 +126,17 @@ module FitbitAPI
|
|
123
126
|
|
124
127
|
refresh_token! if auto_refresh_token && token.expired?
|
125
128
|
|
126
|
-
response = token.public_send(verb, request_path, request_options).response
|
127
|
-
|
129
|
+
response = token.public_send(verb, request_path, request_options, &block).response
|
130
|
+
response_body = MultiJson.load(response.body) unless response.status == 204
|
128
131
|
|
129
|
-
process_keys!(
|
132
|
+
process_keys!(response_body)
|
130
133
|
end
|
131
134
|
|
132
135
|
def auth_headers
|
133
136
|
{ 'Authorization' => ('Basic ' + Base64.encode64(@client_id + ':' + @client_secret)) }
|
134
137
|
end
|
135
138
|
|
136
|
-
def
|
139
|
+
def default_request_headers
|
137
140
|
{
|
138
141
|
'User-Agent' => "fitbit_api gem (v#{FitbitAPI::VERSION})",
|
139
142
|
'Accept-Language' => @unit_system,
|
@@ -141,10 +144,11 @@ module FitbitAPI
|
|
141
144
|
}
|
142
145
|
end
|
143
146
|
|
144
|
-
def process_keys!(object
|
145
|
-
deep_keys_to_snake_case!(object) if
|
146
|
-
deep_symbolize_keys!(object) if
|
147
|
-
|
147
|
+
def process_keys!(object)
|
148
|
+
deep_keys_to_snake_case!(object) if snake_case_keys
|
149
|
+
deep_symbolize_keys!(object) if symbolize_keys
|
150
|
+
|
151
|
+
object
|
148
152
|
end
|
149
153
|
end
|
150
154
|
end
|
data/lib/fitbit_api/devices.rb
CHANGED
data/lib/fitbit_api/food.rb
CHANGED
@@ -2,24 +2,83 @@ 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
|
-
|
10
|
-
|
9
|
+
# Retrieves a list of public foods from the Fitbit foods database and private foods the user created
|
10
|
+
#
|
11
|
+
# @params query [String] The search query
|
12
|
+
|
13
|
+
def search_foods(params)
|
14
|
+
get("foods/search.json", params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def recent_foods
|
18
|
+
get("user/#{user_id}/foods/log/recent.json")
|
19
|
+
end
|
20
|
+
|
21
|
+
def frequent_foods
|
22
|
+
get("user/#{user_id}/foods/log/frequent.json")
|
11
23
|
end
|
12
24
|
|
13
|
-
def
|
14
|
-
get("user/#{user_id}/foods/log/
|
25
|
+
def favorite_foods
|
26
|
+
get("user/#{user_id}/foods/log/favorite.json")
|
15
27
|
end
|
16
28
|
|
17
|
-
|
18
|
-
|
29
|
+
# Creates a new private food for a user
|
30
|
+
#
|
31
|
+
# @params body [Hash] The POST request body
|
32
|
+
|
33
|
+
def create_food(body)
|
34
|
+
post("user/#{user_id}/foods.json", body)
|
19
35
|
end
|
20
36
|
|
21
|
-
|
22
|
-
|
37
|
+
# Deletes a custom food created by the user
|
38
|
+
#
|
39
|
+
# @params food_id [Integer] The ID of the food to be deleted
|
40
|
+
|
41
|
+
def delete_food(food_id)
|
42
|
+
delete("user/#{user_id}/foods/#{food_id}.json")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates a food log entry
|
46
|
+
#
|
47
|
+
# @params body [Hash] The POST request body
|
48
|
+
|
49
|
+
def create_food_log(body)
|
50
|
+
post("user/#{user_id}/foods/log.json", body)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Updates the quantity or calories consumed for a user's food log entry with the given Food Log ID
|
54
|
+
#
|
55
|
+
# @params food_log_id [Integer] The ID of the food log to edit
|
56
|
+
# @params body [Hash] The POST request body
|
57
|
+
|
58
|
+
def update_food_log(food_log_id, body)
|
59
|
+
post("user/#{user_id}/foods/log/#{food_log_id}.json", body)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Deletes a user's food log entry using the given log ID
|
63
|
+
#
|
64
|
+
# @params food_log_id [Integer] The id of the food log entry
|
65
|
+
|
66
|
+
def delete_food_log(food_log_id)
|
67
|
+
delete("user/#{user_id}/foods/log/#{food_log_id}.json")
|
68
|
+
end
|
69
|
+
|
70
|
+
# Adds a food with the given ID to the user's list of favorite foods
|
71
|
+
|
72
|
+
def add_favorite_food(food_id)
|
73
|
+
post("user/#{user_id}/foods/log/favorite/#{food_id}.json")
|
74
|
+
end
|
75
|
+
|
76
|
+
# Deletes a food with the given ID from the user's list of favorite foods
|
77
|
+
#
|
78
|
+
# @params food_id [Integer] The ID of the food to delete from the user's favorites
|
79
|
+
|
80
|
+
def delete_favorite_food(food_id)
|
81
|
+
delete("user/#{user_id}/foods/log/favorite/#{food_id}.json")
|
23
82
|
end
|
24
83
|
|
25
84
|
def food_time_series(resource, opts={})
|
@@ -40,12 +99,25 @@ module FitbitAPI
|
|
40
99
|
end
|
41
100
|
|
42
101
|
if period
|
43
|
-
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
102
|
+
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
44
103
|
else
|
45
|
-
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
104
|
+
result = get("user/#{user_id}/foods/log/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
46
105
|
end
|
106
|
+
|
47
107
|
# remove root key from response
|
48
108
|
result.values[0]
|
49
109
|
end
|
110
|
+
|
111
|
+
# Retrieves the food locales used to search, log or create food
|
112
|
+
|
113
|
+
def food_locales
|
114
|
+
get("foods/locales.json")
|
115
|
+
end
|
116
|
+
|
117
|
+
# Retrieves a list of all valid Fitbit food units
|
118
|
+
|
119
|
+
def food_units
|
120
|
+
get("foods/units.json")
|
121
|
+
end
|
50
122
|
end
|
51
123
|
end
|
data/lib/fitbit_api/friends.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
|
4
|
-
|
3
|
+
# Retrieves a list of the Fitbit user's friends.
|
4
|
+
|
5
|
+
def friends
|
6
|
+
get("user/#{user_id}/friends.json")
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
# Retrieves the user's friends leaderboard.
|
10
|
+
|
11
|
+
def friends_leaderboard
|
12
|
+
get("user/#{user_id}/friends/leaderboard.json")
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/fitbit_api/goals.rb
CHANGED
@@ -1,63 +1,118 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
# GET Goals
|
4
|
-
# =========
|
5
|
-
|
6
3
|
# Retrieves a user's current weight goal.
|
7
4
|
|
8
|
-
def weight_goal
|
9
|
-
get("user
|
5
|
+
def weight_goal
|
6
|
+
get("user/#{user_id}/body/log/weight/goal.json")
|
10
7
|
end
|
11
8
|
|
12
9
|
# Retrieves a user's current body fat percentage goal.
|
13
10
|
|
14
|
-
def body_fat_goal
|
15
|
-
get("user
|
11
|
+
def body_fat_goal
|
12
|
+
get("user/#{user_id}/body/log/fat/goal.json")
|
16
13
|
end
|
17
14
|
|
18
15
|
# Retrieves a user's current daily activity goals.
|
19
16
|
|
20
|
-
def
|
21
|
-
get("user/#{user_id}/activities/goals/daily.json"
|
17
|
+
def daily_activity_goals
|
18
|
+
get("user/#{user_id}/activities/goals/daily.json")
|
22
19
|
end
|
23
20
|
|
24
21
|
# Retrieves a user's current weekly activity goals.
|
25
22
|
|
26
|
-
def
|
27
|
-
get("user/#{user_id}/activities/goals/weekly.json"
|
23
|
+
def weekly_activity_goals
|
24
|
+
get("user/#{user_id}/activities/goals/weekly.json")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Retrieves a user's current sleep goal.
|
28
|
+
|
29
|
+
def sleep_goal
|
30
|
+
get("user/#{user_id}/sleep/goal.json")
|
28
31
|
end
|
29
32
|
|
30
|
-
#
|
31
|
-
|
33
|
+
# Retrieves the user's current daily calorie consumption goal and/or food plan.
|
34
|
+
|
35
|
+
def food_goals
|
36
|
+
get("user/#{user_id}/foods/log/goal.json")
|
37
|
+
end
|
38
|
+
|
39
|
+
# Retrieves a user's daily water consumption goal.
|
40
|
+
|
41
|
+
def water_goal
|
42
|
+
get("user/#{user_id}/foods/log/water/goal.json")
|
43
|
+
end
|
32
44
|
|
33
45
|
# Creates or updates a user's daily activity goals and returns a response using units
|
34
46
|
# in the unit system which corresponds to the Accept-Language header provided.
|
35
47
|
#
|
36
|
-
#
|
48
|
+
# update_daily_activity_goals(calories_out: 2000, active_minutes: 90, floors: 5)
|
49
|
+
#
|
50
|
+
# @param body [Hash] The POST request body
|
37
51
|
#
|
38
|
-
# @
|
39
|
-
# @
|
40
|
-
# @
|
41
|
-
# @
|
42
|
-
# @
|
52
|
+
# @option body :calories_out [Integer] Calories output goal value
|
53
|
+
# @option body :active_minutes [Integer] Active minutes goal value
|
54
|
+
# @option body :floors [Integer] Floor goal value
|
55
|
+
# @option body :distance [Integer, Float] Distance goal value
|
56
|
+
# @option body :steps [Integer] Steps goal value
|
43
57
|
|
44
|
-
def
|
45
|
-
post("user/#{user_id}/activities/goals/daily.json",
|
58
|
+
def update_daily_activity_goals(body={})
|
59
|
+
post("user/#{user_id}/activities/goals/daily.json", body)
|
46
60
|
end
|
47
61
|
|
48
62
|
# Creates or updates a user's weekly activity goals and returns a response using units
|
49
63
|
# in the unit system which corresponds to the Accept-Language header provided.
|
50
64
|
#
|
51
|
-
#
|
65
|
+
# update_weekly_activity_goals(active_minutes: 300, floors: 20)
|
66
|
+
#
|
67
|
+
# @param body [Hash] The POST request body
|
68
|
+
#
|
69
|
+
# @option body :calories_out [Integer] Calories output goal value
|
70
|
+
# @option body :active_minutes [Integer] Active minutes goal value
|
71
|
+
# @option body :floors [Integer] Floor goal value
|
72
|
+
# @option body :distance [Integer, Float] Distance goal value
|
73
|
+
# @option body :steps [Integer] Steps goal value
|
74
|
+
|
75
|
+
def update_weekly_activity_goals(body={})
|
76
|
+
post("user/#{user_id}/activities/goals/weekly.json", body)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates or updates a user's weight goal.
|
80
|
+
#
|
81
|
+
# @param body [Hash] the POST request body
|
82
|
+
def update_weight_goal(body)
|
83
|
+
post("user/#{user_id}/body/log/weight/goal.json", body)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Creates or updates a user's body fat goal.
|
87
|
+
#
|
88
|
+
# @param body [Hash] the POST request body
|
89
|
+
|
90
|
+
def update_body_fat_goal(body)
|
91
|
+
post("user/#{user_id}/body/log/fat/goal.json", body)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Create or update a user's sleep goal.
|
95
|
+
#
|
96
|
+
# @param body [Hash] the POST request body
|
97
|
+
|
98
|
+
def update_sleep_goal(body)
|
99
|
+
post("user/#{user_id}/sleep/goal.json", body)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Creates or updates a user's daily calorie consumption or food plan goals.
|
103
|
+
#
|
104
|
+
# @param body [Hash] the POST request body
|
105
|
+
|
106
|
+
def update_food_goals(body)
|
107
|
+
post("user/#{user_id}/foods/log/goal.json", body)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Creates or updates a user's daily water consumption goal.
|
52
111
|
#
|
53
|
-
# @param
|
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
|
112
|
+
# @param body [Hash] the POST request body
|
58
113
|
|
59
|
-
def
|
60
|
-
post("user/#{user_id}/
|
114
|
+
def update_water_goal(body)
|
115
|
+
post("user/#{user_id}/foods/log/water/goal.json", body)
|
61
116
|
end
|
62
117
|
end
|
63
118
|
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
|
@@ -41,9 +42,9 @@ module FitbitAPI
|
|
41
42
|
end
|
42
43
|
|
43
44
|
if (start_time && end_time)
|
44
|
-
get("user
|
45
|
+
get("user/#{user_id}/activities/heart/date/#{format_date(date)}/1d/#{detail_level}/time/#{format_time(start_time)}/#{format_time(end_time)}.json")
|
45
46
|
else
|
46
|
-
get("user
|
47
|
+
get("user/#{user_id}/activities/heart/date/#{format_date(date)}/1d/#{detail_level}.json")
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
|
4
3
|
PERIODS = %w(1d 7d 30d 1w 1m 3m 6m 1y max).freeze
|
5
4
|
|
6
5
|
def format_date(date)
|
@@ -79,6 +78,5 @@ module FitbitAPI
|
|
79
78
|
string.gsub!(/^\w{1}/) { |word| word.downcase } if opts[:lower]
|
80
79
|
return string
|
81
80
|
end
|
82
|
-
|
83
81
|
end
|
84
82
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module FitbitAPI
|
2
|
+
class Client
|
3
|
+
# Retrieves a list of meals created by the user from their food log
|
4
|
+
|
5
|
+
def meals
|
6
|
+
get("user/#{user_id}/meals.json")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Retrieves a single meal created by the user from their food log given the meal id
|
10
|
+
#
|
11
|
+
# @params meal_id [Integer] The ID of the meal
|
12
|
+
|
13
|
+
def meal(meal_id)
|
14
|
+
get("user/#{user_id}/meals/#{meal_id}.json")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a meal with the given food
|
18
|
+
#
|
19
|
+
# @params body [Hash] The POST request body
|
20
|
+
|
21
|
+
def create_meal(body)
|
22
|
+
post("user/#{user_id}/meals.json", body)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Updates an existing meal with the contents of the request
|
26
|
+
#
|
27
|
+
# @params meal_id [Integer] The ID of the meal
|
28
|
+
# @params body [Hash] The POST request body
|
29
|
+
|
30
|
+
def update_meal(meal_id, body)
|
31
|
+
post("user/#{user_id}/meals/#{meal_id}.json", body)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Deletes an existing meal of the given meal ID
|
35
|
+
#
|
36
|
+
# @params meal_id [Integer] The ID of the meal
|
37
|
+
|
38
|
+
def delete_meal(meal_id)
|
39
|
+
delete("user/#{user_id}/meals/#{meal_id}.json")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/fitbit_api/sleep.rb
CHANGED
@@ -3,8 +3,45 @@ module FitbitAPI
|
|
3
3
|
SLEEP_RESOURCES = %w(startTime timeInBed minutesAsleep awakeningsCount
|
4
4
|
minutesAwake minutesToFallAsleep minutesAfterWakeup efficiency)
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# Returns a list of a user's sleep log entries for a given date. The data returned can include sleep
|
7
|
+
# periods that began on the previous date. For example, if you request a Sleep Log for 2021-12-22,
|
8
|
+
# it may return a log entry that began the previous night on 2021-12-21, but ended on 2021-12-22.
|
9
|
+
#
|
10
|
+
# @params date [Date, String] The date for the sleep log to be returned in the format yyyy-MM-dd
|
11
|
+
|
12
|
+
def sleep_logs(date=Date.today)
|
13
|
+
get("user/#{user_id}/sleep/date/#{format_date(date)}.json")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a list of a user's sleep log entries before or after a given date, and specifying offset,
|
17
|
+
# limit and sort order. The data returned for different dates can include sleep periods that began
|
18
|
+
# on the previous date. For example, a sleep log entry for 2018-10-21 may have ended that day but
|
19
|
+
# started the previous night on 2018-10-20.
|
20
|
+
#
|
21
|
+
# sleep_logs_list(before_date: Date.parse('2021-05-24'), limit: 5)
|
22
|
+
#
|
23
|
+
# @param params [Hash] The request parameters
|
24
|
+
#
|
25
|
+
# @option params :before_date [Date] Specify when filtering entries that occured before the given date
|
26
|
+
# @option params :after_date [Date] Specify when filtering entries that occured after the given date
|
27
|
+
# @option params :sort [String] the Sort order of entries by date (asc or desc)
|
28
|
+
# @option params :offset [Integer] The offset number of entries. Must always be 0
|
29
|
+
# @option params :limit [Integer] The max of the number of entries returned (max: 100)
|
30
|
+
|
31
|
+
def sleep_logs_list(params={})
|
32
|
+
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
|
33
|
+
get("user/#{user_id}/sleep/list.json", default_params.merge(params))
|
34
|
+
end
|
35
|
+
|
36
|
+
# Creates a log entry for a sleep event
|
37
|
+
|
38
|
+
def create_sleep_log(body)
|
39
|
+
post("user/#{user_id}/sleep.json", body)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Deletes a sleep log with the given log ID
|
43
|
+
def delete_sleep_log(sleep_log_id)
|
44
|
+
delete("user/#{user_id}/sleep/#{sleep_log_id}.json")
|
8
45
|
end
|
9
46
|
|
10
47
|
def sleep_time_series(resource, opts={})
|
@@ -25,10 +62,11 @@ module FitbitAPI
|
|
25
62
|
end
|
26
63
|
|
27
64
|
if period
|
28
|
-
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(end_date)}/#{period}.json"
|
65
|
+
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(end_date)}/#{period}.json")
|
29
66
|
else
|
30
|
-
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
|
67
|
+
result = get("user/#{user_id}/sleep/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
31
68
|
end
|
69
|
+
|
32
70
|
# remove root key from response
|
33
71
|
result.values[0]
|
34
72
|
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,23 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
|
4
|
-
|
3
|
+
# Retrieves the user's profile data.
|
4
|
+
|
5
|
+
def profile
|
6
|
+
get("user/#{user_id}/profile.json")
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
# Retrieves a list of the user's badges.
|
10
|
+
|
11
|
+
def badges
|
12
|
+
get("user/#{user_id}/badges.json")
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
# Modifies a user's profile data.
|
16
|
+
#
|
17
|
+
# @params body [Hash] The POST request body
|
18
|
+
|
19
|
+
def update_profile(body)
|
20
|
+
post("user/#{user_id}/profile.json", body)
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
data/lib/fitbit_api/version.rb
CHANGED
data/lib/fitbit_api/water.rb
CHANGED
@@ -1,7 +1,36 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
-
|
4
|
-
|
3
|
+
# Retrieves a summary and list of a user's water log entries for a given day
|
4
|
+
#
|
5
|
+
# @param date [Date] The date for which entries are to be returned
|
6
|
+
|
7
|
+
def water_logs(date=Date.today)
|
8
|
+
get("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Create a user's water log entry
|
12
|
+
#
|
13
|
+
# @param body [Hash] The POST request body for creating the water log entry
|
14
|
+
|
15
|
+
def log_water(body)
|
16
|
+
post("user/#{user_id}/foods/log/water.json", body)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Updates the quantity consumed for a user's water log entry with the given log ID
|
20
|
+
#
|
21
|
+
# @params water_log_id [Integer] The ID of the water log to be updated
|
22
|
+
# @params body [Hash] The POST request body for updating the water log
|
23
|
+
|
24
|
+
def update_water_log(water_log_id, body)
|
25
|
+
post("user/#{user_id}/foods/log/water/#{water_log_id}.json", body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Deleted a user's water log entry using the given log ID
|
29
|
+
#
|
30
|
+
# @param water_log_id [Integer] The id of the water log entry
|
31
|
+
|
32
|
+
def delete_water_log(water_log_id)
|
33
|
+
delete("user/#{user_id}/foods/log/water/#{water_log_id}.json")
|
5
34
|
end
|
6
35
|
end
|
7
36
|
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.12.1
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '11.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '11.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,39 +56,39 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.11'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.11'
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
|
+
- ".github/workflows/test.yml"
|
89
90
|
- ".gitignore"
|
90
91
|
- ".rspec"
|
91
|
-
- ".travis.yml"
|
92
92
|
- CHANGELOG.md
|
93
93
|
- Gemfile
|
94
94
|
- LICENSE.txt
|
@@ -109,7 +109,9 @@ files:
|
|
109
109
|
- lib/fitbit_api/helpers/configuration.rb
|
110
110
|
- lib/fitbit_api/helpers/exceptions.rb
|
111
111
|
- lib/fitbit_api/helpers/utils.rb
|
112
|
+
- lib/fitbit_api/meals.rb
|
112
113
|
- lib/fitbit_api/sleep.rb
|
114
|
+
- lib/fitbit_api/subscriptions.rb
|
113
115
|
- lib/fitbit_api/user.rb
|
114
116
|
- lib/fitbit_api/version.rb
|
115
117
|
- lib/fitbit_api/water.rb
|