fitgem 0.8.0 → 0.9.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: 0093dff6f708728ec192e7dd062940d0091d856b
4
- data.tar.gz: da17edef7d5d5b62529eae6f0afad4a7b3ba7fc4
3
+ metadata.gz: 76633b7e4a93d47e6f38b05ea29bb61aa1bc99a7
4
+ data.tar.gz: 8c9e95113e9fae7d0ac8da7794e57e001f3a7949
5
5
  SHA512:
6
- metadata.gz: 88e9581a93d35371073e55e41bc612fb0db45b5f46c4113f9354dbc1e63bf8e8475e0ce0a7f2c7f169d5f18d3312a1b9a7a47f96bc3c97b27e6bbdc3c30c1671
7
- data.tar.gz: 0f650a3fb149884f52ddab2e6c731ff58da874455a7e3b2ae43258bfb73b5b73a84a0d26daf71beb09ba93ee7ed221ee79e04ae8002f109eb5e05c79b40217d3
6
+ metadata.gz: 27d833fae2901dad5e2f44c69183c020c8685ddd1c7989c8d0c4d07e8744e123a045059dc22b8862a4c4ed19a397694abcaa3cfb26b11601cdd0a8ee41dfdcb2
7
+ data.tar.gz: e995db140ef78a18144ae95673fb0dfa6192392f3edb94f91a1e0f65ad14099b925f3e4d44a97c6b0df0c02ec7682b67da18aa032fe8751075f0b9112c121595
data/.gitignore CHANGED
@@ -8,3 +8,5 @@ test*.rb
8
8
  .fitgem.yml
9
9
  .idea
10
10
  .rvmrc
