fitbyte 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +6 -0
- data/lib/fitbyte/activities.rb +32 -1
- data/lib/fitbyte/body.rb +16 -8
- data/lib/fitbyte/goals.rb +12 -0
- data/lib/fitbyte/heart_rate.rb +25 -0
- data/lib/fitbyte/helpers/utils.rb +14 -0
- data/lib/fitbyte/user.rb +4 -0
- data/lib/fitbyte/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6555eefc24b9e91cd915fb06bef4f000a181bb26
|
4
|
+
data.tar.gz: bbe409b11470d88855a748b55bff0ca9d8ef0d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620ec1e85812a5d9a10a2cf4fbbfc001707511d4e88ffede73e81275ad29ba21dcddf366637d6b320c5835919526d4e1e9e03dfd74ce3d0a031ca001be4d6451
|
7
|
+
data.tar.gz: 0477ab58a7ded7b9f1b13828710dadffdd8f68f9a09794837ccd483cde6d414bed421f59d31ea9da932b5275f89a3f6a2da53a89aa6520f7f297e7da652d2fc0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.7.0
|
2
|
+
-----
|
3
|
+
- Add support for Activity and Heart Rate Intraday Time Series endpoints.
|
4
|
+
- Add support for weight and fat logging and deletion endpoints.
|
5
|
+
- Renamed `#weight_goals` and `#body_fat_goals` to `#weight_goal` and `#body_fat_goal`.
|
6
|
+
|
1
7
|
0.6.0
|
2
8
|
-----
|
3
9
|
- A `refresh_token` option can be passed in to retrieve an existing access token.
|
data/README.md
CHANGED
@@ -23,6 +23,12 @@ gem "fitbyte"
|
|
23
23
|
|
24
24
|
To use the Fitbit API, you must register your application at [dev.fitbit.com](https://dev.fitbit.com/apps). After registering, you should have access to **CLIENT ID**, **CLIENT SECRET**, and **REDIRECT URI (Callback URL)** values for use in instantiating a *Fitbyte::Client* object.
|
25
25
|
|
26
|
+
### Rails
|
27
|
+
|
28
|
+
Please reference the [fitbyte-rails repo](https://github.com/zokioki/fitbyte-rails) as an example of how to use this gem within Rails.
|
29
|
+
|
30
|
+
### Standalone
|
31
|
+
|
26
32
|
- Create a client instance:
|
27
33
|
|
28
34
|
```ruby
|
data/lib/fitbyte/activities.rb
CHANGED
@@ -9,6 +9,8 @@ module Fitbyte
|
|
9
9
|
tracker/minutesLightlyActive tracker/minutesFairlyActive
|
10
10
|
tracker/minutesVeryActive tracker/activityCalories)
|
11
11
|
|
12
|
+
ACTIVITY_INTRADAY_RESOURCES = %w(calories steps distance floors elevation)
|
13
|
+
|
12
14
|
# GET Activities
|
13
15
|
# ==============
|
14
16
|
|
@@ -82,7 +84,7 @@ module Fitbyte
|
|
82
84
|
raise Fitbyte::InvalidArgumentError, "Invalid resource: \"#{resource}\". Please provide one of the following: #{ACTIVITY_RESOURCES}."
|
83
85
|
end
|
84
86
|
|
85
|
-
if [
|
87
|
+
if [start_date, period].none?
|
86
88
|
raise Fitbyte::InvalidArgumentError, "A start_date or period is required."
|
87
89
|
end
|
88
90
|
|
@@ -99,6 +101,35 @@ module Fitbyte
|
|
99
101
|
result.values[0]
|
100
102
|
end
|
101
103
|
|
104
|
+
def activity_intraday_time_series(resource, opts={})
|
105
|
+
date = opts[:date] || Date.today
|
106
|
+
detail_level = opts[:detail_level]
|
107
|
+
start_time = opts[:start_time]
|
108
|
+
end_time = opts[:end_time]
|
109
|
+
|
110
|
+
unless ACTIVITY_INTRADAY_RESOURCES.include?(resource)
|
111
|
+
raise Fitbyte::InvalidArgumentError, "Invalid resource: \"#{resource}\". Please provide one of the following: #{ACTIVITY_RESOURCES}."
|
112
|
+
end
|
113
|
+
|
114
|
+
if [date, detail_level].any?(&:nil?)
|
115
|
+
raise Fitbyte::InvalidArgumentError, "A date and detail_level are required."
|
116
|
+
end
|
117
|
+
|
118
|
+
unless %(1min 15min).include? detail_level
|
119
|
+
raise Fitbyte::InvalidArgumentError, "Invalid detail_level: \"#{detail_level}\". Please provide one of the following: \"1min\" or \"15min\"."
|
120
|
+
end
|
121
|
+
|
122
|
+
if (start_time || end_time) && !(start_time && end_time)
|
123
|
+
raise Fitbyte::InvalidArgumentError, "Both start_time and end_time are required if time is being specified."
|
124
|
+
end
|
125
|
+
|
126
|
+
if (start_time && end_time)
|
127
|
+
get("user/-/activities/#{resource}/date/#{format_date(date)}/1d/#{detail_level}/time/#{format_time(start_time)}/#{format_time(end_time)}.json")
|
128
|
+
else
|
129
|
+
get("user/-/activities/#{resource}/date/#{format_date(date)}/1d/#{detail_level}.json")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
102
133
|
# POST Activities
|
103
134
|
# ===============
|
104
135
|
|
data/lib/fitbyte/body.rb
CHANGED
@@ -10,14 +10,6 @@ module Fitbyte
|
|
10
10
|
get("user/-/body/log/fat/date/#{format_date(date)}.json", opts)
|
11
11
|
end
|
12
12
|
|
13
|
-
def weight_goals(opts={})
|
14
|
-
get("user/-/body/log/weight/goal.json", opts)
|
15
|
-
end
|
16
|
-
|
17
|
-
def body_fat_goals(opts={})
|
18
|
-
get("user/-/body/log/fat/goal.json", opts)
|
19
|
-
end
|
20
|
-
|
21
13
|
def body_time_series(resource, opts={})
|
22
14
|
start_date = opts[:start_date]
|
23
15
|
end_date = opts[:end_date] || Date.today
|
@@ -43,5 +35,21 @@ module Fitbyte
|
|
43
35
|
# remove root key from response
|
44
36
|
result.values[0]
|
45
37
|
end
|
38
|
+
|
39
|
+
def log_weight(opts)
|
40
|
+
post("user/#{user_id}/body/log/weight.json", opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_weight_log(weight_log_id, opts={})
|
44
|
+
delete("user/#{user_id}/body/log/weight/#{weight_log_id}.json", opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
def log_body_fat(opts)
|
48
|
+
post("user/#{user_id}/body/log/fat.json", opts)
|
49
|
+
end
|
50
|
+
|
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)
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
data/lib/fitbyte/goals.rb
CHANGED
@@ -3,6 +3,18 @@ module Fitbyte
|
|
3
3
|
# GET Goals
|
4
4
|
# =========
|
5
5
|
|
6
|
+
# Retrieves a user's current weight goal.
|
7
|
+
|
8
|
+
def weight_goal(opts={})
|
9
|
+
get("user/-/body/log/weight/goal.json", opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Retrieves a user's current body fat percentage goal.
|
13
|
+
|
14
|
+
def body_fat_goal(opts={})
|
15
|
+
get("user/-/body/log/fat/goal.json", opts)
|
16
|
+
end
|
17
|
+
|
6
18
|
# Retrieves a user's current daily activity goals.
|
7
19
|
|
8
20
|
def daily_goals(opts={})
|
data/lib/fitbyte/heart_rate.rb
CHANGED
@@ -21,5 +21,30 @@ module Fitbyte
|
|
21
21
|
# remove root key from response
|
22
22
|
result.values[0]
|
23
23
|
end
|
24
|
+
|
25
|
+
def heart_rate_intraday_time_series(opts={})
|
26
|
+
date = opts[:date] || Date.today
|
27
|
+
detail_level = opts[:detail_level]
|
28
|
+
start_time = opts[:start_time]
|
29
|
+
end_time = opts[:end_time]
|
30
|
+
|
31
|
+
if [date, detail_level].any?(&:nil?)
|
32
|
+
raise Fitbyte::InvalidArgumentError, "A date and detail_level are required."
|
33
|
+
end
|
34
|
+
|
35
|
+
unless %(1sec 1min).include? detail_level
|
36
|
+
raise Fitbyte::InvalidArgumentError, "Invalid detail_level: \"#{detail_level}\". Please provide one of the following: \"1sec\" or \"1min\"."
|
37
|
+
end
|
38
|
+
|
39
|
+
if (start_time || end_time) && !(start_time && end_time)
|
40
|
+
raise Fitbyte::InvalidArgumentError, "Both start_time and end_time are required if time is being specified."
|
41
|
+
end
|
42
|
+
|
43
|
+
if (start_time && end_time)
|
44
|
+
get("user/-/activities/heart/date/#{format_date(date)}/1d/#{detail_level}/time/#{format_time(start_time)}/#{format_time(end_time)}.json")
|
45
|
+
else
|
46
|
+
get("user/-/activities/heart/date/#{format_date(date)}/1d/#{detail_level}.json")
|
47
|
+
end
|
48
|
+
end
|
24
49
|
end
|
25
50
|
end
|
@@ -17,6 +17,20 @@ module Fitbyte
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def format_time(time)
|
21
|
+
if [Time, DateTime].include?(time.class)
|
22
|
+
time.strftime("%H:%M")
|
23
|
+
elsif time.is_a? String
|
24
|
+
if time =~ /\d{2}\:\d{2}/
|
25
|
+
time
|
26
|
+
else
|
27
|
+
raise Fitbyte::InvalidArgumentError, "Invalid argument [\"#{time}\"] - string must follow HH:mm format."
|
28
|
+
end
|
29
|
+
else
|
30
|
+
raise Fitbyte::InvalidArgumentError, "Invalid type [#{time.class}] - provide a Time/DateTime or a String(HH:mm format)."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
20
34
|
def format_scope(scope)
|
21
35
|
scope.is_a?(Array) ? scope.join(" ") : scope
|
22
36
|
end
|
data/lib/fitbyte/user.rb
CHANGED
data/lib/fitbyte/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbyte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran Pesic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|