fitbit_api 0.10.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0a38e6d977a2507680f2ab421d438f1ce5450a2e3346b197f7fe854096278fc
4
- data.tar.gz: '090c11c75f82f5bb6b9ac56ce4d2bd0f55d19693cf201c3d3ad9b776151aa4da'
3
+ metadata.gz: '0199cc0ea15375afa47467c885ccf179c73955116fb9edf4a8f21bdfc4087867'
4
+ data.tar.gz: a394ad4302abe48783bc0bec9217a4132e5939cd067fc922d4e571cac7ea527e
5
5
  SHA512:
6
- metadata.gz: adb8632ad6260887b6bd93c5ec1230cad1bc144c9408f1c8fc8c52f2aae463b08d63361cbd1e33bb0f804c813c90abe9c6b45168b02fd649df1cd93cc3961d19
7
- data.tar.gz: 5aa550aee293be92bd8f417ca270ee37151543db933c853d2874ea2ff56181b6aeb1279bca208c6bf5fe865fdd867a1bb19da70be22d1a31dffb7983dc60b6f4
6
+ metadata.gz: 112c2fa3669262d9e86b09a356147ba6665f768b16a7fc096beb1a36de39350c2c79c5258b850fbe0027bab8a78bf5de2c237d79311406f3c537fd0d82a8f83d
7
+ data.tar.gz: fc9c32427092a0f4f3ccafe15c2a53c486bf7d0e67810bb957d384bb1a83bcc899615bbcf63d9ad881fa30ddbdc1bd7b1cc555ac4246c5c9c5f89bb074cfe9d6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  0.10.2
2
9
  ------
3
10
  - Fix docs for examples
@@ -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, opts={})
24
- get("user/#{user_id}/activities/date/#{format_date(date)}.json", opts)
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(opts={})
31
- get("user/#{user_id}/activities/frequent.json", opts)
30
+ def frequent_activities
31
+ get("user/#{user_id}/activities/frequent.json")
32
32
  end
33
33
 
34
- def recent_activities(opts={})
35
- get("user/#{user_id}/activities/recent.json", opts)
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(opts={})
41
- get("user/#{user_id}/activities/favorite.json", opts)
40
+ def favorite_activities
41
+ get("user/#{user_id}/activities/favorite.json")
42
42
  end
43
43
 
44
- # Gets a tree of all valid Fitbit public activities from the activities catalog
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(opts={})
48
- get('activities.json', opts)
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
@@ -60,16 +60,9 @@ module FitbitAPI
60
60
  # @param offset [Integer] The offset number of entries. Must always be 0
61
61
  # @param limit [Integer] The max of the number of entries returned (max: 20)
62
62
 
63
- def activity_logs_list(opts={})
64
- opts[:params] = {}
65
- param_defaults = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
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)
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(opts={})
90
- get("user/#{user_id}/activities.json", opts)
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", opts)
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", opts)
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,7 +145,7 @@ 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(body: { activity_id: 90013, manual_calories: 300, duration_millis: 6000000 })
148
+ # log_activity(activity_id: 90013, manual_calories: 300, duration_millis: 6000000)
155
149
  #
156
150
  # @param activity_id [Integer, String] The activity ID
157
151
  # @param activity_name [String] Custom activity name. Either activity ID or activity_name must be provided
@@ -162,8 +156,8 @@ module FitbitAPI
162
156
  # @param distance [Integer] Distance; required for logging directory activity
163
157
  # @param distance_unit [String] Distance measurement unit
164
158
 
165
- def log_activity(opts)
166
- post("user/#{user_id}/activities.json", opts)
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.
@@ -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, opts={})
11
- get("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", opts)
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,7 +16,7 @@ module FitbitAPI
16
16
 
17
17
  # Adds the alarm settings to a given ID for a given device.
18
18
  #
19
- # add_alarm(123, body: { time: "07:15-08:00", recurring: true, week_days: "MONDAY,FRIDAY,SATURDAY" })
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
  #
@@ -25,13 +25,13 @@ module FitbitAPI
25
25
  # @param recurring [Boolean] If false, the alarm is a single event
26
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, opts={})
29
- post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", opts)
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, body: { week_days: "TUESDAY,SUNDAY" })
34
+ # update_alarm(123, 987, week_days: "TUESDAY,SUNDAY")
35
35
  #
36
36
  # @param tracker_id [Integer] The ID of the tracker for which the alarm is created
37
37
  # @param alarm_id [Integer] The ID of the alarm to be updated
@@ -45,8 +45,8 @@ module FitbitAPI
45
45
  # @param label [String] Label for alarm
46
46
  # @param vibe [String] Vibe pattern; only one value for now (DEFAULT)
47
47
 
48
- def update_alarm(tracker_id, alarm_id, opts={})
49
- post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", opts)
48
+ def update_alarm(tracker_id, alarm_id, body={})
49
+ post("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", body)
50
50
  end
51
51
 
52
52
  # DELETE Alarms
@@ -59,8 +59,8 @@ module FitbitAPI
59
59
  # @param tracker_id [Integer] The ID of the tracker for which the alarm is to be deleted
60
60
  # @param alarm_id [Integer] The ID of the alarm to be deleted
61
61
 
62
- def delete_alarm(tracker_id, alarm_id, opts={})
63
- delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", opts)
62
+ def delete_alarm(tracker_id, alarm_id)
63
+ delete("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
64
64
  end
65
65
  end
66
66
  end
@@ -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, opts={})
6
- get("user/-/body/log/weight/date/#{format_date(date)}.json", opts)
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, opts={})
10
- get("user/-/body/log/fat/date/#{format_date(date)}.json", opts)
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", opts)
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", opts)
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(opts)
40
- post("user/#{user_id}/body/log/weight.json", opts)
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, opts={})
44
- delete("user/#{user_id}/body/log/weight/#{weight_log_id}.json", opts)
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(opts)
48
- post("user/#{user_id}/body/log/fat.json", opts)
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, opts={})
52
- delete("user/#{user_id}/body/log/fat/#{body_fat_log_id}.json", opts)
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
@@ -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
- object = MultiJson.load(response.body) unless response.status == 204
129
+ response_body = MultiJson.load(response.body) unless response.status == 204
128
130
 