11
+ .ruby-version
12
+ .ruby-gemset
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Fitgem [![Build Status](https://secure.travis-ci.org/whazzmaster/fitgem.png)](http://travis-ci.org/whazzmaster/fitgem)
2
2
 
3
- Provides access to [fitbit.com](http://www.fitbit.com) data through [their REST API](http://dev.fitbit.com). Fitgem can pull data with or without user authentication. Without user authentication, any data that the a fitbit.com user has denoted as 'public' can be gathered. If a user logs in via OAuth then all exposed data can be gathered.
3
+ This gem provides access to [fitbit.com](http://www.fitbit.com) data through [their REST API](http://dev.fitbit.com). Fitgem can pull data with or without a valid OAUth access_token. Without an access_token you can only gather data that a user has denoted as 'public'. However, if an access_token is provided then all exposed data can be gathered for the logged-in account.
4
4
 
5
- The [Fitbit API](https://wiki.fitbit.com/display/API/Fitbit+API) is currently in BETA and is under development to extend its reach. As the API evolves and is enhanced it's a priority to mirror the functionality in the gem, and any **pull requests** are appreciated if you see gaps in API support.
5
+ The [Fitbit API](https://wiki.fitbit.com/display/API/Fitbit+API) is currently in BETA and is under development to extend its reach. As the API evolves and is enhanced it's a priority to mirror the functionality in the gem, and **pull requests** are appreciated if you see gaps in API support.
6
6
 
7
- # Usage
7
+ ## Installation
8
8
 
9
9
  Install fitgem
10
10
 
@@ -18,11 +18,16 @@ or add it to your Gemfile
18
18
  gem 'fitgem'
19
19
  ```
20
20
 
21
+ ## API Reference
22
+
21
23
  Comprehensive method documentation is [available online](http://www.rubydoc.info/github/whazzmaster/fitgem/frames).
22
24
 
23
25
  The best way to connect your users to the Fitbit API is to use
24
- **[omniauth-fitbit](https://github.com/tkgospodinov/omniauth-fitbit)** to integrate Fitbit accounts into your web
25
- application. Once you have a Fitbit API OAuth `access_token` for a user it's simple to create a client object through fitgem to send and receive fitness data.
26
+ [omniauth-fitbit](https://github.com/tkgospodinov/omniauth-fitbit) to integrate Fitbit accounts into your web application. Once you have a Fitbit API OAuth `access_token` for a user it's simple to create a client object through fitgem to send and receive fitness data.
27
+
28
+ ## Subscriptions
29
+
30
+ The Fitbit API allows for you to set up notification subscriptions. When user data changes (through syncing with the fitbit device) your applications can be notified automatically. You can set up a default subscription callback URL via the [Fitbit dev site](https://dev.fitbit.com/ 'Fitbit Developer Site') and then use the Subscriptions API to add or remove subscriptions for individual users.
26
31
 
27
32
  ## Reference Application
28
33
 
@@ -34,13 +39,9 @@ The reference app is written using Rails 3.2 and [Backbone.js](http://backbonejs
34
39
  * Store and use OAuth access tokens
35
40
  * Create and use instances of `Fitgem::Client` using the stored OAuth access token
36
41
 
37
- # Subscriptions
42
+ ## Contributing to Fitgem
38
43
 
39
- The Fitbit API allows for you to set up notification subscription so that when values change (via automatic syncs with the fitbit device) your applications can be notified automatically. You can set up a default subscription callback URL via the [Fitbit dev site](https://dev.fitbit.com/ 'Fitbit Developer Site') and then use the Subscriptions API to add or remove subscriptions for individual users.
40
-
41
- # Help Improve Fitgem!
42
-
43
- The Fitbit REST API is in BETA right now, and so it will quite likely change over time (though I can't be sure whether it will be additive change or change of the non-backwards-compatible variety). I aim to keep as up-to-date as I can but if you absolutely need functionality that isn't included here, **feel free to fork and implement it, then send me a pull request**.
44
+ The Fitbit REST API is in BETA right now, and so it will quite likely change over time. I aim to keep as up-to-date as I can but if you absolutely need functionality that isn't included here, **feel free to fork and implement it, then send me a pull request**.
44
45
 
45
46
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
46
47
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -51,11 +52,10 @@ The Fitbit REST API is in BETA right now, and so it will quite likely change ove
51
52
  * **Please try not to mess with the Rakefile, version, or history**. If you want to have your own version, or is otherwise
52
53
  necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
53
54
 
54
- ## Contributors
55
+ ### Contributors
55
56
 
56
57
  **Many, many thanks** to [everyone that has contributed to improve fitgem](https://github.com/whazzmaster/fitgem/graphs/contributors)!
57
58
 
58
- # Copyright & Disclaimer
59
+ ## Copyright & Disclaimer
59
60
 
60
61
  Copyright © 2011-2013 Zachery Moneypenny. See LICENSE for further details. __I am not employed by [Fitbit](http://fitbit.com)__. I created this library to assist other ruby developers in creating interesting applications on top of fitbit.com's data store and device data stream.
61
-
data/changelog.md CHANGED
@@ -3,6 +3,35 @@
3
3
 
4
4
  # fitgem changelog
5
5
 
6
+ ## v0.9.0
7
+
8
+ #### 2014-02-11 Zachery Moneypenny <fitgem@whazzmaster.com>
9
+
10
+ The v0.9.0 release adds a number of new methods to match new functionality available through the Fitbit REST API. It
11
+ also removes support for concepts (monthly leaderboards) that have been removed from the Fitbit REST API.
12
+
13
+ There's a big change to **leaderboard support** in this update; please read the notes below if you're currently using
14
+ `monthly_leaderboard` or `weekly_leaderboard` -- you should update your code to use the new method before v1.0 is
15
+ released.
16
+
17
+ * Add ability to target SSL Fitbit REST endpoints
18
+ * Add `activity_on_date_range` method
19
+ * Condense existing `weekly_leaderboard` and (no longer available) `monthly_leaderboard` into a simple `leaderboard`
20
+ method. There is now only one leaderboard (weekly) so no need to differentiate in the API. The previous leaderboard
21
+ methods are now deprecated and **will be removed** in v1.0.
22
+ * Add `create_or_update_weekly_goal` method and specs
23
+ * Add `create_or_update_daily_goal` method and specs
24
+ * Add `daily_goals` method and update documentation
25
+ * Add `delete_body_fat_log` method
26
+ * Add `delete_body_weight_log` method
27
+ * Add `create_or_update_body_fat_goal` method
28
+ * Add `create_or_update_body_weight_goal` method
29
+ * Add `log_body_fat` method to push a body fat measurement to Fitbit
30
+ * Add `body_fat_goal` method to fetch the current body fat goal
31
+ * Add `body_fat` method to fetch body fat measurements
32
+ * Add `body_weight` method to fetch body fat measurements
33
+ * For the `body_weight` and `body_fat` methods, determine a URI based on the base URI and provided options
34
+
6
35
  ## v0.8.0
7
36
 
8
37
  #### 2013-08-03 Zachery Moneypenny <fitgem@whazzmaster.com>
@@ -22,24 +22,34 @@ module Fitgem
22
22
  get("/user/#{@user_id}/activities/date/#{format_date(date)}.json")
23
23
  end
24
24
 
25
+ # Get activity information for a date range
26
+ #
27
+ # @param [String] activity to retrieve information for
28
+ # @param [Datetime] start of date range
29
+ # @param [Datetime] end of date range
30
+ # @return [Hash] activity information for the given date range
31
+ def activity_on_date_range(activity, start, finish)
32
+ get("/user/#{@user_id}/activities/#{activity}/date/#{format_date(start)}/#{format_date(finish)}.json")
33
+ end
34
+
25
35
  # Get a list of the frequently logged activities
26
36
  #
27
37
  # @return [Array] list of frequently logged activities
28
- def frequent_activities()
38
+ def frequent_activities
29
39
  get("/user/#{@user_id}/activities/frequent.json")
30
40
  end
31
41
 
32
42
  # Get a list of recently logged activities
33
43
  #
34
44
  # @return [Array] list of of recently-logged activities
35
- def recent_activities()
45
+ def recent_activities
36
46
  get("/user/#{@user_id}/activities/recent.json")
37
47
  end
38
48
 
39
49
  # Get a list of activities marked as favorite by the user
40
50
  #
41
51
  # @return [Array] list of user-defined favorite activities
42
- def favorite_activities()
52
+ def favorite_activities
43
53
  get("/user/#{@user_id}/activities/favorite.json")
44
54
  end
45
55
 
@@ -58,23 +68,40 @@ module Fitgem
58
68
  # Get the activity statistics for the current user
59
69
  #
60
70
  # @return [Hash] Hash containing statistics for the activities that
61
- # the user has logged
71
+ # the user has logged
62
72
  def activity_statistics
63
73
  get("/user/#{@user_id}/activities.json")
64
74
  end
65
75
 
76
+ # ==========================================
77
+ # Goal Retrieval Methods
78
+ # ==========================================
79
+
66
80
  # Get the daily activity goals for the current user
67
81
  #
68
- # @return [Hash] Hash containing the calorie, distance, floors, and
69
- # step goals for the current user
82
+ # @return [Hash] Hash containing the calorie, distance, floors, and
83
+ # step goals for the current user
84
+ #
85
+ # @deprecated Use the daily_goals method; in v1.0.0 this method will
86
+ # be removed
70
87
  def goals
71
88
  get("/user/#{@user_id}/activities/goals/daily.json")
72
89
  end
73
90
 
91
+ # Get the daily activity goals for the current user
92
+ #
93
+ # @return [Hash] Hash containing the calorie, distance, floors, and
94
+ # step goals for the current user
95
+ #
96
+ # @since v0.9.0
97
+ def daily_goals
98
+ goals
99
+ end
100
+
74
101
  # Get the weekly activity goals for the current user
75
102
  #
76
103
  # @return [Hash] Hash containing the distance, floors and step goals
77
- # for the current user
104
+ # for the current user
78
105
  def weekly_goals
79
106
  get("/user/#{@user_id}/activities/goals/weekly.json")
80
107
  end
@@ -88,25 +115,26 @@ module Fitgem
88
115
  # @param [Hash] opts The options used to log the activity for the
89
116
  # current user
90
117
  #
91
- # @option opts [String] :activityId The id of the activity, directory activity or intensity
92
- # level activity. See activity types at {http://wiki.fitbit.com/display/API/API-Log-Activity} for more
118
+ # @option opts [String] :activityId The id of the activity, directory
119
+ # activity or intensity level activity. See activity types at
120
+ # {http://wiki.fitbit.com/display/API/API-Log-Activity} for more
93
121
  # information. This value OR activityName is REQUIRED for all calls.
94
- # @option opts [String] :activityName The name of the activity to log. This value OR activityId
95
- # is REQUIRED for alls.
96
- #
122
+ # @option opts [String] :activityName The name of the activity to log.
123
+ # This value OR activityId is REQUIRED for alls.
97
124
  # @option opts [String, Integer] :durationMillis Activity duration in milliseconds.
98
125
  # Must be a numeric value in Integer or String format. This value is REQUIRED for all calls.
99
126
  # @option opts [String] :startTime Activity start time, in the format "HH:mm" using hours
100
127
  # and seconds. This value is REQUIRED for all calls.
101
- # @option opts [String] :date Activity date, in "yyyy-MM-dd" format. This value is REQUIRED for all calls.
102
- #
103
- # @option opts [String] :distance Distance traveled, a string in the format "X.XX". This value is
128
+ # @option opts [String] :date Activity date, in "yyyy-MM-dd" format. This
129
+ # value is REQUIRED for all calls.
130
+ # @option opts [String] :distance Distance traveled, a string in the format "X.XX". This value is
104
131
  # REQUIRED when logging a directory activity, OPTIONAL otherwise.
105
- # @option opts [String, Integer] :manualCalories The number of calories to log against the activity. This
106
- # value is REQUIRED if using the activityName, OPTIONAL otherwise.
107
- #
108
- # @option opts [String] :distanceUnit One of {Fitgem::ApiDistanceUnit}. The "steps" units are available
109
- # only for "Walking" and "Running" directory activities and their intensity levels
132
+ # @option opts [String, Integer] :manualCalories The number of calories
133
+ # to log against the activity. This value is REQUIRED if using the activityName,
134
+ # OPTIONAL otherwise.
135
+ # @option opts [String] :distanceUnit One of {Fitgem::ApiDistanceUnit}.
136
+ # The "steps" units are available only for "Walking" and "Running"
137
+ # directory activities and their intensity levels
110
138
  #
111
139
  # @return [Hash] A hash with a summary of the logged activity
112
140
  def log_activity(opts)
@@ -119,11 +147,60 @@ module Fitgem
119
147
  # typcially retrieved by browsing or searching the list of all
120
148
  # available activities. Must be a numerical ID in either Integer
121
149
  # or String format.
150
+ #
122
151
  # @return [Hash] Empty hash if successfully marked as a favorite
123
152
  def add_favorite_activity(activity_id)
124
153
  post("/user/#{@user_id}/activities/log/favorite/#{activity_id}.json")
125
154
  end
126
155
 
156
+ # ==========================================
157
+ # Goal Creation/Update Methods
158
+ # ==========================================
159
+
160
+ # Create or update a user's daily goal
161
+ #
162
+ # @param [Hash] :opts
163
+ #
164
+ # @option opts [Symbol] :type The type of goal to create or update; must be one of
165
+ # :steps, :distance, :floors, or :caloriesOut. REQUIRED
166
+ # @option opts [Decimal, Integer, String] :value The goal value; in the format 'X.XX'
167
+ # if a string. REQUIRED
168
+ #
169
+ # @since v0.9.0
170
+ def create_or_update_daily_goal(opts)
171
+ unless opts[:type] && [:steps, :distance, :floors, :caloriesOut].include?(opts[:type])
172
+ raise InvalidArgumentError, 'Must specify type in order to create or update a daily goal. One of (:steps, :distance, :floors, or :caloriesOut) is required.'
173
+ end
174
+
175
+ unless opts[:value]
176
+ raise InvalidArgumentError, 'Must specify value of the daily goal to be created or updated.'
177
+ end
178
+
179
+ post("/user/#{@user_id}/activities/goals/daily.json", opts)
180
+ end
181
+
182
+ # Create or update a user's weekly goal
183
+ #
184
+ # @param [Hash] :opts
185
+ #
186
+ # @option opts [Symbol] :type The type of goal to create or update; must be one of
187
+ # :steps, :distance, or :floors. REQUIRED
188
+ # @option opts [Decimal, Integer, String] :value The goal value; in the format 'X.XX'
189
+ # if a string. REQUIRED
190
+ #
191
+ # @since v0.9.0
192
+ def create_or_update_weekly_goal(opts)
193
+ unless opts[:type] && [:steps, :distance, :floors].include?(opts[:type])
194
+ raise InvalidArgumentError, 'Must specify type in order to create or update a weekly goal. One of (:steps, :distance, or :floors) is required.'
195
+ end
196
+
197
+ unless opts[:value]
198
+ raise InvalidArgumentError, 'Must specify value of the weekly goal to be created or updated.'
199
+ end
200
+
201
+ post("/user/#{@user_id}/activities/goals/weekly.json", opts)
202
+ end
203
+
127
204
  # ==========================================
128
205
  # Activity Removal Methods
129
206
  # ==========================================
@@ -1,38 +1,77 @@
1
1
  module Fitgem
2
2
  class Client
3
3
  # ==========================================
4
- # Body Measurements Update Methods
4
+ # Body Measurements Methods
5
5
  # ==========================================
6
6
 
7
7
  # Get the body measurements logged on a specified date
8
8
  #
9
9
  # @param [DateTime, String] date The date to retrieve body
10
10
  # measurements for. May be a DateTime object or a String
11
- # in "yyyy-MM-dd" format.
11
+ # in 'yyyy-MM-dd' format.
12
12
  # @return [Hash] A hash containing the logged body measurements
13
13
  # along with any goals set for the current user.
14
14
  def body_measurements_on_date(date)
15
15
  get("/user/#{@user_id}/body/date/#{format_date(date)}.json")
16
16
  end
17
17
 
18
- # ==========================================
19
- # Body Measurements Update Methods
20
- # ==========================================
18
+ # Get a list of logged body weight entries for the specified period
19
+ #
20
+ # @params [Hash] opts body weight options
21
+ # @option opts [Date] date The date in the format YYYY-mm-dd.
22
+ # @option opts [Date] base_date The end date when period is provided, in the
23
+ # format yyyy-MM-dd or today; range start date when a date range is provided.
24
+ # @option opts [String] period The date range period. One of 1d, 7d, 30d, 1w, 1m
25
+ # @option opts [Date] end_date Range end date when date range is provided.
26
+ # Note that period should not be longer than 31 day
27
+ #
28
+ # @return [Hash] A hash containing body weight log entries
29
+ #
30
+ # @since v0.9.0
31
+ def body_weight(opts = {})
32
+ get determine_body_uri("/user/#{@user_id}/body/log/weight", opts)
33
+ end
21
34
 
22
- # Log weight to fitbit for the current user
35
+ # Retrieve the body weight goal of the current user
23
36
  #
24
- # @param [Integer, String] weight The weight to log, as either
25
- # an integer or a string in "X.XX'" format
26
- # @param [DateTime, String] date The date the weight should be
27
- # logged, as either a DateTime or a String in "yyyy-MM-dd" format
28
- # @return [Hash]
37
+ # @return [Hash] A hash containing the start date,
38
+ # start weight and current weight.
29
39
  #
30
- # @deprecated {#log_body_measurements} should be used instead of
31
- # log_weight
32
- def log_weight(weight, date, options={})
33
- post("/user/#{@user_id}/body/weight.json", options.merge(:weight => weight, :date => format_date(date)))
40
+ # @since v0.9.0
41
+ def body_weight_goal
42
+ get("/user/#{@user_id}/body/log/weight/goal.json")
34
43
  end
35
44
 
45
+ # Get a list of logged body fat entries for the specified period
46
+ #
47
+ # @params [Hash] opts body fat options
48
+ # @option opts [Date] date The date in the format YYYY-mm-dd.
49
+ # @option opts [Date] base_date The end date when period is provided, in the
50
+ # format yyyy-MM-dd or today; range start date when a date range is provided.
51
+ # @option opts [String] period The date range period. One of 1d, 7d, 30d, 1w, 1m
52
+ # @option opts [Date] end_date Range end date when date range is provided.
53
+ # Note that period should not be longer than 31 day
54
+ #
55
+ # @return [Hash] A hash containing body fat log entries
56
+ #
57
+ # @since v0.9.0
58
+ def body_fat(opts = {})
59
+ get determine_body_uri("/user/#{@user_id}/body/log/fat", opts)
60
+ end
61
+
62
+ # Retrieve the body fat goal of the current user
63
+ #
64
+ # @return [Hash] A hash containing the body fat goal
65
+ #
66
+ # @since v0.9.0
67
+ def body_fat_goal
68
+ get("/user/#{@user_id}/body/log/fat/goal.json")
69
+ end
70
+
71
+ # ==========================================
72
+ # Body Measurements Update Methods
73
+ # ==========================================
74
+
36
75
  # Log body measurements to fitbit for the current user
37
76
  #
38
77
  # At least ONE measurement item is REQUIRED in the call, as well as the
@@ -65,5 +104,115 @@ module Fitgem
65
104
  opts[:date] = format_date(opts[:date]) if opts[:date]
66
105
  post("/user/#{@user_id}/body.json", opts)
67
106
  end
107
+
108
+ # Log weight to fitbit for the current user
109
+ #
110
+ # @param [Integer, String] weight The weight to log, as either
111
+ # an integer or a string in "X.XX'" format
112
+ # @param [DateTime, String] date The date the weight should be
113
+ # logged, as either a DateTime or a String in 'yyyy-MM-dd' format
114
+ #
115
+ # @options opts [DateTime, String] :time The time the weight should be logged
116
+ # as either a DateTime or a String in 'HH:mm:ss' format
117
+ #
118
+ # @return [Hash]
119
+ #
120
+ # @since v0.9.0
121
+ def log_weight(weight, date, opts={})
122
+ opts[:time] = format_time(opts[:time]) if opts[:time]
123
+ post("/user/#{@user_id}/body/log/weight.json", opts.merge(:weight => weight, :date => format_date(date)))
124
+ end
125
+
126
+ # Log body fat percentage
127
+ #
128
+ # @param [Decimal, Integer, String] fatPercentage Body fat percentage to log,
129
+ # in format "X.XX" if a string
130
+ # @param [DateTime, Date, String] date The date to log body fat percentage on,
131
+ # in format "yyyy-MM-dd" if a string
132
+ # @param [Hash] opts
133
+ # @option opts [DateTime, Time, String] :time The time to log body fat percentage
134
+ # at, in " HH:mm:ss" format if a String
135
+ #
136
+ # @since v0.9.0
137
+ def log_body_fat(fatPercentage, date, opts={})
138
+ opts[:fat] = fatPercentage
139
+ opts[:date] = format_date(date)
140
+ opts[:time] = format_time(opts[:time]) if opts[:time]
141
+ post("/user/#{@user_id}/body/fat.json", opts)
142
+ end
143
+
144
+ # Create or update a user's weight goal
145
+ #
146
+ # @param [DateTime, Date, String] startDate Weight goal start date;
147
+ # in the format "yyyy-MM-dd" if a string
148
+ # @param [Decimal, Integer, String] startWeight Weight goal start weight;
149
+ # in the format "X.XX" if a string
150
+ # @param [Decimal, Integer, String] goalWeight Weight goal target weight;
151
+ # in the format "X.XX" if a string
152
+ #
153
+ # @since v0.9.0
154
+ def create_or_update_body_weight_goal(startDate, startWeight, goalWeight)
155
+ opts = {startDate: format_date(startDate), startWeight: startWeight, weight: goalWeight}
156
+ post("/user/#{@user_id}/body/log/weight/goal.json", opts)
157
+ end
158
+
159
+ # Create or update a user's body fat percentage goal
160
+ #
161
+ # @param [Decimal, Integer, String] fatPercentageGoal Target body fat in %;
162
+ # in the format "X.XX" if a string
163
+ #
164
+ # @since v0.9.0
165
+ def create_or_update_body_fat_goal(fatPercentageGoal)
166
+ opts = {fat: fatPercentageGoal}
167
+ post("/user/#{@user_id}/body/log/fat/goal.json", opts)
168
+ end
169
+
170
+ # ==========================================
171
+ # Body Measurements Delete Methods
172
+ # ==========================================
173
+
174
+ # Delete user's body weight log entry with the given id
175
+ #
176
+ # @param [Integer] logId The id of the body weight entry
177
+ #
178
+ # @since v0.9.0
179
+ def delete_body_weight_log(logId)
180
+ delete("/user/#{@user_id}/body/log/weight/#{logId}.json")
181
+ end
182
+
183
+ # Delete user's body fat log entry with the given id
184
+ #
185
+ # @param [Integer] logId The id of the body fat entry
186
+ #
187
+ # @since v0.9.0
188
+ def delete_body_fat_log(logId)
189
+ delete("/user/#{@user_id}/body/log/fat/#{logId}.json")
190
+ end
191
+
192
+ private
193
+
194
+ # Determine the URI for the body_weight or body_fat method
195
+ #
196
+ # @params [String] base_uri the base URI for the body weight or body fat method
197
+ # @params [Hash] opts body weight/fat options
198
+ # @option opts [Date] date The date in the format YYYY-mm-dd.
199
+ # @option opts [Date] base-date The end date when period is provided, in the
200
+ # format yyyy-MM-dd or today; range start date when a date range is provided.
201
+ # @option opts [String] period The date range period. One of 1d, 7d, 30d, 1w, 1m
202
+ # @option opts [Date] end-date Range end date when date range is provided.
203
+ # Note that period should not be longer than 31 day
204
+ #
205
+ # @return [String] an URI based on the base URI and provided options
206
+ def determine_body_uri(base_uri, opts = {})
207
+ if opts[:date]
208
+ date = format_date opts[:date]
209
+ "#{base_uri}/date/#{date}.json"
210
+ elsif opts[:base_date] && (opts[:period] || opts[:end_date])
211
+ date_range = construct_date_range_fragment opts
212
+ "#{base_uri}/#{date_range}.json"
213
+ else
214
+ raise Fitgem::InvalidArgumentError, "You didn't supply one of the required options."
215
+ end
216
+ end
68
217
  end
69
218
  end
data/lib/fitgem/client.rb CHANGED
@@ -22,14 +22,19 @@ require 'uri'
22
22
 
23
23
  module Fitgem
24
24
  class Client
25
- API_VERSION = "1"
26
- EMPTY_BODY = ""
25
+ API_VERSION = '1'
26
+ EMPTY_BODY = ''
27
27
 
28
28
  # Sets or gets the api_version to be used in API calls
29
29
  #"
30
30
  # @return [String]
31
31
  attr_accessor :api_version
32
32
 
33
+ # Sets or gets the ssl settings
34
+ #
35
+ # @return [Boolean]
36
+ attr_accessor :ssl
37
+
33
38
  # Sets or gets the api unit system to be used in API calls
34
39
  #
35
40
  # @return [String]
@@ -98,12 +103,13 @@ module Fitgem
98
103
  @consumer_key = opts[:consumer_key]
99
104
  @consumer_secret = opts[:consumer_secret]
100
105
 
106
+ @ssl = opts[:ssl]
101
107
 
102
108
  @token = opts[:token]
103
109
  @secret = opts[:secret]
104
110
 
105
111
  @proxy = opts[:proxy] if opts[:proxy]
106
- @user_id = opts[:user_id] || "-"
112
+ @user_id = opts[:user_id] || '-'
107
113
 
108
114
  @api_unit_system = opts[:unit_system] || Fitgem::ApiUnitSystem.US
109
115
  @api_version = API_VERSION
@@ -176,12 +182,19 @@ module Fitgem
176
182
  consumer.options[:authorize_path] = '/oauth/authenticate'
177
183
  request_token(opts)
178
184
  end
185
+
186
+ # The protocol to be used for the API requests
187
+ #
188
+ # @return [String], 'http', or 'https' if ssl == true
189
+ def protocol
190
+ ssl ? "https" : "http"
191
+ end
179
192
 
180
193
  private
181
194
 
182
195
  def consumer
183
196
  @consumer ||= OAuth::Consumer.new(@consumer_key, @consumer_secret, {
184
- :site => 'http://api.fitbit.com',
197
+ :site => "#{protocol}://api.fitbit.com",
185
198
  :proxy => @proxy
186
199
  })
187
200
  end
@@ -195,7 +208,7 @@ module Fitgem
195
208
  end
196
209
 
197
210
  def raw_get(path, headers={})
198
- headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
211
+ headers.merge!('User-Agent' => "fitgem gem v#{Fitgem::VERSION}", 'Accept-Language' => @api_unit_system)
199
212
  uri = "/#{@api_version}#{path}"
200
213
  access_token.get(uri, headers)
201
214
  end
@@ -205,7 +218,7 @@ module Fitgem
205
218
  end
206
219
 
207
220
  def raw_post(path, body='', headers={})
208
- headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
221
+ headers.merge!('User-Agent' => "fitgem gem v#{Fitgem::VERSION}", 'Accept-Language' => @api_unit_system)
209
222
  uri = "/#{@api_version}#{path}"
210
223
  access_token.post(uri, body, headers)
211
224
  end
@@ -215,7 +228,7 @@ module Fitgem
215
228
  end
216
229
 
217
230
  def raw_delete(path, headers={})
218
- headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
231
+ headers.merge!('User-Agent' => "fitgem gem v#{Fitgem::VERSION}", 'Accept-Language' => @api_unit_system)
219
232
  uri = "/#{@api_version}#{path}"
220
233
  access_token.delete(uri, headers)
221
234
  end
data/lib/fitgem/foods.rb CHANGED
@@ -17,7 +17,7 @@ module Fitgem
17
17
  #
18
18
  # @return [Array] A list of foods, each of which is a Hash
19
19
  # containing the food details
20
- def recent_foods()
20
+ def recent_foods
21
21
  get("/user/#{@user_id}/foods/log/recent.json")
22
22
  end
23
23
 
@@ -25,7 +25,7 @@ module Fitgem
25
25
  #
26
26
  # @return [Array] A list of foods, each of which is a Hash
27
27
  # containing the food details
28
- def frequent_foods()
28
+ def frequent_foods
29
29
  get("/user/#{@user_id}/foods/log/frequent.json")
30
30
  end
31
31
 
@@ -33,15 +33,24 @@ module Fitgem
33
33
  #
34
34
  # @return [Array] A list of foods, each of which is a Hash
35
35
  # containing the food details
36
- def favorite_foods()
36
+ def favorite_foods
37
37
  get("/user/#{@user_id}/foods/log/favorite.json")
38
38
  end
39
39
 
40
40
  # Get a list of all of the available food units
41
41
  #
42
42
  # @return [Array] List of food units
43
- def foods_units()
44
- get("/foods/units.json")
43
+ def foods_units
44
+ get('/foods/units.json')
45
+ end
46
+
47
+ # Get a hash containing the user's meal informarion
48
+ #
49
+ # @return [Hash] Meal information
50
+ #
51
+ # @since v0.9.0
52
+ def meals
53
+ get("/user/#{@user_id}/meals.json")
45
54
  end
46
55
 
47
56
  # ==========================================
@@ -77,7 +86,7 @@ module Fitgem
77
86
  # @option opts [Integer, String] :foodId Food id
78
87
  # @option opts [String] :foodName Food entry name
79
88
  # @option opts [String] :brandName Brand name, valid only with foodName
80
- # @option opts [Integer, String] :calories Calories for this serving size,
89
+ # @option opts [Integer, String] :calories Calories for this serving size,
81
90
  # valid only with foodName
82
91
  # @option opts [Integer, String] :mealTypeId Meal type id; (1 -
83
92
  # Breakfast, 2 - Morning Snack, 3 - Lunch, 4 - Afternoon Snack, 5 - Dinner, 7 - Anytime)
@@ -12,18 +12,31 @@ module Fitgem
12
12
  get("/user/#{@user_id}/friends.json")
13
13
  end
14
14
 
15
- # Get the weekly leaderboard of friends' activities
15
+ # Get the leaderboard of friends' weekly activities
16
16
  #
17
17
  # @return [Hash] Friends' information
18
- def weekly_leaderboard
19
- leaderboard('7d')
18
+ def leaderboard
19
+ get("/user/#{@user_id}/friends/leaderboard.json")
20
20
  end
21
21
 
22
- # Get the monthly leaderboard of friends' activities
22
+ # Get the leaderboard of friends' weekly activities
23
23
  #
24
24
  # @return [Hash] Friends' information
25
+ #
26
+ # @deprecated Monthly leaderboards are no longer available from Fitbit. Please update to use {#leaderboard}
25
27
  def monthly_leaderboard
26
- leaderboard('30d')
28
+ warn '[DEPRECATED] monthly_leaderboard will be removed in v1.0. Update to using leaderboard method.'
29
+ leaderboard
30
+ end
31
+
32
+ # Get the leaderboard of friends' weekly activities
33
+ #
34
+ # @return [Hash] Friends' information
35
+ #
36
+ # @deprecated Please update to use {#leaderboard}
37
+ def weekly_leaderboard
38
+ warn '[DEPRECATED] weekly_leaderboard will be removed in v1.0. Update to using leaderboard method.'
39
+ leaderboard
27
40
  end
28
41
 
29
42
  # ==========================================
@@ -70,10 +83,6 @@ module Fitgem
70
83
 
71
84
  private
72
85
 
73
- def leaderboard(range)
74
- get("/user/#{@user_id}/friends/leaders/#{range}.json")
75
- end
76
-
77
86
  def respond_to_invite(requestor_id, does_accept)
78
87
  options = { :accept => does_accept.to_s }
79
88
  post("/user/#{@user_id}/friends/invitations/#{requestor_id}.json", options)
data/lib/fitgem/users.rb CHANGED
@@ -15,11 +15,32 @@ module Fitgem
15
15
  # @option opts [DateTime, Date, String] :birthday Birthday, in
16
16
  # "yyyy-MM-dd" if a String
17
17
  # @option opts [Decimal, Integer, String] :height Height, in format
18
- # "X.XX" if a string
18
+ # "X.XX" if a String
19
19
  # @option opts [String] :nickname Nickname
20
+ # @option opts [String] :aboutMe About Me description
20
21
  # @option opts [String] :fullName Full name
22
+ # @option opts [String] :country; two-character code
23
+ # @option opts [String] :state; two-character code
24
+ # @option opts [String] :city
25
+ # @option opts [Decimal, Integer, String] :strideLengthWalking Walking
26
+ # stride length, in format "X.XX" if a String
27
+ # @option opts [Decimal, Integer, String] :strideLengthRunning Running
28
+ # stride length, in format "X.XX" if a String
29
+ # @option opts [String] :weightUnit Default water unit on website
30
+ # (doesn't affect API); one of (en_US, en_GB, "any" for METRIC)
31
+ # @option opts [String] :heightUnit Default height/distance unit
32
+ # on website (doesn't affect API); one of (en_US, "any" for METRIC)
33
+ # @option opts [String] :waterUnit Default water unit on website
34
+ # (doesn't affect API); one of (en_US, "any" for METRIC)
35
+ # @option opts [String] :glucoseUnit Default glucose unit on website
36
+ # (doesn't affect API); one of (en_US, "any" for METRIC)
21
37
  # @option opts [String] :timezone Time zone; in the format
22
38
  # "America/Los Angelos"
39
+ # @option opts [String] :foodsLocale Food Database Locale; in the
40
+ # format "xx_XX"
41
+ # @option opts [String] :locale Locale of website (country/language);
42
+ # one of the locales, see https://wiki.fitbit.com/display/API/API-Update-User-Info
43
+ # for the currently supported values.
23
44
  #
24
45
  # @return [Hash] Hash containing updated profile information
25
46
  def update_user_info(opts)
@@ -1,3 +1,3 @@
1
1
  module Fitgem
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
data/spec/fitgem_spec.rb CHANGED
@@ -32,5 +32,33 @@ describe Fitgem do
32
32
  it 'should default to a user id of \'-\', the currently-logged in user' do
33
33
  @client.user_id.should == '-'
34
34
  end
35
+
36
+ it "returns the protocol to be used" do
37
+ @client.protocol.should eq "http"
38
+ end
39
+
40
+ describe "ssl" do
41
+ it "should expose the ssl setting" do
42
+ @client.ssl.should eq nil
43
+ end
44
+
45
+ context "when true" do
46
+ let(:client) { Fitgem::Client.new({
47
+ :consumer_key => '12345',
48
+ :consumer_secret => '67890',
49
+ :ssl => true
50
+ }) }
51
+
52
+ it "can set the ssl setting to true" do
53
+ client.ssl.should be_true
54
+ end
55
+
56
+ it "uses https protocol" do
57
+ client.protocol.should eq "https"
58
+ end
59
+
60
+ end
61
+
62
+ end
35
63
  end
36
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachery Moneypenny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-03 00:00:00.000000000 Z
11
+ date: 2014-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth