fitgem 0.7.0 → 0.8.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: 5aaeb0e1f4c0baea6b4d4b4e3a49625b8263d18f
4
- data.tar.gz: e89fd2e5c2fb3694bfca85a311ef13dff614f7f2
3
+ metadata.gz: 0093dff6f708728ec192e7dd062940d0091d856b
4
+ data.tar.gz: da17edef7d5d5b62529eae6f0afad4a7b3ba7fc4
5
5
  SHA512:
6
- metadata.gz: 5b7334843303227af479383f16a012a8445ca6ccf584ace5c54cf34f9dc23bb883e586e48dbd02657922c03d27e984f0600fb925a6d64c614364ff2c26039655
7
- data.tar.gz: 8611b499e6fd9108d4d5fefca76226a296ff88d7695015423b8315fb937916af0cebc6bedf3173e345dc0bcef2c822e791641d468cc074e892ce386a3aff449a
6
+ metadata.gz: 88e9581a93d35371073e55e41bc612fb0db45b5f46c4113f9354dbc1e63bf8e8475e0ce0a7f2c7f169d5f18d3312a1b9a7a47f96bc3c97b27e6bbdc3c30c1671
7
+ data.tar.gz: 0f650a3fb149884f52ddab2e6c731ff58da874455a7e3b2ae43258bfb73b5b73a84a0d26daf71beb09ba93ee7ed221ee79e04ae8002f109eb5e05c79b40217d3
data/README.md CHANGED
@@ -1,23 +1,38 @@
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 API](http://dev.fitbit.com). Fitgem can pull data with or without usernauthentication. 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
+ 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.
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. Since it is early in the lifecycle of the API I expect this gem to go through a number of revisions as we attempt to match the functionality of their platform.
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.
6
6
 
7
7
  # Usage
8
8
 
9
- Install fitgem:
9
+ Install fitgem
10
10
 
11
11
  ```bash
12
12
  $ gem install fitgem
13
13
  ```
14
+
15
+ or add it to your Gemfile
16
+
17
+ ```ruby
18
+ gem 'fitgem'
19
+ ```
20
+
14
21
  Comprehensive method documentation is [available online](http://www.rubydoc.info/github/whazzmaster/fitgem/frames).
15
22
 
16
23
  The best way to connect your users to the Fitbit API is to use
17
24
  **[omniauth-fitbit](https://github.com/tkgospodinov/omniauth-fitbit)** to integrate Fitbit accounts into your web
18
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.
19
26
 
20
- **Go to [http://fitbitclient.com](http://fitbitclient.com) to view online documentation on how to use fitgem**. The reference app includes information on how to use some bench test tools to get acquainted with the library, and the application code itself (Rails 3.2 + Backbone.js) is also [available online](https://github.com/whazzmaster/fitgem-client) to illustrate how the live data from Fitbit is manipulated by the application.
27
+ ## Reference Application
28
+
29
+ To learn more about how to use fitgem in a Rails application, go to [http://fitbitclient.com](http://fitbitclient.com) or see the code at [https://github.com/whazzmaster/fitgem-client](https://github.com/whazzmaster/fitgem-client).
30
+
31
+ The reference app is written using Rails 3.2 and [Backbone.js](http://backbonejs.org) and includes examples on how to:
32
+
33
+ * Integrate OAuth logins [omniauth-fitbit](https://github.com/tkgospodinov/omniauth-fitbit)
34
+ * Store and use OAuth access tokens
35
+ * Create and use instances of `Fitgem::Client` using the stored OAuth access token
21
36
 
22
37
  # Subscriptions
23
38
 
@@ -32,8 +47,8 @@ The Fitbit REST API is in BETA right now, and so it will quite likely change ove
32
47
  * Fork the project
33
48
  * Start a feature/bugfix branch
34
49
  * Commit and push until you are happy with your contribution
35
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
36
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise
50
+ * **Make sure to add tests for it**. This is important so I don't break it in a future version unintentionally.
51
+ * **Please try not to mess with the Rakefile, version, or history**. If you want to have your own version, or is otherwise
37
52
  necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
38
53
 
39
54
  ## Contributors
@@ -42,5 +57,5 @@ necessary, that is fine, but please isolate to its own commit so I can cherry-pi
42
57
 
43
58
  # Copyright & Disclaimer
44
59
 
45
- Copyright © 2011-2013 Zachery Moneypenny. See LICENSE for further details. __I am not employed by 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.
60
+ 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.
46
61
 
data/changelog.md CHANGED
@@ -3,6 +3,40 @@
3
3
 
4
4
  # fitgem changelog
5
5
 
6
+ ## v0.8.0
7
+
8
+ #### 2013-08-03 Zachery Moneypenny <fitgem@whazzmaster.com>
9
+
10
+ * Add support for weekly goals
11
+ * Add support for silent alarms (including updates)
12
+ * Add support for intraday distance
13
+ * Add time zone support for usage of times
14
+ * Add support for badges
15
+
16
+ ## v0.7.0
17
+
18
+ #### 2013-05-17 Zachery Moneypenny <fitgem@whazzmaster.com>
19
+
20
+ * Add support for intraday time series retrieval of various resources
21
+ * Removed rvmrc from project- use whatever ruby you want!
22
+ * Updated Travis CI configuration
23
+
24
+ ## v0.6.1
25
+
26
+ #### 2013-02-28 Zachery Moneypenny <fitgem@whazzmaster.com>
27
+
28
+ * More unit tests
29
+ * Fix an issue where we weren't applying the `format_date` helper when constructing a date range fragment
30
+
31
+ ## v0.6.0
32
+
33
+ * Streamline the README; add contributors link
34
+ * Removed FAQs from README
35
+ * Added support for daily activity goals
36
+ * Moved testing-focused gemspec dependencies to the Gemfile
37
+
38
+ #### 2013-02-13 Zachery Moneypenny <fitgem@whazzmaster.com>
39
+
6
40
  ## v0.5.2
7
41
 
8
42
  #### 2012-03-04 Zachery Moneypenny <fitgem@whazzmaster.com>
data/fitgem.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.files = [
26
26
  '.gitignore',
27
- '.rvmrc',
27
+ # '.rvmrc',
28
28
  '.yardopts',
29
29
  '.travis.yml',
30
30
  'Gemfile',
@@ -37,6 +37,8 @@ Gem::Specification.new do |s|
37
37
  'lib/fitgem.rb',
38
38
  'lib/fitgem/version.rb',
39
39
  'lib/fitgem/activities.rb',
40
+ 'lib/fitgem/alarms.rb',
41
+ 'lib/fitgem/badges.rb',
40
42
  'lib/fitgem/body_measurements.rb',
41
43
  'lib/fitgem/client.rb',
42
44
  'lib/fitgem/devices.rb',
@@ -71,6 +71,14 @@ module Fitgem
71
71
  get("/user/#{@user_id}/activities/goals/daily.json")
72
72
  end
73
73
 
74
+ # Get the weekly activity goals for the current user
75
+ #
76
+ # @return [Hash] Hash containing the distance, floors and step goals
77
+ # for the current user
78
+ def weekly_goals
79
+ get("/user/#{@user_id}/activities/goals/weekly.json")
80
+ end
81
+
74
82
  # ==========================================
75
83
  # Activity Update Methods
76
84
  # ==========================================
@@ -158,8 +166,8 @@ module Fitgem
158
166
  #
159
167
  # @return [Hash] A hash containing time series data
160
168
  def intraday_time_series(opts)
161
- unless opts[:resource] && [:calories, :steps, :floors, :elevation].include?(opts[:resource])
162
- raise Fitgem::InvalidArgumentError, 'Must specify resource to fetch intraday time series data for. One of (:calories, :steps, :floors, or :elevation) is required.'
169
+ unless opts[:resource] && [:calories, :steps, :distance, :floors, :elevation].include?(opts[:resource])
170
+ raise Fitgem::InvalidArgumentError, 'Must specify resource to fetch intraday time series data for. One of (:calories, :steps, :distance, :floors, or :elevation) is required.'
163
171
  end
164
172
 
165
173
  unless opts[:date]
@@ -0,0 +1,67 @@
1
+ module Fitgem
2
+ class Client
3
+ # Add a silent alarm to your profile
4
+ #
5
+ # @param [Hash] opts Alarm options
6
+ # @option opts [Integer, String] device_id The id of the device you would like
7
+ # to manage the alarm on
8
+ # @option opts [String] :time Time of the alarm in the format XX:XX+XX:XX, time
9
+ # with timezone
10
+ # @option opts [TrueClass, FalseClass] :enabled
11
+ # @option opts [TrueClass, FalseClass] :recurring One time or recurring alarm
12
+ # @option opts [String] :weekDays The days the alarm is active on as a list of
13
+ # comma separated values: MONDAY, WEDNESDAY, SATURDAY. For recurring only
14
+ # @option opts [Integer] :snoozeLength Minutes between the alarms
15
+ # @option opts [Integer] :snoozeCount Maximum snooze count
16
+ # @option opts [String] :label Label for the alarm
17
+ #
18
+ # @return [Hash] Hash containing the alarm settings
19
+ def add_alarm(opts)
20
+ device_id = opts[:device_id]
21
+ post("/user/#{@user_id}/devices/tracker/#{device_id}/alarms.json", opts)
22
+ end
23
+
24
+ # Retrieve the silent alarms of your device
25
+ #
26
+ # @param [Integer, String] device_id The id of the device you would like to
27
+ # manage the alarms of
28
+ #
29
+ # @return [Hash] Hash containing the alarms and it's settings
30
+ def get_alarms(device_id)
31
+ get("/user/#{@user_id}/devices/tracker/#{device_id}/alarms.json")
32
+ end
33
+
34
+ # Remove a silent alarm from your profile
35
+ #
36
+ # @param [Integer, String] alarm_id The id of the alarm
37
+ # @param [Integer, String] device_id The id of the device you would like to
38
+ # manage the alarm on
39
+ #
40
+ # @return [Hash] Empty hash denotes success
41
+ def delete_alarm(alarm_id, device_id)
42
+ delete("/user/#{@user_id}/devices/tracker/#{device_id}/alarms/#{alarm_id}.json")
43
+ end
44
+
45
+ # Update an existing alarm
46
+ #
47
+ # @param [Integer, String] alarm_id The id of the alarm
48
+ # @param [Integer, String] device_id The id of the device you would like to
49
+ # manage the alarm on
50
+ # @param [Hash] opts Alarm settings
51
+ # @option opts [DateTime, Time, String] :time Time of the alarm
52
+ # @option opts [TrueClass, FalseClass] :enabled
53
+ # @option opts [TrueClass, FalseClass] :recurring One time or recurring alarm
54
+ # @option opts [String] :weekDays The days the alarm is active on as a list of
55
+ # comma separated values: MONDAY, WEDNESDAY, SATURDAY. For recurring only
56
+ # @option opts [Integer] :snoozeLength Minutes between the alarms
57
+ # @option opts [Integer] :snoozeCount Maximum snooze count
58
+ # @option opts [String] :label Label for the alarm
59
+ #
60
+ # @return [Hash] Hash containing updated alarm settings
61
+ def update_alarm(alarm_id, device_id, opts)
62
+ opts[:time] = format_time opts[:time], include_timezone: true
63
+ post("/user/#{@user_id}/devices/tracker/#{device_id}/alarms/#{alarm_id}.json", opts)
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,12 @@
1
+ module Fitgem
2
+ class Client
3
+
4
+ # Get a list of all badges earned
5
+ #
6
+ # @return [Hash] Hash containing an array of badges
7
+ def badges
8
+ get("/user/#{@user_id}/badges.json")
9
+ end
10
+
11
+ end
12
+ end
data/lib/fitgem/client.rb CHANGED
@@ -15,6 +15,8 @@ require 'fitgem/body_measurements'
15
15
  require 'fitgem/time_range'
16
16
  require 'fitgem/devices'
17
17
  require 'fitgem/notifications'
18
+ require 'fitgem/alarms'
19
+ require 'fitgem/badges'
18
20
  require 'date'
19
21
  require 'uri'
20
22
 
@@ -43,22 +43,26 @@ module Fitgem
43
43
  # indicate that the time value used is the current localtime.
44
44
  #
45
45
  # @param [DateTime, Time, String] time The object to format into a time string
46
+ # @param [Hash] opts format time options
47
+ # @option opts [TrueClass, FalseClass] :include_timezone Include timezone in the output or not
46
48
  # @raise [Fitgem::InvalidTimeArgument] Raised when the parameter object is not a
47
49
  # DateTime, Time, or a valid ("HH:mm" or "now") string object
48
50
  # @return [String] Date in "HH:mm" string format
49
- def format_time(time)
51
+ def format_time(time, opts = {})
52
+ format = opts[:include_timezone] ? "%H:%M%:z" : "%H:%M"
50
53
  if time.is_a? String
51
54
  case time
52
55
  when 'now'
53
- return DateTime.now.strftime("%H:%M")
56
+ return DateTime.now.strftime format
54
57
  else
55
- unless time =~ /\d{2}\:\d{2}/
58
+ unless time =~ /^\d{2}\:\d{2}$/
56
59
  raise Fitgem::InvalidTimeArgument, "Invalid time (#{time}), must be in HH:mm format"
57
60
  end
58
- return time
61
+ timezone = DateTime.now.strftime("%:z")
62
+ return opts[:include_timezone] ? [ time, timezone ].join : time
59
63
  end
60
64
  elsif DateTime === time || Time === time
61
- return time.strftime("%H:%M")
65
+ return time.strftime format
62
66
  else
63
67
  raise Fitgem::InvalidTimeArgument, "Date used must be a valid time object or a string in the format HH:mm; supplied argument is a #{time.class}"
64
68
  end
@@ -1,3 +1,3 @@
1
1
  module Fitgem
2
- VERSION = "0.7.0"
2
+ VERSION = '0.8.0'
3
3
  end
@@ -84,24 +84,51 @@ describe Fitgem::Client do
84
84
  end
85
85
 
86
86
  describe "#format_time" do
87
- it "accepts DateTime objects" do
88
- time = DateTime.parse("3rd Feb 2001 04:05:06 PM")
89
- @client.format_time(time).should == "16:05"
90
- end
87
+ context "without a timezone" do
88
+ it "accepts DateTime objects" do
89
+ time = DateTime.parse("3rd Feb 2001 04:05:06 PM")
90
+ @client.format_time(time).should == "16:05"
91
+ end
91
92
 
92
- it "accepts Time objects" do
93
- time = Time.mktime 2012, 1, 20, 13, 33, 30
94
- @client.format_time(time).should == "13:33"
95
- end
93
+ it "accepts Time objects" do
94
+ time = Time.mktime 2012, 1, 20, 13, 33, 30
95
+ @client.format_time(time).should == "13:33"
96
+ end
97
+
98
+ it "accepts the string 'now' to denote the current localtime" do
99
+ now = DateTime.now
100
+ @client.format_time('now').should == now.strftime("%H:%M")
101
+ end
96
102
 
97
- it "accepts the string 'now' to denote the current localtime" do
98
- now = DateTime.now
99
- @client.format_time('now').should == now.strftime("%H:%M")
103
+ it "accepts strings in HH:mm format" do
104
+ time = "04:20"
105
+ @client.format_time(time).should == "04:20"
106
+ end
100
107
  end
101
108
 
102
- it "accepts strings in HH:mm format" do
103
- time = "04:20"
104
- @client.format_time(time).should == "04:20"
109
+ context "with a timezone" do
110
+ it "accepts DateTime objects" do
111
+ time = DateTime.parse("3rd Feb 2001 04:05:06 PM UTC")
112
+ @client.format_time(time, include_timezone: true).should == "16:05+00:00"
113
+ end
114
+
115
+ it "accepts Time objects" do
116
+ time = Time.new 2012, 1, 20, 13, 33, 30, "+00:00"
117
+ @client.format_time(time, include_timezone: true).should == "13:33+00:00"
118
+ end
119
+
120
+ it "accepts the string 'now' to denote the current localtime" do
121
+ now = DateTime.now
122
+ @client.format_time('now', include_timezone: true).should == now.strftime("%H:%M%:z")
123
+ end
124
+
125
+ it "accepts strings in HH:mm format" do
126
+ datetime = DateTime.parse("26th Apr 2000 09:27:00 +08:00")
127
+ DateTime.stub(:now).and_return datetime
128
+
129
+ time = "04:20"
130
+ @client.format_time(time, include_timezone: true).should == "04:20+08:00"
131
+ end
105
132
  end
106
133
 
107
134
  it "rejects Date objects" do
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.7.0
4
+ version: 0.8.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-05-17 00:00:00.000000000 Z
11
+ date: 2013-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -89,7 +89,6 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - .gitignore
92
- - .rvmrc
93
92
  - .yardopts
94
93
  - .travis.yml
95
94
  - Gemfile
@@ -102,6 +101,8 @@ files:
102
101
  - lib/fitgem.rb
103
102
  - lib/fitgem/version.rb
104
103
  - lib/fitgem/activities.rb
104
+ - lib/fitgem/alarms.rb
105
+ - lib/fitgem/badges.rb
105
106
  - lib/fitgem/body_measurements.rb
106
107
  - lib/fitgem/client.rb
107
108
  - lib/fitgem/devices.rb