129
- process_keys!(object, opts)
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 request_headers
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, opts={})
145
- deep_keys_to_snake_case!(object) if (opts[:snake_case_keys] || snake_case_keys)
146
- deep_symbolize_keys!(object) if (opts[:symbolize_keys] || symbolize_keys)
147
- return object
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
@@ -1,7 +1,7 @@
1
1
  module FitbitAPI
2
2
  class Client
3
- def devices(opts={})
4
- get("user/#{user_id}/devices.json", opts)
3
+ def devices
4
+ get("user/#{user_id}/devices.json")
5
5
  end
6
6
  end
7
7
  end
@@ -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, opts={})
6
- get("user/#{user_id}/foods/log/date/#{format_date(date)}.json", opts)
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(opts={})
10
- get("user/#{user_id}/foods/log/recent.json", opts)
9
+ def recent_foods
10
+ get("user/#{user_id}/foods/log/recent.json")
11
11
  end
12
12
 
13
- def frequent_foods(opts={})
14
- get("user/#{user_id}/foods/log/frequent.json", opts)
13
+ def frequent_foods
14
+ get("user/#{user_id}/foods/log/frequent.json")
15
15
  end
16
16
 
17
- def favorite_foods(opts={})
18
- get("user/#{user_id}/foods/log/favorite.json", opts)
17
+ def favorite_foods
18
+ get("user/#{user_id}/foods/log/favorite.json")
19
19
  end
20
20
 
21
- def food_goals(opts={})
22
- get("user/#{user_id}/foods/log/goal.json", opts)
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", opts)
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", opts)
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
@@ -1,11 +1,11 @@
1
1
  module FitbitAPI
2
2
  class Client
3
- def friends(opts={})
4
- get("user/#{user_id}/friends.json", opts)
3
+ def friends
4
+ get("user/#{user_id}/friends.json")
5
5
  end
6
6
 
7
- def friends_leaderboard(opts={})
8
- get("user/#{user_id}/friends/leaderboard.json", opts)
7
+ def friends_leaderboard
8
+ get("user/#{user_id}/friends/leaderboard.json")
9
9
  end
10
10
  end
11
11
  end
@@ -5,26 +5,26 @@ module FitbitAPI
5
5
 
6
6
  # Retrieves a user's current weight goal.
7
7
 
8
- def weight_goal(opts={})
9
- get("user/-/body/log/weight/goal.json", opts)
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(opts={})
15
- get("user/-/body/log/fat/goal.json", opts)
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(opts={})
21
- get("user/#{user_id}/activities/goals/daily.json", opts)
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(opts={})
27
- get("user/#{user_id}/activities/goals/weekly.json", opts)
26
+ def weekly_goals
27
+ get("user/#{user_id}/activities/goals/weekly.json")
28
28
  end
29
29
 
30
30
  # POST Goals
@@ -33,7 +33,7 @@ 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(body: {calories_out: 2000, active_minutes: 90, floors: 5})
36
+ # create_or_update_daily_goals(calories_out: 2000, active_minutes: 90, floors: 5)
37
37
  #
38
38
  # @param calories_out [Integer] Calories output goal value
39
39
  # @param active_minutes [Integer] Active minutes goal value
@@ -41,14 +41,14 @@ module FitbitAPI
41
41
  # @param distance [Integer, Float] Distance goal value
42
42
  # @param steps [Integer] Steps goal value
43
43
 
44
- def create_or_update_daily_goals(opts={})
45
- post("user/#{user_id}/activities/goals/daily.json", opts)
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(body: { active_minutes: 300, floors: 20 })
51
+ # create_or_update_weekly_goals(active_minutes: 300, floors: 20)
52
52
  #
53
53
  # @param calories_out [Integer] Calories output goal value
54
54
  # @param active_minutes [Integer] Active minutes goal value
@@ -56,8 +56,8 @@ module FitbitAPI
56
56
  # @param distance [Integer, Float] Distance goal value
57
57
  # @param steps [Integer] Steps goal value
58
58
 
59
- def create_or_update_weekly_goals(opts={})
60
- post("user/#{user_id}/activities/goals/weekly.json", opts)
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", opts)
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", opts)
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
@@ -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, opts={})
7
- get("user/#{user_id}/sleep/date/#{format_date(date)}.json", opts)
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", opts)
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", opts)
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
@@ -1,15 +1,15 @@
1
1
  module FitbitAPI
2
2
  class Client
3
- def profile(opts={})
4
- get("user/#{user_id}/profile.json", opts)
3
+ def profile
4
+ get("user/#{user_id}/profile.json")
5
5
  end
6
6
 
7
- def badges(opts={})
8
- get("user/#{user_id}/badges.json", opts)
7
+ def badges
8
+ get("user/#{user_id}/badges.json")
9
9
  end
10
10
 
11
- def update_profile(opts)
12
- post("user/#{user_id}/profile.json", opts)
11
+ def update_profile(body)
12
+ post("user/#{user_id}/profile.json", body)
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module FitbitAPI
2
- VERSION = '0.10.2'
2
+ VERSION = '0.11.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module FitbitAPI
2
2
  class Client
3
- def water_logs(date=Date.today, opts={})
4
- get("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json", opts)
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.10.2
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-05 00:00:00.000000000 Z
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