From 3ff2bb6255684861646d5bb3a249ffeb9510b275 Mon Sep 17 00:00:00 2001 From: Zoran Pesic Date: Tue, 6 Aug 2024 22:13:57 -0700 Subject: [PATCH 1/3] remove unused values from default request params 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. Addresses https://github.com/zokioki/fitbit_api/issues/12 --- lib/fitbit_api/activities.rb | 2 +- lib/fitbit_api/electrocardiogram.rb | 2 +- lib/fitbit_api/sleep.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fitbit_api/activities.rb b/lib/fitbit_api/activities.rb index 64e5cbf..23227a6 100644 --- a/lib/fitbit_api/activities.rb +++ b/lib/fitbit_api/activities.rb @@ -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 diff --git a/lib/fitbit_api/electrocardiogram.rb b/lib/fitbit_api/electrocardiogram.rb index 8faf793..ad506e2 100644 --- a/lib/fitbit_api/electrocardiogram.rb +++ b/lib/fitbit_api/electrocardiogram.rb @@ -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 diff --git a/lib/fitbit_api/sleep.rb b/lib/fitbit_api/sleep.rb index d19cbd3..5984b68 100644 --- a/lib/fitbit_api/sleep.rb +++ b/lib/fitbit_api/sleep.rb @@ -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 From 5fc27c9be9958b8803ca5c62fe89c5c815546518 Mon Sep 17 00:00:00 2001 From: Zoran Pesic Date: Tue, 6 Aug 2024 22:35:37 -0700 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3c4906..2308302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +1.0.1 +----- +- Remove unused values from default params for the following: + - activity_logs_list + - ecg_logs_list + - sleep_logs_list +- Fixes bad request errors for `activity_logs_list` endpoint. + 1.0.0 ----- - BREAKING: Upgrade `oauth2` dependency to v2.0 From 344dd7a07d2ad8c3871f0541f1964950278cb2e6 Mon Sep 17 00:00:00 2001 From: Zoran Pesic Date: Tue, 6 Aug 2024 22:36:14 -0700 Subject: [PATCH 3/3] bump version --- lib/fitbit_api/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fitbit_api/version.rb b/lib/fitbit_api/version.rb index 0a5cfbb..f314b99 100644 --- a/lib/fitbit_api/version.rb +++ b/lib/fitbit_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module FitbitAPI - VERSION = '1.0.0' + VERSION = '1.0.1' end