fitgem_oauth2 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d549d93c4f0c6e8c6c217f6d18ad69b11f5b90ed3ee42e39fe19ed25ca12a27a
4
- data.tar.gz: 0d5d8ecf9c0bb6563cd1ecba8d65f1458076113f2ba79d2e3d98b54fc5b0ed3c
3
+ metadata.gz: a4195903df9731ae5176aa7577c7320322e4adbaa9f7ac68234a36716a536c85
4
+ data.tar.gz: 28b46788c80bd68e8a16c14caadbbe2d9a961640c67fb3a1011c6fc7977db51b
5
5
  SHA512:
6
- metadata.gz: 13211f94cbf789323aa48718019c6831022dd099e8926c20f3cd5c1fcb1382b61e111d3403253399bbce0d8a75b2f69ce8860c2002f810f9e95095fac44186b8
7
- data.tar.gz: 26ef31364d04f7fc7c8c218ffd669952712271204d415492d5d72650ada09a5cf3ba2542eb011c71f6cbec06a66a7d1603813f374da1612e9b655796f90ef1b5
6
+ metadata.gz: e44efb1b76d77d3bdf42d44709ec7c3683e95060e3387cb896ac9ca9317920880bd530421418cde9995cbd6a08e756828c07bc244f2a5c5dc3cc33b10ff91c8e
7
+ data.tar.gz: c012c4d7f421ddfd44ac782de4294bc5ea94d96f154ae7b1f1dc1dedae5db07ad2821f9576a2bea6af7667f995d9e507db94c47808393e0cef643997399128dc
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- $:.unshift File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
4
  require 'fitgem_oauth2/version'
5
5
 
6
6
  Gem::Specification.new do |s|
@@ -10,13 +10,13 @@ Gem::Specification.new do |s|
10
10
  s.description = 'This gem allows requesting data from Fitbit API using OAuth2'
11
11
  s.authors = ['Ankit Gupta']
12
12
  s.email = 'ankit.gupta2801@gmail.com'
13
- s.files = %w(fitgem_oauth2.gemspec) + `git ls-files -z`.split("\x0").select { |f| f.start_with?('lib/') }
13
+ s.files = %w[fitgem_oauth2.gemspec] + `git ls-files -z`.split("\x0").select {|f| f.start_with?('lib/') }
14
14
  s.homepage = 'http://rubygems.org/gems/fitgem_oauth2'
15
15
  s.license = 'MIT'
16
16
 
17
17
  s.add_runtime_dependency 'faraday', '~> 1.0.1'
18
18
 
19
+ s.add_development_dependency 'factory_bot', '~> 4.5'
19
20
  s.add_development_dependency 'rake', '~> 13.0.1'
20
21
  s.add_development_dependency 'rspec', '~> 3.4'
21
- s.add_development_dependency 'factory_girl', '~> 4.5'
22
22
  end
data/lib/fitgem_oauth2.rb CHANGED
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fitgem_oauth2/client.rb'
2
4
 
3
5
  # Top level module for the classes for this gem
4
6
  module FitgemOauth2
