fitgem_oauth2 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fitgem_oauth2/client.rb +4 -4
- data/lib/fitgem_oauth2/food.rb +40 -1
- data/lib/fitgem_oauth2/heartrate.rb +63 -23
- data/lib/fitgem_oauth2/utils.rb +12 -1
- data/lib/fitgem_oauth2/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae7eec9fd825f4fc19feafe55ca51d3b6e176fdd
|
4
|
+
data.tar.gz: 0b1d4f6fb319465919049c96c8d4e2f731ad22c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49b06536b0b23e8645666d85c67081a047ca2b125b1398fa1cde532f441a65cdd10c1f5d2c657df14fed795e6ffaccbbb6690a92d81f77039616e960a1000931
|
7
|
+
data.tar.gz: '0691da40e4d1dcf14757ecd6656a5b391d537223bb00f09d8028327b7f79e201711d71f0538619578cc1d467a50041ddb428366c6ab73200ed3abda847baa7c5'
|
data/lib/fitgem_oauth2/client.rb
CHANGED
@@ -107,10 +107,10 @@ module FitgemOauth2
|
|
107
107
|
},
|
108
108
|
201 => lambda { },
|
109
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
|
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
114
|
500..599 => lambda { raise FitgemOauth2::ServerError }
|
115
115
|
}
|
116
116
|
|
data/lib/fitgem_oauth2/food.rb
CHANGED
@@ -9,9 +9,32 @@ module FitgemOauth2
|
|
9
9
|
# Food or Water Series
|
10
10
|
# ==================================
|
11
11
|
|
12
|
+
def food_series_for_date_range(start_date, end_date)
|
13
|
+
validate_start_date(start_date)
|
14
|
+
validate_end_date(end_date)
|
15
|
+
get_call(food_series_url(user_id, format_date(start_date), format_date(end_date)))
|
16
|
+
end
|
12
17
|
|
13
|
-
def
|
18
|
+
def food_series_for_period(start_date, period)
|
19
|
+
validate_start_date(start_date)
|
20
|
+
validate_food_series_period(period)
|
21
|
+
get_call(food_series_url(user_id, format_date(start_date), period))
|
22
|
+
end
|
23
|
+
|
24
|
+
def water_series_for_date_range(start_date, end_date)
|
25
|
+
validate_start_date(start_date)
|
26
|
+
validate_end_date(end_date)
|
27
|
+
get_call(water_series_url(user_id, format_date(start_date), format_date(end_date)))
|
28
|
+
end
|
29
|
+
|
30
|
+
def water_series_for_period(start_date, period)
|
31
|
+
validate_start_date(start_date)
|
32
|
+
validate_food_series_period(period)
|
33
|
+
get_call(water_series_url(user_id, format_date(start_date), period))
|
34
|
+
end
|
14
35
|
|
36
|
+
def food_series(resource: nil, start_date: nil, end_date: nil, period: nil)
|
37
|
+
warn '[DEPRECATED] use `food_series_for_date_range`, `food_series_for_period`, `water_series_for_date_range`, or `water_series_for_period` instead.'
|
15
38
|
unless FOOD_SERIES_RESOURCES.include?(resource)
|
16
39
|
raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Specify a valid resource from #{FOOD_SERIES_RESOURCES}"
|
17
40
|
end
|
@@ -153,5 +176,21 @@ module FitgemOauth2
|
|
153
176
|
def search_foods(params)
|
154
177
|
post_call('foods/search.json', params)
|
155
178
|
end
|
179
|
+
|
180
|
+
private
|
181
|
+
def validate_food_series_period(period)
|
182
|
+
unless FOOD_SERIES_PERIODS.include?(period)
|
183
|
+
raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def food_series_url(user_id, start_date, end_date_or_period)
|
189
|
+
['user', user_id, 'foods/log/caloriesIn', 'date', start_date, end_date_or_period].join('/') + '.json'
|
190
|
+
end
|
191
|
+
|
192
|
+
def water_series_url(user_id, start_date, end_date_or_period)
|
193
|
+
['user', user_id, 'foods/log/water', 'date', start_date, end_date_or_period].join('/') + '.json'
|
194
|
+
end
|
156
195
|
end
|
157
196
|
end
|
@@ -4,12 +4,70 @@ module FitgemOauth2
|
|
4
4
|
HR_PERIODS = %w(1d 7d 30d 1w 1m)
|
5
5
|
HR_DETAIL_LEVELS = %w(1sec 1min)
|
6
6
|
|
7
|
+
def hr_series_for_date_range(start_date, end_date)
|
8
|
+
validate_start_date(start_date)
|
9
|
+
validate_end_date(end_date)
|
10
|
+
|
11
|
+
url = ['user', user_id, 'activities/heart/date', format_date(start_date), format_date(end_date)].join('/')
|
12
|
+
get_call(url + '.json')
|
13
|
+
end
|
14
|
+
|
15
|
+
def hr_series_for_period(start_date, period)
|
16
|
+
validate_start_date(start_date)
|
17
|
+
validate_hr_period(period)
|
18
|
+
|
19
|
+
url = ['user', user_id, 'activities/heart/date', format_date(start_date), period].join('/')
|
20
|
+
get_call(url + '.json')
|
21
|
+
end
|
22
|
+
|
7
23
|
# retrieve heartrate time series
|
8
24
|
def heartrate_time_series(start_date: nil, end_date: nil, period: nil)
|
9
|
-
|
10
|
-
|
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
|
+
# retrieve intraday series for heartrate
|
41
|
+
def intraday_heartrate_time_series(start_date: nil, end_date: nil, detail_level: nil, start_time: nil, end_time: nil)
|
42
|
+
intraday_series_guard(
|
43
|
+
start_date: start_date,
|
44
|
+
end_date: end_date,
|
45
|
+
detail_level: detail_level,
|
46
|
+
start_time: start_time,
|
47
|
+
end_time: end_time
|
48
|
+
)
|
49
|
+
|
50
|
+
end_date = format_date(end_date) || '1d'
|
51
|
+
|
52
|
+
url = ['user', user_id, 'activities/heart/date', format_date(start_date), end_date, detail_level].join('/')
|
53
|
+
|
54
|
+
if start_time && end_time
|
55
|
+
url = [url, 'time', format_time(start_time), format_time(end_time)].join('/')
|
11
56
|
end
|
12
57
|
|
58
|
+
get_call(url + '.json')
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def validate_hr_period(period)
|
63
|
+
unless period && HR_PERIODS.include?(period)
|
64
|
+
raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Valid periods are #{HR_PERIODS}."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def regular_time_series_guard(start_date:, end_date:, period:)
|
69
|
+
validate_start_date(start_date)
|
70
|
+
|
13
71
|
if end_date && period
|
14
72
|
raise FitgemOauth2::InvalidArgumentError, 'Both end_date and period specified. Specify only one.'
|
15
73
|
end
|
@@ -18,19 +76,11 @@ module FitgemOauth2
|
|
18
76
|
raise FitgemOauth2::InvalidArgumentError, 'Neither end_date nor period specified. Specify at least one.'
|
19
77
|
end
|
20
78
|
|
21
|
-
|
22
|
-
raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Valid periods are #{HR_PERIODS}."
|
23
|
-
end
|
24
|
-
|
25
|
-
second = period || format_date(end_date)
|
26
|
-
|
27
|
-
url = ['user', user_id, 'activities/heart/date', format_date(start_date), second].join('/')
|
28
|
-
|
29
|
-
get_call(url + '.json')
|
79
|
+
validate_hr_period(period) if period
|
30
80
|
end
|
31
81
|
|
32
|
-
|
33
|
-
def
|
82
|
+
|
83
|
+
def intraday_series_guard(start_date:, end_date:, detail_level:, start_time:, end_time:)
|
34
84
|
unless start_date
|
35
85
|
raise FitgemOauth2::InvalidArgumentError, 'Start date not provided.'
|
36
86
|
end
|
@@ -39,19 +89,9 @@ module FitgemOauth2
|
|
39
89
|
raise FitgemOauth2::InvalidArgumentError, "Please specify the defail level. Detail level should be one of #{HR_DETAIL_LEVELS}."
|
40
90
|
end
|
41
91
|
|
42
|
-
end_date = format_date(end_date) || '1d'
|
43
|
-
|
44
|
-
url = ['user', user_id, 'activities/heart/date', format_date(start_date), end_date, detail_level].join('/')
|
45
|
-
|
46
92
|
if (start_time && !end_time) || (end_time && !start_time)
|
47
93
|
raise FitgemOauth2::InvalidArgumentError, 'Either specify both the start_time and end_time or specify neither.'
|
48
94
|
end
|
49
|
-
|
50
|
-
if start_time && end_time
|
51
|
-
url = [url, 'time', format_time(start_time), format_time(end_time)].join('/')
|
52
|
-
end
|
53
|
-
|
54
|
-
get_call(url + '.json')
|
55
95
|
end
|
56
96
|
end
|
57
97
|
end
|
data/lib/fitgem_oauth2/utils.rb
CHANGED
@@ -2,7 +2,6 @@ module FitgemOauth2
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
def format_date(date)
|
5
|
-
|
6
5
|
if !date
|
7
6
|
return nil
|
8
7
|
end
|
@@ -30,6 +29,18 @@ module FitgemOauth2
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
32
|
+
def validate_start_date(start_date)
|
33
|
+
unless start_date
|
34
|
+
raise FitgemOauth2::InvalidArgumentError, 'Please specify a valid start date.'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_end_date(end_date)
|
39
|
+
unless end_date
|
40
|
+
raise FitgemOauth2::InvalidArgumentError, 'Please specify a valid end date.'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
33
44
|
private
|
34
45
|
def date_from_semantic(semantic)
|
35
46
|
if semantic === 'yesterday'
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -107,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.2
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Fitbit API client library
|
114
114
|
test_files: []
|
115
|
-
has_rdoc:
|