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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a32301ec7ebc23f284d69bf208224560907ca0b1
4
- data.tar.gz: 1f31799f033bd22b5994712bca93131e44e3a747
3
+ metadata.gz: 6555eefc24b9e91cd915fb06bef4f000a181bb26
4
+ data.tar.gz: bbe409b11470d88855a748b55bff0ca9d8ef0d42
5
5
  SHA512:
6
- metadata.gz: 9e3f5ef3548894d0acd1fb0380e8cf91df985885709d35584727c3336364ab20926ce42b4bace452ecedfc47057ed1ed93c99c79cbc20b41889d149f0d6ec7c8
7
- data.tar.gz: cc11b65e4b42bcf77e45294d7b127d1b6ed517234bf1397e9d7d79c737df91b5a049288922e361b6efa82ac07d6738e9b2aabf82ca0d41feda3c69ae59d90ec6
6
+ metadata.gz: 620ec1e85812a5d9a10a2cf4fbbfc001707511d4e88ffede73e81275ad29ba21dcddf366637d6b320c5835919526d4e1e9e03dfd74ce3d0a031ca001be4d6451
7
+ data.tar.gz: 0477ab58a7ded7b9f1b13828710dadffdd8f68f9a09794837ccd483cde6d414bed421f59d31ea9da932b5275f89a3f6a2da53a89aa6520f7f297e7da652d2fc0
@@ -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
@@ -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 [period, start_date].none?
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
 
@@ -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
@@ -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={})
@@ -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
@@ -7,5 +7,9 @@ module Fitbyte
7
7
  def badges(opts={})
8
8
  get("user/#{user_id}/badges.json", opts)
9
9
  end
10
+
11
+ def update_profile(opts)
12
+ post("user/#{user_id}/profile.json", opts)
13
+ end
10
14
  end
11
15
  end
@@ -1,4 +1,4 @@
1
1
  module Fitbyte
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  REPO_URL = "https://github.com/zokioki/fitbyte"
4
4
  end
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.6.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-04-18 00:00:00.000000000 Z
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2