5
-
6
7
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
-
4
5
  ACTIVITY_RESOURCES = %w[
5
6
  calories caloriesBMR steps distance floors elevation minutesSedentary
6
7
  minutesLightlyActive minutesFairlyActive minutesVeryActive
@@ -29,14 +30,11 @@ module FitgemOauth2
29
30
  # @param period the period starting from start_date for which the series needs to be retrieved. If specifying period,
30
31
  # do not use end_date
31
32
  def activity_time_series(resource: nil, start_date: nil, end_date: nil, period: nil)
32
-
33
33
  unless resource && ACTIVITY_RESOURCES.include?(resource)
34
34
  raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Valid resources are #{ACTIVITY_RESOURCES}."
35
35
  end
36
36
 
37
- unless start_date
38
- raise FitgemOauth2::InvalidArgumentError, 'Start date must be specified.'
39
- end
37
+ raise FitgemOauth2::InvalidArgumentError, 'Start date must be specified.' unless start_date
40
38
 
41
39
  if period && end_date
42
40
  raise FitgemOauth2::InvalidArgumentError, 'Both period and end_date are specified. Please specify only one.'
@@ -78,22 +76,22 @@ module FitgemOauth2
78
76
 
79
77
  end_date ||= '1d'
80
78
 
81
- unless detail_level && %w(1min 15min).include?(detail_level)
79
+ unless detail_level && %w[1min 15min].include?(detail_level)
82
80
  raise FitgemOauth2::InvalidArgumentError,
83
81
  'Must specify the data resolution to fetch intraday time series data for.'\
84
82
  ' One of (\"1d\" or \"15min\") is required.'
85
83
  end
86
84
 
87
85
  resource_path = [
88
- 'user', @user_id,
89
- 'activities', resource,
90
- 'date', format_date(start_date),
91
- end_date, detail_level
86
+ 'user', @user_id,
87
+ 'activities', resource,
88
+ 'date', format_date(start_date),
89
+ end_date, detail_level
92
90
  ].join('/')
93
91
 
94
92
  if start_time || end_time
95
93
  resource_path =
96
- [resource_path, 'time', format_time(start_time), format_time(end_time)].join('/')
94
+ [resource_path, 'time', format_time(start_time), format_time(end_time)].join('/')
97
95
  end
98
96
  get_call("#{resource_path}.json")
99
97
  end
@@ -118,12 +116,12 @@ module FitgemOauth2
118
116
  # retrieves activity list for the user
119
117
  def activity_list(date, sort, limit)
120
118
  date_param = format_date(date)
121
- if sort == "asc"
119
+ if sort == 'asc'
122
120
  date_param = "afterDate=#{date_param}"
123
- elsif sort == "desc"
121
+ elsif sort == 'desc'
124
122
  date_param = "beforeDate=#{date_param}"
125
123
  else
126
- raise FitgemOauth2::InvalidArgumentError, "sort can either be asc or desc"
124
+ raise FitgemOauth2::InvalidArgumentError, 'sort can either be asc or desc'
127
125
  end
128
126
  get_call("user/#{user_id}/activities/list.json?offset=0&limit=#{limit}&sort=#{sort}&#{date_param}")
129
127
  end
@@ -133,7 +131,6 @@ module FitgemOauth2
133
131
  get_call("user/#{user_id}/activities/#{id}.tcx")
134
132
  end
135
133
 
136
-
137
134
  # ======================================
138
135
  # Activity Types
139
136
  # ======================================
@@ -185,9 +182,10 @@ module FitgemOauth2
185
182
  # retrieve activity goals for a period
186
183
  # @period the period for which the goals need to be retrieved. either 'weekly' or 'daily'
187
184
  def goals(period)
188
- unless period && %w(daily weekly).include?(period)
185
+ unless period && %w[daily weekly].include?(period)
189
186
  raise FitgemOauth2::InvalidArgumentError, "Goal period should either be 'daily' or 'weekly'"
190
187
  end
188
+
191
189
  get_call("user/#{user_id}/activities/goals/#{period}.json")
192
190
  end
193
191
 
@@ -195,9 +193,10 @@ module FitgemOauth2
195
193
  # @param period period for the goal ('weekly' or 'daily')
196
194
  # @param params the POST params for the request. Refer to Fitbit documentation for accepted format
197
195
  def update_activity_goals(period, params)
198
- unless period && %w(daily weekly).include?(period)
196
+ unless period && %w[daily weekly].include?(period)
199
197
  raise FitgemOauth2::InvalidArgumentError, "Goal period should either be 'daily' or 'weekly'"
200
198
  end
199
+
201
200
  post_call("user/#{user_id}/activities/goals/#{period}.json", params)
202
201
  end
203
202
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
- FAT_PERIODS = %w(1d 7d 1w 1m)
4
- WEIGHT_PERIODS = %w(1d 7d 30d 1w 1m)
5
- BODY_GOALS = %w(fat weight)
6
- BODY_TIME_SERIES_PERIODS = %w(1d 7d 30d 1w 1m 3m 6m 1y max)
5
+ FAT_PERIODS = %w[1d 7d 1w 1m].freeze
6
+ WEIGHT_PERIODS = %w[1d 7d 30d 1w 1m].freeze
7
+ BODY_GOALS = %w[fat weight].freeze
8
+ BODY_TIME_SERIES_PERIODS = %w[1d 7d 30d 1w 1m 3m 6m 1y max].freeze
7
9
 
8
10
  # ======================================
9
11
  # Boday Fat
@@ -15,13 +17,10 @@ module FitgemOauth2
15
17
  # @param end_date (optional)end date for the logs
16
18
  # @param period (optional) period for the logs
17
19
  def body_fat_logs(start_date: nil, end_date: nil, period: nil)
18
- unless start_date
19
- raise FitgemOauth2::InvalidArgumentError, 'must specify start_date'
20
- end
20
+ raise FitgemOauth2::InvalidArgumentError, 'must specify start_date' unless start_date
21
+
21
22
  url = ['user', user_id, 'body/log/fat/date', format_date(start_date)].join('/')
22
- if end_date
23
- url = [url, format_date(end_date)].join('/')
24
- end
23
+ url = [url, format_date(end_date)].join('/') if end_date
25
24
 
26
25
  if period
27
26
  if FAT_PERIODS.include?(period)
@@ -31,7 +30,7 @@ module FitgemOauth2
31
30
  end
32
31
  end
33
32
 
34
- url = url + '.json'
33
+ url += '.json'
35
34
 
36
35
  get_call(url)
37
36
  end
@@ -48,7 +47,6 @@ module FitgemOauth2
48
47
  delete_call("user/#{user_id}/body/log/fat/#{id}.json")
49
48
  end
50
49
 
51
-
52
50
  # ==================================
53
51
  # Body Time Series
54
52
  # ==================================
@@ -78,16 +76,13 @@ module FitgemOauth2
78
76
  end
79
77
  end
80
78
 
81
- if end_date
82
- second = format_date(end_date)
83
- end
79
+ second = format_date(end_date) if end_date
84
80
 
85
81
  url = [url, second].join('/')
86
82
 
87
83
  get_call(url + '.json')
88
84
  end
89
85
 
90
-
91
86
  # ======================================
92
87
  # Body Goals
93
88
  # ======================================
@@ -123,9 +118,7 @@ module FitgemOauth2
123
118
  # @param end_date (optional)end_date for the logs
124
119
  # @param period (optional)period for the logs
125
120
  def weight_logs(start_date: nil, end_date: nil, period: nil)
126
- unless start_date
127
- raise FitgemOauth2::InvalidArgumentError, 'start_date not specified.'
128
- end
121
+ raise FitgemOauth2::InvalidArgumentError, 'start_date not specified.' unless start_date
129
122
 
130
123
  if period && end_date
131
124
  raise FitgemOauth2::InvalidArgumentError, 'both end_date and period specified. please provide only one.'
@@ -158,6 +151,5 @@ module FitgemOauth2
158
151
  def delete_logged_weight(id)
159
152
  delete_call("user/#{user_id}/body/log/weight/#{id}.json")
160
153
  end
161
-
162
154
  end
163
155
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fitgem_oauth2/activity.rb'
2
4
  require 'fitgem_oauth2/body_measurements.rb'
3
5
  require 'fitgem_oauth2/devices.rb'
@@ -16,7 +18,6 @@ require 'faraday'
16
18
 
17
19
  module FitgemOauth2
18
20
  class Client
19
-
20
21
  DEFAULT_USER_ID = '-'
21
22
  API_VERSION = '1'
22
23
 
@@ -27,10 +28,8 @@ module FitgemOauth2
27
28
  attr_reader :unit_system
28
29
 
29
30
  def initialize(opts)
30
- missing = [:client_id, :client_secret, :token] - opts.keys
31
- if missing.size > 0
32
- raise FitgemOauth2::InvalidArgumentError, "Missing required options: #{missing.join(',')}"
33
- end
31
+ missing = %i[client_id client_secret token] - opts.keys
32
+ raise FitgemOauth2::InvalidArgumentError, "Missing required options: #{missing.join(',')}" unless missing.empty?
34
33
 
35
34
  @client_id = opts[:client_id]
36
35
  @client_secret = opts[:client_secret]
@@ -53,7 +52,7 @@ module FitgemOauth2
53
52
 
54
53
  def get_call(url)
55
54
  url = "#{API_VERSION}/#{url}"
56
- response = connection.get(url) { |request| set_headers(request) }
55
+ response = connection.get(url) {|request| set_headers(request) }
57
56
  parse_response(response)
58
57
  end
59
58
 
@@ -62,61 +61,62 @@ module FitgemOauth2
62
61
  # date (Nov 5, 2017)
63
62
  def get_call_1_2(url)
64
63
  url = "1.2/#{url}"
65
- response = connection.get(url) {|request| set_headers(request)}
64
+ response = connection.get(url) {|request| set_headers(request) }
66
65
  parse_response(response)
67
66
  end
68
67
 
69
- def post_call(url, params = {})
68
+ def post_call(url, params={})
70
69
  url = "#{API_VERSION}/#{url}"
71
- response = connection.post(url, params) { |request| set_headers(request) }
70
+ response = connection.post(url, params) {|request| set_headers(request) }
72
71
  parse_response(response)
73
72
  end
74
73
 
75
- def post_call_1_2(url, params = {})
74
+ def post_call_1_2(url, params={})
76
75
  url = "1.2/#{url}"
77
- response = connection.post(url, params) { |request| set_headers(request) }
76
+ response = connection.post(url, params) {|request| set_headers(request) }
78
77
  parse_response(response)
79
78
  end
80
79
 
81
80
  def delete_call(url)
82
81
  url = "#{API_VERSION}/#{url}"
83
- response = connection.delete(url) { |request| set_headers(request) }
82
+ response = connection.delete(url) {|request| set_headers(request) }
84
83
  parse_response(response)
85
84
  end
86
85
 
87
86
  private
87
+
88
88
  attr_reader :connection
89
89
 
90
90
  def set_headers(request)
91
91
  request.headers['Authorization'] = "Bearer #{token}"
92
92
  request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
93
- request.headers['Accept-Language'] = unit_system unless unit_system == nil
93
+ request.headers['Accept-Language'] = unit_system unless unit_system.nil?
94
94
  end
95
95
 
96
96
  def parse_response(response)
97
- headers_to_keep = %w(fitbit-rate-limit-limit fitbit-rate-limit-remaining fitbit-rate-limit-reset)
97
+ headers_to_keep = %w[fitbit-rate-limit-limit fitbit-rate-limit-remaining fitbit-rate-limit-reset]
98
98
 
99
99
  error_handler = {
100
- 200 => lambda {
101
- body = JSON.parse(response.body)
102
- body = {body: body} if body.is_a?(Array)
103
- headers = response.headers.to_hash.keep_if { |k,v|
104
- headers_to_keep.include? k
105
- }
106
- body.merge!(headers)
107
- },
108
- 201 => lambda { },
109
- 204 => lambda { },
110
- 400 => lambda { raise FitgemOauth2::BadRequestError },
111
- 401 => lambda { raise FitgemOauth2::UnauthorizedError },
112
- 403 => lambda { raise FitgemOauth2::ForbiddenError },
113
- 404 => lambda { raise FitgemOauth2::NotFoundError },
114
- 429 => lambda { raise FitgemOauth2::ApiLimitError },
115
- 500..599 => lambda { raise FitgemOauth2::ServerError }
100
+ 200 => lambda {
101
+ body = JSON.parse(response.body)
102
+ body = {body: body} if body.is_a?(Array)
103
+ headers = response.headers.to_hash.keep_if do |k, _v|
104
+ headers_to_keep.include? k
105
+ end
106
+ body.merge!(headers)
107
+ },
108
+ 201 => -> {},
109
+ 204 => -> {},
110
+ 400 => -> { raise FitgemOauth2::BadRequestError },
111
+ 401 => -> { raise FitgemOauth2::UnauthorizedError },
112
+ 403 => -> { raise FitgemOauth2::ForbiddenError },
113
+ 404 => -> { raise FitgemOauth2::NotFoundError },
114
+ 429 => -> { raise FitgemOauth2::ApiLimitError },
115
+ 500..599 => -> { raise FitgemOauth2::ServerError }
116
116
  }
117
117
 
118
- fn = error_handler.detect { |k, _| k === response.status }
119
- if fn === nil
118
+ fn = error_handler.find {|k, _| k === response.status }
119
+ if fn.nil?
120
120
  raise StandardError, "Unexpected response status #{response.status}"
121
121
  else
122
122
  fn.last.call
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
-
4
5
  # ==================================
5
6
  # Devices
6
7
  # ==================================
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class InvalidDateArgument < ArgumentError
3
5
  end
4
6
 
5
7
  class InvalidTimeArgument < ArgumentError
6
-
7
8
  end
8
9
 
9
10
  class InvalidArgumentError < ArgumentError
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fitgem_oauth2/food/collection.rb'
2
4
  require 'fitgem_oauth2/food/series.rb'
3
5
  require 'fitgem_oauth2/food/metadata.rb'
4
6
 
5
7
  module FitgemOauth2
6
8
  class Client
7
-
8
9
  FOOD_SERIES_RESOURCES = %w[caloriesIn water].freeze
9
10
  FOOD_SERIES_PERIODS = %w[1d 7d 30d 1w 1m 3m 6m 1y max].freeze
10
11
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  def food_goals
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  def add_favorite_food(food_id)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  def food_series_for_date_range(start_date, end_date)
@@ -23,33 +25,5 @@ module FitgemOauth2
23
25
  validate_food_series_period(period)
24
26
  get_call(water_series_url(user_id, format_date(start_date), period))
25
27
  end
26
-
27
- def food_series(resource: nil, start_date: nil, end_date: nil, period: nil)
28
- warn '[DEPRECATED] use `food_series_for_date_range`, `food_series_for_period`, `water_series_for_date_range`, or `water_series_for_period` instead.'
29
- unless FOOD_SERIES_RESOURCES.include?(resource)
30
- raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Specify a valid resource from #{FOOD_SERIES_RESOURCES}"
31
- end
32
-
33
- if end_date && period
34
- raise FitgemOauth2::InvalidArgumentError, 'Provide only one of end_date and period.'
35
- end
36
-
37
- if !end_date && !period
38
- raise FitgemOauth2::InvalidArgumentError, 'Provide at least one of end_date and period.'
39
- end
40
-
41
- url = ['user', user_id, 'foods/log', resource, 'date', start_date].join('/')
42
-
43
- if period
44
- unless FOOD_SERIES_PERIODS.include?(period)
45
- raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
46
- end
47
- end
48
-
49
- second = period || format_date(end_date)
50
- url = [url, second].join('/')
51
-
52
- get_call(url + '.json')
53
- end
54
28
  end
55
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  # retrieves list of friends for the current user
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
-
4
5
  HR_PERIODS = %w[1d 7d 30d 1w 1m].freeze
5
6
  HR_DETAIL_LEVELS = %w[1sec 1min].freeze
6
7
 
@@ -20,23 +21,6 @@ module FitgemOauth2
20
21
  get_call(url + '.json')
21
22
  end
22
23
 
23
- # retrieve heartrate time series
24
- def heartrate_time_series(start_date: nil, end_date: nil, period: nil)
25
- warn '[DEPRECATION] `heartrate_time_series` is deprecated. Please use `hr_series_for_date_range` or `hr_series_for_period` instead.'
26
-
27
- regular_time_series_guard(
28
- start_date: start_date,
29
- end_date: end_date,
30
- period: period
31
- )
32
-
33
- second = period || format_date(end_date)
34
-
35
- url = ['user', user_id, 'activities/heart/date', format_date(start_date), second].join('/')
36
-
37
- get_call(url + '.json')
38
- end
39
-
40
24
  # retrieve intraday series for heartrate
41
25
  def intraday_heartrate_time_series(start_date: nil, end_date: nil, detail_level: nil, start_time: nil, end_time: nil)
42
26
  intraday_series_guard(
@@ -51,9 +35,7 @@ module FitgemOauth2
51
35
 
52
36
  url = ['user', user_id, 'activities/heart/date', format_date(start_date), end_date, detail_level].join('/')
53
37
 
54
- if start_time && end_time
55
- url = [url, 'time', format_time(start_time), format_time(end_time)].join('/')
56
- end
38
+ url = [url, 'time', format_time(start_time), format_time(end_time)].join('/') if start_time && end_time
57
39
 
58
40
  get_call(url + '.json')
59
41
  end
@@ -61,25 +43,21 @@ module FitgemOauth2
61
43
  private
62
44
 
63
45
  def validate_hr_period(period)
64
- raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Valid periods are #{HR_PERIODS}." unless period && HR_PERIODS.include?(period)
65
- end
66
-
67
- def regular_time_series_guard(start_date:, end_date:, period:)
68
- validate_start_date(start_date)
69
-
70
- raise FitgemOauth2::InvalidArgumentError, 'Both end_date and period specified. Specify only one.' if end_date && period
71
-
72
- raise FitgemOauth2::InvalidArgumentError, 'Neither end_date nor period specified. Specify at least one.' if !end_date && !period
73
-
74
- validate_hr_period(period) if period
46
+ unless period && HR_PERIODS.include?(period)
47
+ raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Valid periods are #{HR_PERIODS}."
48
+ end
75
49
  end
76
50
 
77
51
  def intraday_series_guard(start_date:, end_date:, detail_level:, start_time:, end_time:)
78
- raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.' unless start_date
52
+ raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.' unless start_date
79
53
 
80
- raise FitgemOauth2::InvalidArgumentError, "Please specify the defail level. Detail level should be one of #{HR_DETAIL_LEVELS}." unless detail_level && HR_DETAIL_LEVELS.include?(detail_level)
54
+ unless detail_level && HR_DETAIL_LEVELS.include?(detail_level)
55
+ raise FitgemOauth2::InvalidArgumentError, "Please specify the defail level. Detail level should be one of #{HR_DETAIL_LEVELS}."
56
+ end
81
57
 
82
- raise FitgemOauth2::InvalidArgumentError, 'Either specify both the start_time and end_time or specify neither.' if (start_time && !end_time) || (end_time && !start_time)
58
+ if (start_time && !end_time) || (end_time && !start_time)
59
+ raise FitgemOauth2::InvalidArgumentError, 'Either specify both the start_time and end_time or specify neither.'
60
+ end
83
61
  end
84
62
  end
85
63
  end
@@ -1,7 +1,7 @@
1
- module FitgemOauth2
1
+ # frozen_string_literal: true
2
2
 
3
+ module FitgemOauth2
3
4
  class Client
4
-
5
5
  SLEEP_RESOURCES = %w[
6
6
  startTime timeInBed minutesAsleep awakeningsCount minutesAwake
7
7
  minutesToFallAsleep minutesAfterWakeup efficiency
@@ -26,7 +26,7 @@ module FitgemOauth2
26
26
  elsif sort == 'desc'
27
27
  date_param = "beforeDate=#{date_param}"
28
28
  else
29
- raise FitgemOauth2::InvalidArgumentError, "sort can either be asc or desc"
29
+ raise FitgemOauth2::InvalidArgumentError, 'sort can either be asc or desc'
30
30
  end
31
31
  get_call_1_2("user/#{user_id}/sleep/list.json?#{date_param}&offset=0&sort=#{sort}&limit=#{limit}")
32
32
  end
@@ -48,9 +48,7 @@ module FitgemOauth2
48
48
  # @param end_date ending date for sleep time series
49
49
  # @param period period for sleep time series
50
50
  def sleep_time_series(resource: nil, start_date: nil, end_date: nil, period: nil)
51
- unless start_date
52
- raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.'
53
- end
51
+ raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.' unless start_date
54
52
 
55
53
  unless resource && SLEEP_RESOURCES.include?(resource)
56
54
  raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Valid resources are #{SLEEP_RESOURCES}."
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
-
4
5
  SUBSCRIBABLE_TYPES = %i[sleep body activities foods all].freeze
5
6
 
6
7
  def subscriptions(opts)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  def user_info
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
4
  class Client
3
5
  def format_date(date)
4
-
5
6
  return nil if date.nil?
6
7
 
7
8
  valid_semantic_date = %w[today yesterday].include? date
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FitgemOauth2
2
- VERSION = '2.2.0'.freeze
4
+ VERSION = '3.0.0'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitgem_oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Gupta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -25,47 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: factory_bot
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 13.0.1
33
+ version: '4.5'
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: 13.0.1
40
+ version: '4.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: 13.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.4'
54
+ version: 13.0.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: factory_girl
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.5'
61
+ version: '3.4'
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: '4.5'
68
+ version: '3.4'
69
69
  description: This gem allows requesting data from Fitbit API using OAuth2
70
70
  email: ankit.gupta2801@gmail.com
71
71
  executables: []
@@ -94,7 +94,7 @@ homepage: http://rubygems.org/gems/fitgem_oauth2
94
94
  licenses:
95
95
  - MIT
96
96
  metadata: {}
97
- post_install_message:
97
+ post_install_message:
98
98
  rdoc_options: []
99
99
  require_paths:
100
100
  - lib
@@ -109,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.0.3
113
- signing_key:
112
+ rubygems_version: 3.2.3
113
+ signing_key:
114
114
  specification_version: 4
115
115
  summary: Fitbit API client library
116
116
  test_files: []