fitbit_api 0.11.0 → 0.12.2
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 +23 -0
- data/README.md +1 -1
- data/fitbit_api.gemspec +3 -3
- data/lib/fitbit_api/activities.rb +24 -29
- data/lib/fitbit_api/alarms.rb +15 -22
- data/lib/fitbit_api/body.rb +2 -2
- data/lib/fitbit_api/client.rb +9 -8
- data/lib/fitbit_api/devices.rb +2 -0
- data/lib/fitbit_api/food.rb +73 -2
- data/lib/fitbit_api/friends.rb +4 -0
- data/lib/fitbit_api/goals.rb +78 -23
- data/lib/fitbit_api/heart_rate.rb +2 -2
- data/lib/fitbit_api/helpers/utils.rb +0 -2
- data/lib/fitbit_api/meals.rb +42 -0
- data/lib/fitbit_api/sleep.rb +37 -0
- data/lib/fitbit_api/user.rb +8 -0
- data/lib/fitbit_api/version.rb +1 -1
- data/lib/fitbit_api/water.rb +29 -0
- metadata +16 -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: 78cae3c27a67636b099e84c993d65ca42e2039dd3caba794df413baf947dc7eb
|
4
|
+
data.tar.gz: 8cd276fc40a20b3592c54e7b4e53f86b450ce8b6f57160151080f9bf8586b557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f197a5a6e3e8bd08c3d435b44fde8953716f9a1a589d6ea46ae469bb875b77ee39b1f0a289d1e66cd5f2bd055051e5f7dad73f468c628ab9a5ce4f41be7b0758
|
7
|
+
data.tar.gz: 062e014f64ab3780554c2e8f705bcee89a9c74ce3d2119371230207849fb991d777197722641f55cb9983186aa0a97960218eb7413e766fd9ff41e07557226ab
|
@@ -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,26 @@
|
|
1
|
+
0.12.2
|
2
|
+
------
|
3
|
+
- Fix docs formatting
|
4
|
+
|
5
|
+
0.12.1
|
6
|
+
------
|
7
|
+
- Some docs improvements
|
8
|
+
|
9
|
+
0.12.0
|
10
|
+
------
|
11
|
+
- Expand endpont support for foods (searching foods, creating custom foods, updating/deleting logs).
|
12
|
+
- Expand endpoint support for water logging (create, update, delete water logs).
|
13
|
+
- Expand endpoint support for sleep (list sleep logs, create/delete sleep logs).
|
14
|
+
- Expand endpoint support for goals (food, sleep, water goals).
|
15
|
+
- Add endpoint support for meals.
|
16
|
+
- Allow `get`, `post`, and `delete` methods to accept blocks.
|
17
|
+
- Switch to Github Actions for CI.
|
18
|
+
- Rename a few methods for better accuracy/clarity:
|
19
|
+
- daily_goals -> daily_activity_goals
|
20
|
+
- weekly_goals -> weekly_activity_goals
|
21
|
+
- create_or_update_daily_goals -> update_daily_activity_goals
|
22
|
+
- create_or_update_weekly_goals -> update_weekly_activity_goals
|
23
|
+
|
1
24
|
0.11.0
|
2
25
|
------
|
3
26
|
- Add support for subscriptions endpoints.
|
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,12 +11,7 @@ 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
|
|
@@ -24,13 +19,15 @@ module FitbitAPI
|
|
24
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
24
|
def frequent_activities
|
31
25
|
get("user/#{user_id}/activities/frequent.json")
|
32
26
|
end
|
33
27
|
|
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
|
+
|
34
31
|
def recent_activities
|
35
32
|
get("user/#{user_id}/activities/recent.json")
|
36
33
|
end
|
@@ -54,11 +51,13 @@ 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
|
-
# @
|
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)
|
62
61
|
|
63
62
|
def activity_logs_list(params={})
|
64
63
|
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
|
@@ -133,28 +132,27 @@ module FitbitAPI
|
|
133
132
|
end
|
134
133
|
|
135
134
|
if (start_time && end_time)
|
136
|
-
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")
|
137
136
|
else
|
138
|
-
get("user
|
137
|
+
get("user/#{user_id}/activities/#{resource}/date/#{format_date(date)}/1d/#{detail_level}.json")
|
139
138
|
end
|
140
139
|
end
|
141
140
|
|
142
|
-
# POST Activities
|
143
|
-
# ===============
|
144
|
-
|
145
141
|
# Creates log entry for an activity or user's private custom activity using units
|
146
142
|
# in the unit system which corresponds to the Accept-Language header provided.
|
147
143
|
#
|
148
144
|
# log_activity(activity_id: 90013, manual_calories: 300, duration_millis: 6000000)
|
149
145
|
#
|
150
|
-
# @param
|
151
|
-
#
|
152
|
-
# @
|
153
|
-
# @
|
154
|
-
# @
|
155
|
-
# @
|
156
|
-
# @
|
157
|
-
# @
|
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
|
158
156
|
|
159
157
|
def log_activity(body)
|
160
158
|
post("user/#{user_id}/activities.json", body)
|
@@ -168,9 +166,6 @@ module FitbitAPI
|
|
168
166
|
post("user/#{user_id}/activities/favorite/#{activity_id}.json")
|
169
167
|
end
|
170
168
|
|
171
|
-
# DELETE Activities
|
172
|
-
# =================
|
173
|
-
|
174
169
|
# Deletes a user's activity log entry with the given ID.
|
175
170
|
#
|
176
171
|
# @param activity_log_id [Integer] The ID of the activity log entry
|
data/lib/fitbit_api/alarms.rb
CHANGED
@@ -1,29 +1,24 @@
|
|
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
|
+
# @param tracker_id [Integer] The ID of the tracker for which the data is returned
|
9
6
|
|
10
7
|
def alarms(tracker_id)
|
11
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
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
23
|
def add_alarm(tracker_id, body={})
|
29
24
|
post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", body)
|
@@ -35,23 +30,21 @@ module FitbitAPI
|
|
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
|
33
|
+
# @param body [Hash] The POST request body.
|
38
34
|
#
|
39
|
-
# @
|
40
|
-
# @
|
41
|
-
# @
|
42
|
-
# @
|
43
|
-
# @
|
44
|
-
# @
|
45
|
-
# @
|
46
|
-
# @
|
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)
|
47
43
|
|
48
44
|
def update_alarm(tracker_id, alarm_id, body={})
|
49
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)
|
data/lib/fitbit_api/body.rb
CHANGED
@@ -3,11 +3,11 @@ module FitbitAPI
|
|
3
3
|
BODY_RESOURCES = %w(bmi fat weight)
|
4
4
|
|
5
5
|
def weight_logs(date=Date.today)
|
6
|
-
get("user
|
6
|
+
get("user/#{user_id}/body/log/weight/date/#{format_date(date)}.json")
|
7
7
|
end
|
8
8
|
|
9
9
|
def body_fat_logs(date=Date.today)
|
10
|
-
get("user
|
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={})
|
data/lib/fitbit_api/client.rb
CHANGED
@@ -7,6 +7,7 @@ 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'
|
11
12
|
require 'fitbit_api/subscriptions'
|
12
13
|
require 'fitbit_api/user'
|
@@ -47,16 +48,16 @@ module FitbitAPI
|
|
47
48
|
@token
|
48
49
|
end
|
49
50
|
|
50
|
-
def get(path, params={}, opts={})
|
51
|
-
request(:get, path, opts.merge(params: params))
|
51
|
+
def get(path, params={}, opts={}, &block)
|
52
|
+
request(:get, path, opts.merge(params: params), &block)
|
52
53
|
end
|
53
54
|
|
54
|
-
def post(path, body={}, opts={})
|
55
|
-
request(:post, path, opts.merge(body: body))
|
55
|
+
def post(path, body={}, opts={}, &block)
|
56
|
+
request(:post, path, opts.merge(body: body), &block)
|
56
57
|
end
|
57
58
|
|
58
|
-
def delete(path, params={}, opts={})
|
59
|
-
request(:delete, path, opts.merge(params: params))
|
59
|
+
def delete(path, params={}, opts={}, &block)
|
60
|
+
request(:delete, path, opts.merge(params: params), &block)
|
60
61
|
end
|
61
62
|
|
62
63
|
private
|
@@ -115,7 +116,7 @@ module FitbitAPI
|
|
115
116
|
refresh_token! if @token.token.empty?
|
116
117
|
end
|
117
118
|
|
118
|
-
def request(verb, path, opts={})
|
119
|
+
def request(verb, path, opts={}, &block)
|
119
120
|
request_path = "#{@api_version}/#{path}"
|
120
121
|
request_headers = default_request_headers.merge(opts[:headers] || {})
|
121
122
|
request_options = opts.merge(headers: request_headers)
|
@@ -125,7 +126,7 @@ module FitbitAPI
|
|
125
126
|
|
126
127
|
refresh_token! if auto_refresh_token && token.expired?
|
127
128
|
|
128
|
-
response = token.public_send(verb, request_path, request_options).response
|
129
|
+
response = token.public_send(verb, request_path, request_options, &block).response
|
129
130
|
response_body = MultiJson.load(response.body) unless response.status == 204
|
130
131
|
|
131
132
|
process_keys!(response_body)
|
data/lib/fitbit_api/devices.rb
CHANGED
data/lib/fitbit_api/food.rb
CHANGED
@@ -6,6 +6,14 @@ module FitbitAPI
|
|
6
6
|
get("user/#{user_id}/foods/log/date/#{format_date(date)}.json")
|
7
7
|
end
|
8
8
|
|
9
|
+
# Retrieves a list of public foods from the Fitbit foods database and private foods the user created
|
10
|
+
#
|
11
|
+
# @param query [String] The search query
|
12
|
+
|
13
|
+
def search_foods(params)
|
14
|
+
get("foods/search.json", params)
|
15
|
+
end
|
16
|
+
|
9
17
|
def recent_foods
|
10
18
|
get("user/#{user_id}/foods/log/recent.json")
|
11
19
|
end
|
@@ -18,8 +26,59 @@ module FitbitAPI
|
|
18
26
|
get("user/#{user_id}/foods/log/favorite.json")
|
19
27
|
end
|
20
28
|
|
21
|
-
|
22
|
-
|
29
|
+
# Creates a new private food for a user
|
30
|
+
#
|
31
|
+
# @param body [Hash] The POST request body
|
32
|
+
|
33
|
+
def create_food(body)
|
34
|
+
post("user/#{user_id}/foods.json", body)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Deletes a custom food created by the user
|
38
|
+
#
|
39
|
+
# @param 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
|
+
# @param 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
|
+
# @param food_log_id [Integer] The ID of the food log to edit
|
56
|
+
# @param 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
|
+
# @param 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
|
+
# @param 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={})
|
@@ -48,5 +107,17 @@ module FitbitAPI
|
|
48
107
|
# remove root key from response
|
49
108
|
result.values[0]
|
50
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
|
51
122
|
end
|
52
123
|
end
|
data/lib/fitbit_api/friends.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
+
# Retrieves a list of the Fitbit user's friends.
|
4
|
+
|
3
5
|
def friends
|
4
6
|
get("user/#{user_id}/friends.json")
|
5
7
|
end
|
6
8
|
|
9
|
+
# Retrieves the user's friends leaderboard.
|
10
|
+
|
7
11
|
def friends_leaderboard
|
8
12
|
get("user/#{user_id}/friends/leaderboard.json")
|
9
13
|
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
5
|
def weight_goal
|
9
|
-
get("user
|
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
11
|
def body_fat_goal
|
15
|
-
get("user
|
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
|
17
|
+
def daily_activity_goals
|
21
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
|
23
|
+
def weekly_activity_goals
|
27
24
|
get("user/#{user_id}/activities/goals/weekly.json")
|
28
25
|
end
|
29
26
|
|
30
|
-
#
|
31
|
-
|
27
|
+
# Retrieves a user's current sleep goal.
|
28
|
+
|
29
|
+
def sleep_goal
|
30
|
+
get("user/#{user_id}/sleep/goal.json")
|
31
|
+
end
|
32
|
+
|
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
|
58
|
+
def update_daily_activity_goals(body={})
|
45
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)
|
52
66
|
#
|
53
|
-
# @param
|
54
|
-
#
|
55
|
-
# @
|
56
|
-
# @
|
57
|
-
# @
|
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
|
58
74
|
|
59
|
-
def
|
75
|
+
def update_weekly_activity_goals(body={})
|
60
76
|
post("user/#{user_id}/activities/goals/weekly.json", body)
|
61
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.
|
111
|
+
#
|
112
|
+
# @param body [Hash] the POST request body
|
113
|
+
|
114
|
+
def update_water_goal(body)
|
115
|
+
post("user/#{user_id}/foods/log/water/goal.json", body)
|
116
|
+
end
|
62
117
|
end
|
63
118
|
end
|
@@ -42,9 +42,9 @@ module FitbitAPI
|
|
42
42
|
end
|
43
43
|
|
44
44
|
if (start_time && end_time)
|
45
|
-
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")
|
46
46
|
else
|
47
|
-
get("user
|
47
|
+
get("user/#{user_id}/activities/heart/date/#{format_date(date)}/1d/#{detail_level}.json")
|
48
48
|
end
|
49
49
|
end
|
50
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
|
+
# @param 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
|
+
# @param 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
|
+
# @param meal_id [Integer] The ID of the meal
|
28
|
+
# @param 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
|
+
# @param 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,10 +3,47 @@ module FitbitAPI
|
|
3
3
|
SLEEP_RESOURCES = %w(startTime timeInBed minutesAsleep awakeningsCount
|
4
4
|
minutesAwake minutesToFallAsleep minutesAfterWakeup efficiency)
|
5
5
|
|
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
|
+
# @param date [Date, String] The date for the sleep log to be returned in the format yyyy-MM-dd
|
11
|
+
|
6
12
|
def sleep_logs(date=Date.today)
|
7
13
|
get("user/#{user_id}/sleep/date/#{format_date(date)}.json")
|
8
14
|
end
|
9
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")
|
45
|
+
end
|
46
|
+
|
10
47
|
def sleep_time_series(resource, opts={})
|
11
48
|
start_date = opts[:start_date]
|
12
49
|
end_date = opts[:end_date] || Date.today
|
data/lib/fitbit_api/user.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
module FitbitAPI
|
2
2
|
class Client
|
3
|
+
# Retrieves the user's profile data.
|
4
|
+
|
3
5
|
def profile
|
4
6
|
get("user/#{user_id}/profile.json")
|
5
7
|
end
|
6
8
|
|
9
|
+
# Retrieves a list of the user's badges.
|
10
|
+
|
7
11
|
def badges
|
8
12
|
get("user/#{user_id}/badges.json")
|
9
13
|
end
|
10
14
|
|
15
|
+
# Modifies a user's profile data.
|
16
|
+
#
|
17
|
+
# @param body [Hash] The POST request body
|
18
|
+
|
11
19
|
def update_profile(body)
|
12
20
|
post("user/#{user_id}/profile.json", body)
|
13
21
|
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
|
+
# 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
|
+
|
3
7
|
def water_logs(date=Date.today)
|
4
8
|
get("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json")
|
5
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
|
+
# @param water_log_id [Integer] The ID of the water log to be updated
|
22
|
+
# @param 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")
|
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.2
|
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,6 +109,7 @@ 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
|
113
114
|
- lib/fitbit_api/subscriptions.rb
|
114
115
|
- lib/fitbit_api/user.rb
|