Skip to content

Commit

Permalink
remove unused values from default request params
Browse files Browse the repository at this point in the history
Recently, the Fitbit API appears to throw bad request errors
if passing empty params to some of its endpoints - in particular
it would error out on the activity logs list endpoint as both the
beforeDate and afterDate params are being sent over, even though
the afterDate param is null by default. Previously, it looks like
Fitbit's API would gracefully handle these nil params but in this
case it explicitly fails as you can't have both a before and after
date set at the same time.

This updates affected methods so that unused values are removed
from the default params object. There should be no difference in
behavior other than fixing the recently broken activity logs
endpoint.
  • Loading branch information
zokioki committed Aug 7, 2024
1 parent 809fdcf commit b4bf56a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/fitbit_api/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def all_activities
# @option params :limit [Integer] The max of the number of entries returned (max: 20)

def activity_logs_list(params = {})
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
default_params = { before_date: Date.today, sort: 'desc', limit: 20, offset: 0 }
get("user/#{user_id}/activities/list.json", default_params.merge(params))
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fitbit_api/electrocardiogram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Client
# @option params :limit [Integer] The max of the number of entries returned (max: 10)

def ecg_logs_list(params = {})
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 10, offset: 0 }
default_params = { before_date: Date.today, sort: 'desc', limit: 10, offset: 0 }
get("user/#{user_id}/ecg/list.json", default_params.merge(params))
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fitbit_api/sleep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def sleep_logs_by_date_range(opts = {})
# @option params :limit [Integer] The max of the number of entries returned (max: 100)

def sleep_logs_list(params = {})
default_params = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
default_params = { before_date: Date.today, sort: 'desc', limit: 20, offset: 0 }
get("user/#{user_id}/sleep/list.json", default_params.merge(params))
end

Expand Down

0 comments on commit b4bf56a

Please sign in to comment.