fitgem 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/changelog.md +8 -0
- data/fitgem.gemspec +12 -12
- data/lib/fitgem/client.rb +1 -15
- data/lib/fitgem/errors.rb +3 -0
- data/lib/fitgem/friends.rb +2 -4
- data/lib/fitgem/notifications.rb +2 -2
- data/lib/fitgem/version.rb +1 -1
- data/spec/fitgem_helper_spec.rb +43 -43
- data/spec/fitgem_notifications_spec.rb +29 -29
- data/spec/fitgem_spec.rb +7 -35
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d4e7ae922736d2f4d8093c43988e563c2a2fae
|
4
|
+
data.tar.gz: 1c018275740218d4adc237efd254740cf9656153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff191fe963d6291b1ed8cf97be3b606e0dc5a27fab0696d2927d012d7774760b61cbe7064c207194b2fcd43e7248cb9c9a8f767661e0e6d2974648d02d187f06
|
7
|
+
data.tar.gz: fee32faa7cfa3137dd711f71a1461d04fa1a30cc7951e03674d1da8b81adedac05be14c92f68ea45f6eba546878ee4e1362df08d4d78cc668fd584e50dca4a4d
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Fitgem [](http://travis-ci.org/whazzmaster/fitgem)
|
2
2
|
|
3
|
-
|
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 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
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
|
|
data/changelog.md
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
|
4
4
|
# fitgem changelog
|
5
5
|
|
6
|
+
## v0.10.0
|
7
|
+
|
8
|
+
#### 2014-08-08 Zachery Moneypenny <fitgem@whazzmaster.com>
|
9
|
+
|
10
|
+
* Updates default test framework to RSpec 3
|
11
|
+
* Updates library to use SSL exclusively when hitting the Fitbit REST API. Fitbit is restricting access to its API via https only on November 3rd, 2014. See [issue #30](https://github.com/whazzmaster/fitgem/issues/30) for more information. This should be transparent to end users of fitgem, as the library simply ignores the :ssl option in the Client constructor and defaults to https everywhere.
|
12
|
+
* The previously-deprecated `weekly_leaderboard` and `monthly_leaderboard` methods have now been updated to throw a `DeprecatedApiError` rather than warning about deprecation. These methods will be removed in v1.0.
|
13
|
+
|
6
14
|
## v0.9.0
|
7
15
|
|
8
16
|
#### 2014-02-11 Zachery Moneypenny <fitgem@whazzmaster.com>
|
data/fitgem.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
3
|
$:.push File.join(File.dirname(__FILE__), '.', 'lib')
|
4
4
|
|
5
5
|
require 'fitgem/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name =
|
8
|
+
s.name = 'fitgem'
|
9
9
|
s.version = Fitgem::VERSION
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.authors = [
|
12
|
-
s.email = [
|
13
|
-
s.homepage =
|
11
|
+
s.authors = ['Zachery Moneypenny']
|
12
|
+
s.email = ['fitgem@whazzmaster.com']
|
13
|
+
s.homepage = 'http://github.com/whazzmaster/fitgem'
|
14
14
|
s.summary = %q{OAuth client library to the data on fitbit.com}
|
15
15
|
s.description = %q{A client library to send and retrieve workout, weight, and diet data from fitbit.com}
|
16
16
|
|
17
|
-
s.rubyforge_project =
|
17
|
+
s.rubyforge_project = 'fitgem'
|
18
18
|
|
19
|
-
s.add_dependency
|
20
|
-
s.add_development_dependency
|
21
|
-
s.add_development_dependency
|
22
|
-
s.add_development_dependency
|
23
|
-
s.add_development_dependency
|
19
|
+
s.add_dependency 'oauth'
|
20
|
+
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'rspec', '~> 3.0.0'
|
22
|
+
s.add_development_dependency 'yard'
|
23
|
+
s.add_development_dependency 'rdiscount'
|
24
24
|
|
25
25
|
s.files = [
|
26
26
|
'.gitignore',
|
@@ -69,5 +69,5 @@ Gem::Specification.new do |s|
|
|
69
69
|
'spec/fitgem_helper_spec.rb',
|
70
70
|
'spec/fitgem_constructor_spec.rb'
|
71
71
|
]
|
72
|
-
s.require_paths = [
|
72
|
+
s.require_paths = ['lib']
|
73
73
|
end
|
data/lib/fitgem/client.rb
CHANGED
@@ -30,11 +30,6 @@ module Fitgem
|
|
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
|
-
|
38
33
|
# Sets or gets the api unit system to be used in API calls
|
39
34
|
#
|
40
35
|
# @return [String]
|
@@ -103,8 +98,6 @@ module Fitgem
|
|
103
98
|
@consumer_key = opts[:consumer_key]
|
104
99
|
@consumer_secret = opts[:consumer_secret]
|
105
100
|
|
106
|
-
@ssl = opts[:ssl]
|
107
|
-
|
108
101
|
@token = opts[:token]
|
109
102
|
@secret = opts[:secret]
|
110
103
|
|
@@ -182,19 +175,12 @@ module Fitgem
|
|
182
175
|
consumer.options[:authorize_path] = '/oauth/authenticate'
|
183
176
|
request_token(opts)
|
184
177
|
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
|
192
178
|
|
193
179
|
private
|
194
180
|
|
195
181
|
def consumer
|
196
182
|
@consumer ||= OAuth::Consumer.new(@consumer_key, @consumer_secret, {
|
197
|
-
:site =>
|
183
|
+
:site => 'https://api.fitbit.com',
|
198
184
|
:proxy => @proxy
|
199
185
|
})
|
200
186
|
end
|
data/lib/fitgem/errors.rb
CHANGED
data/lib/fitgem/friends.rb
CHANGED
@@ -25,8 +25,7 @@ module Fitgem
|
|
25
25
|
#
|
26
26
|
# @deprecated Monthly leaderboards are no longer available from Fitbit. Please update to use {#leaderboard}
|
27
27
|
def monthly_leaderboard
|
28
|
-
|
29
|
-
leaderboard
|
28
|
+
raise DeprecatedApiError, 'Fitbit no longer exposes a monthly leaderboard. See https://wiki.fitbit.com/display/API/API-Get-Friends-Leaderboard for more information. Use #leaderboard() instead.'
|
30
29
|
end
|
31
30
|
|
32
31
|
# Get the leaderboard of friends' weekly activities
|
@@ -35,8 +34,7 @@ module Fitgem
|
|
35
34
|
#
|
36
35
|
# @deprecated Please update to use {#leaderboard}
|
37
36
|
def weekly_leaderboard
|
38
|
-
|
39
|
-
leaderboard
|
37
|
+
raise DeprecatedApiError, 'Fitbit now only exposes a weekly leaderboard, Use #leaderboard() instead.'
|
40
38
|
end
|
41
39
|
|
42
40
|
# ==========================================
|
data/lib/fitgem/notifications.rb
CHANGED
@@ -16,7 +16,7 @@ module Fitgem
|
|
16
16
|
|
17
17
|
# Creates a notification subscription
|
18
18
|
#
|
19
|
-
# @note You must check the HTTP response code to check the status of the request to add a subscription. See {https://wiki.fitbit.com/display/API/Subscriptions
|
19
|
+
# @note You must check the HTTP response code to check the status of the request to add a subscription. See {https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API} for information about what the codes mean.
|
20
20
|
#
|
21
21
|
# @param [Hash] opts The notification subscription data
|
22
22
|
# @option opts [Symbol] :type The type of subscription (valid
|
@@ -33,7 +33,7 @@ module Fitgem
|
|
33
33
|
|
34
34
|
# Removes a notification subscription
|
35
35
|
#
|
36
|
-
# @note You must check the HTTP response code to check the status of the request to remove a subscription. See {https://wiki.fitbit.com/display/API/Subscriptions
|
36
|
+
# @note You must check the HTTP response code to check the status of the request to remove a subscription. See {https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API} for information about what the codes mean.
|
37
37
|
#
|
38
38
|
# @param [Hash] opts The notification subscription data
|
39
39
|
# @option opts [Symbol] :type The type of subscription to remove;
|
data/lib/fitgem/version.rb
CHANGED
data/spec/fitgem_helper_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe Fitgem::Client do
|
|
11
11
|
describe "#construct_date_range_fragment" do
|
12
12
|
it 'should format the correct URI fragment based on a base date and end date' do
|
13
13
|
frag = @client.construct_date_range_fragment({:base_date => '2011-03-07', :end_date => '2011-03-14'})
|
14
|
-
frag.
|
14
|
+
expect(frag).to eq 'date/2011-03-07/2011-03-14'
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should format the correct URI fragment based on a base date and period' do
|
18
18
|
frag = @client.construct_date_range_fragment({:base_date => '2011-03-07', :period => '7d'})
|
19
|
-
frag.
|
19
|
+
expect(frag).to eq 'date/2011-03-07/7d'
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should raise an error unless there is a base date AND either a period or an end date' do
|
@@ -37,28 +37,28 @@ describe Fitgem::Client do
|
|
37
37
|
span_start = DateTime.new(1997, 4, 18, 9, 30, 30)
|
38
38
|
span_end = DateTime.new(1999, 10, 3, 15, 30, 30)
|
39
39
|
frag = @client.construct_date_range_fragment base_date: span_start, end_date: span_end
|
40
|
-
frag.
|
40
|
+
expect(frag).to eq 'date/1997-04-18/1999-10-03'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "#format_date" do
|
45
45
|
it "accepts DateTime objects" do
|
46
46
|
date = DateTime.strptime('2011-03-19','%Y-%m-%d')
|
47
|
-
@client.format_date(date).
|
47
|
+
expect(@client.format_date(date)).to eq '2011-03-19'
|
48
48
|
end
|
49
49
|
|
50
50
|
it "accepts strings in YYYY-MM-DD format" do
|
51
|
-
@client.format_date('2011-03-19').
|
51
|
+
expect(@client.format_date('2011-03-19')).to eq '2011-03-19'
|
52
52
|
end
|
53
53
|
|
54
54
|
it "accepts the string 'today' to denote the current date" do
|
55
55
|
today = Date.today.strftime("%Y-%m-%d")
|
56
|
-
@client.format_date('today').
|
56
|
+
expect(@client.format_date('today')).to eq today
|
57
57
|
end
|
58
58
|
|
59
59
|
it "accepts the string 'yesterday' to denote the day previous to today" do
|
60
60
|
yesterday = (Date.today-1).strftime("%Y-%m-%d")
|
61
|
-
@client.format_date('yesterday').
|
61
|
+
expect(@client.format_date('yesterday')).to eq yesterday
|
62
62
|
end
|
63
63
|
|
64
64
|
it "rejects strings that are not in YYY-MM-DD format" do
|
@@ -87,47 +87,47 @@ describe Fitgem::Client do
|
|
87
87
|
context "without a timezone" do
|
88
88
|
it "accepts DateTime objects" do
|
89
89
|
time = DateTime.parse("3rd Feb 2001 04:05:06 PM")
|
90
|
-
@client.format_time(time).
|
90
|
+
expect(@client.format_time(time)).to eq "16:05"
|
91
91
|
end
|
92
92
|
|
93
93
|
it "accepts Time objects" do
|
94
94
|
time = Time.mktime 2012, 1, 20, 13, 33, 30
|
95
|
-
@client.format_time(time).
|
95
|
+
expect(@client.format_time(time)).to eq "13:33"
|
96
96
|
end
|
97
97
|
|
98
98
|
it "accepts the string 'now' to denote the current localtime" do
|
99
99
|
now = DateTime.now
|
100
|
-
@client.format_time('now').
|
100
|
+
expect(@client.format_time('now')).to eq now.strftime("%H:%M")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "accepts strings in HH:mm format" do
|
104
104
|
time = "04:20"
|
105
|
-
@client.format_time(time).
|
105
|
+
expect(@client.format_time(time)).to eq "04:20"
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
context "with a timezone" do
|
110
110
|
it "accepts DateTime objects" do
|
111
111
|
time = DateTime.parse("3rd Feb 2001 04:05:06 PM UTC")
|
112
|
-
@client.format_time(time, include_timezone: true).
|
112
|
+
expect(@client.format_time(time, include_timezone: true)).to eq "16:05+00:00"
|
113
113
|
end
|
114
114
|
|
115
115
|
it "accepts Time objects" do
|
116
116
|
time = Time.new 2012, 1, 20, 13, 33, 30, "+00:00"
|
117
|
-
@client.format_time(time, include_timezone: true).
|
117
|
+
expect(@client.format_time(time, include_timezone: true)).to eq "13:33+00:00"
|
118
118
|
end
|
119
119
|
|
120
120
|
it "accepts the string 'now' to denote the current localtime" do
|
121
121
|
now = DateTime.now
|
122
|
-
@client.format_time('now', include_timezone: true).
|
122
|
+
expect(@client.format_time('now', include_timezone: true)).to eq now.strftime("%H:%M%:z")
|
123
123
|
end
|
124
124
|
|
125
125
|
it "accepts strings in HH:mm format" do
|
126
126
|
datetime = DateTime.parse("26th Apr 2000 09:27:00 +08:00")
|
127
|
-
DateTime.
|
127
|
+
allow(DateTime).to receive(:now).and_return datetime
|
128
128
|
|
129
129
|
time = "04:20"
|
130
|
-
@client.format_time(time, include_timezone: true).
|
130
|
+
expect(@client.format_time(time, include_timezone: true)).to eq "04:20+08:00"
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -195,49 +195,49 @@ describe Fitgem::Client do
|
|
195
195
|
|
196
196
|
it "returns the correct values when the unit system is Fitgem::ApiUnitSystem.US" do
|
197
197
|
@client.api_unit_system = Fitgem::ApiUnitSystem.US
|
198
|
-
@client.label_for_measurement(:duration, false).
|
199
|
-
@client.label_for_measurement(:distance, false).
|
200
|
-
@client.label_for_measurement(:elevation, false).
|
201
|
-
@client.label_for_measurement(:height, false).
|
202
|
-
@client.label_for_measurement(:weight, false).
|
203
|
-
@client.label_for_measurement(:measurements, false).
|
204
|
-
@client.label_for_measurement(:liquids, false).
|
205
|
-
@client.label_for_measurement(:blood_glucose, false).
|
198
|
+
expect(@client.label_for_measurement(:duration, false)).to eq "milliseconds"
|
199
|
+
expect(@client.label_for_measurement(:distance, false)).to eq "miles"
|
200
|
+
expect(@client.label_for_measurement(:elevation, false)).to eq "feet"
|
201
|
+
expect(@client.label_for_measurement(:height, false)).to eq "inches"
|
202
|
+
expect(@client.label_for_measurement(:weight, false)).to eq "pounds"
|
203
|
+
expect(@client.label_for_measurement(:measurements, false)).to eq "inches"
|
204
|
+
expect(@client.label_for_measurement(:liquids, false)).to eq "fl oz"
|
205
|
+
expect(@client.label_for_measurement(:blood_glucose, false)).to eq "mg/dL"
|
206
206
|
end
|
207
207
|
|
208
208
|
it "returns the correct values when the unit system is Fitgem::ApiUnitSystem.UK" do
|
209
209
|
@client.api_unit_system = Fitgem::ApiUnitSystem.UK
|
210
|
-
@client.label_for_measurement(:duration, false).
|
211
|
-
@client.label_for_measurement(:distance, false).
|
212
|
-
@client.label_for_measurement(:elevation, false).
|
213
|
-
@client.label_for_measurement(:height, false).
|
214
|
-
@client.label_for_measurement(:weight, false).
|
215
|
-
@client.label_for_measurement(:measurements, false).
|
216
|
-
@client.label_for_measurement(:liquids, false).
|
217
|
-
@client.label_for_measurement(:blood_glucose, false).
|
210
|
+
expect(@client.label_for_measurement(:duration, false)).to eq "milliseconds"
|
211
|
+
expect(@client.label_for_measurement(:distance, false)).to eq "kilometers"
|
212
|
+
expect(@client.label_for_measurement(:elevation, false)).to eq "meters"
|
213
|
+
expect(@client.label_for_measurement(:height, false)).to eq "centimeters"
|
214
|
+
expect(@client.label_for_measurement(:weight, false)).to eq "stone"
|
215
|
+
expect(@client.label_for_measurement(:measurements, false)).to eq "centimeters"
|
216
|
+
expect(@client.label_for_measurement(:liquids, false)).to eq "mL"
|
217
|
+
expect(@client.label_for_measurement(:blood_glucose, false)).to eq "mmol/l"
|
218
218
|
end
|
219
219
|
|
220
220
|
it "returns the correct values when the unit system is Fitgem::ApiUnitSystem.METRIC" do
|
221
221
|
@client.api_unit_system = Fitgem::ApiUnitSystem.METRIC
|
222
|
-
@client.label_for_measurement(:duration, false).
|
223
|
-
@client.label_for_measurement(:distance, false).
|
224
|
-
@client.label_for_measurement(:elevation, false).
|
225
|
-
@client.label_for_measurement(:height, false).
|
226
|
-
@client.label_for_measurement(:weight, false).
|
227
|
-
@client.label_for_measurement(:measurements, false).
|
228
|
-
@client.label_for_measurement(:liquids, false).
|
229
|
-
@client.label_for_measurement(:blood_glucose, false).
|
222
|
+
expect(@client.label_for_measurement(:duration, false)).to eq "milliseconds"
|
223
|
+
expect(@client.label_for_measurement(:distance, false)).to eq "kilometers"
|
224
|
+
expect(@client.label_for_measurement(:elevation, false)).to eq "meters"
|
225
|
+
expect(@client.label_for_measurement(:height, false)).to eq "centimeters"
|
226
|
+
expect(@client.label_for_measurement(:weight, false)).to eq "kilograms"
|
227
|
+
expect(@client.label_for_measurement(:measurements, false)).to eq "centimeters"
|
228
|
+
expect(@client.label_for_measurement(:liquids, false)).to eq "mL"
|
229
|
+
expect(@client.label_for_measurement(:blood_glucose, false)).to eq "mmol/l"
|
230
230
|
end
|
231
231
|
|
232
232
|
context "when respecting the user's unit measurement preferences" do
|
233
233
|
before(:each) do
|
234
|
-
@client.
|
235
|
-
@client.
|
234
|
+
allow(@client).to receive(:connected?).and_return(true)
|
235
|
+
allow(@client).to receive(:user_info).and_return({"user" => {"distanceUnit"=>"en_GB", "glucoseUnit"=>"en_GB", "heightUnit"=>"en_GB", "waterUnit"=>"METRIC", "weightUnit"=>"en_GB"}})
|
236
236
|
end
|
237
237
|
|
238
238
|
it "returns the correct overridden measurement label" do
|
239
239
|
@client.api_unit_system = Fitgem::ApiUnitSystem.US
|
240
|
-
@client.label_for_measurement(:distance).
|
240
|
+
expect(@client.label_for_measurement(:distance)).to eq "kilometers"
|
241
241
|
end
|
242
242
|
end
|
243
243
|
end
|
@@ -8,18 +8,18 @@ describe Fitgem::Client do
|
|
8
8
|
|
9
9
|
describe "#subscriptions" do
|
10
10
|
before(:each) do
|
11
|
-
@client.
|
11
|
+
allow(@client).to receive(:get)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "calls #make_headers to create the headers for the API call" do
|
15
15
|
opts = { :subscriber_id => "5555", :type => :all }
|
16
|
-
@client.
|
16
|
+
expect(@client).to receive(:make_headers).with({:type=>:all, :subscriber_id=>"5555"})
|
17
17
|
@client.subscriptions(opts)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "calls #get with the correct url and headers" do
|
21
21
|
opts = { :subscriber_id => "5555", :type => :all }
|
22
|
-
@client.
|
22
|
+
expect(@client).to receive(:get).with("/user/-/apiSubscriptions.json", {"X-Fitbit-Subscriber-Id"=>"5555"})
|
23
23
|
@client.subscriptions(opts)
|
24
24
|
end
|
25
25
|
end
|
@@ -27,68 +27,68 @@ describe Fitgem::Client do
|
|
27
27
|
describe "#create_subscription" do
|
28
28
|
before(:each) do
|
29
29
|
@resp = OpenStruct.new
|
30
|
-
@client.
|
30
|
+
allow(@client).to receive(:raw_post).and_return(@resp)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "adds the :use_subscription_id flag and calls #make_headers" do
|
34
34
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320" }
|
35
|
-
@client.
|
35
|
+
expect(@client).to receive(:make_headers).with({ :subscriber_id => "5555", :type => :all, :subscription_id => "320"})
|
36
36
|
@client.create_subscription(opts)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "calls #raw_post with the correct url and headers for :all collection type" do
|
40
40
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
41
|
-
@client.
|
41
|
+
expect(@client).to receive(:raw_post).once.with("/user/-/apiSubscriptions/320.json", "", {"X-Fitbit-Subscriber-Id"=>"5555"})
|
42
42
|
@client.create_subscription(opts)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "calls #raw_post with the correct url and headers for :sleep collection type" do
|
46
46
|
opts = { :subscriber_id => "5555", :type => :sleep, :subscription_id => "320", :use_subscription_id => true }
|
47
|
-
@client.
|
47
|
+
expect(@client).to receive(:raw_post).once.with("/user/-/sleep/apiSubscriptions/320.json", "", {"X-Fitbit-Subscriber-Id"=>"5555"})
|
48
48
|
@client.create_subscription(opts)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "calls #extract_response_body to get the JSON body" do
|
52
52
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
53
|
-
@client.
|
53
|
+
expect(@client).to receive(:extract_response_body)
|
54
54
|
@client.create_subscription(opts)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns the code and the JSON body in an array" do
|
58
58
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
59
|
-
@resp.
|
60
|
-
@client.create_subscription(opts).
|
59
|
+
expect(@resp).to receive(:code)
|
60
|
+
expect(@client.create_subscription(opts)).to be_a(Array)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe "#remove_subscription" do
|
65
65
|
before(:each) do
|
66
66
|
@resp = OpenStruct.new
|
67
|
-
@client.
|
67
|
+
allow(@client).to receive(:raw_delete).and_return(@resp)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "adds the :use_subscription_id flag and calls #make_headers" do
|
71
71
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320" }
|
72
|
-
@client.
|
72
|
+
expect(@client).to receive(:make_headers).with({ :subscriber_id => "5555", :type => :all, :subscription_id => "320" })
|
73
73
|
@client.remove_subscription(opts)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "calls #raw_delete with the correct url and headers for :all collection type" do
|
77
77
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
78
|
-
@client.
|
78
|
+
expect(@client).to receive(:raw_delete).once.with("/user/-/apiSubscriptions/320.json", {"X-Fitbit-Subscriber-Id"=>"5555"})
|
79
79
|
@client.remove_subscription(opts)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "calls #extract_response_body to get the JSON body" do
|
83
83
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
84
|
-
@client.
|
84
|
+
expect(@client).to receive(:extract_response_body)
|
85
85
|
@client.remove_subscription(opts)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "returns the code and the JSON body in an array" do
|
89
89
|
opts = { :subscriber_id => "5555", :type => :all, :subscription_id => "320", :use_subscription_id => true }
|
90
|
-
@resp.
|
91
|
-
@client.remove_subscription(opts).
|
90
|
+
expect(@resp).to receive(:code)
|
91
|
+
expect(@client.remove_subscription(opts)).to be_a(Array)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -111,40 +111,40 @@ describe Fitgem::Client do
|
|
111
111
|
it "adds the subscriber id header" do
|
112
112
|
opts = { :subscriber_id => '5555', :subscription_id => '320-activity' }
|
113
113
|
headers = @client.send(:make_headers, opts)
|
114
|
-
headers.size.
|
115
|
-
headers['X-Fitbit-Subscriber-Id'].
|
114
|
+
expect(headers.size).to eq 1
|
115
|
+
expect(headers['X-Fitbit-Subscriber-Id']).to eq "5555"
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "#make_subscription_url" do
|
120
120
|
it "creates the correct URL when no specific subscription id is used" do
|
121
121
|
opts = { :subscription_id => "320", :type => :all }
|
122
|
-
@client.send(:make_subscription_url, opts).
|
122
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/apiSubscriptions.json"
|
123
123
|
end
|
124
124
|
|
125
125
|
it "creates the correct URL for :all collection types" do
|
126
126
|
opts = { :subscription_id => "320", :type => :all, :use_subscription_id => true }
|
127
|
-
@client.send(:make_subscription_url, opts).
|
127
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/apiSubscriptions/320.json"
|
128
128
|
end
|
129
129
|
|
130
130
|
it "creates the correct URL for the :sleep collection type" do
|
131
131
|
opts = { :subscription_id => "320", :type => :sleep, :use_subscription_id => true }
|
132
|
-
@client.send(:make_subscription_url, opts).
|
132
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/sleep/apiSubscriptions/320.json"
|
133
133
|
end
|
134
134
|
|
135
135
|
it "creates the correct URL for the :body collection type" do
|
136
136
|
opts = { :subscription_id => "320", :type => :body, :use_subscription_id => true }
|
137
|
-
@client.send(:make_subscription_url, opts).
|
137
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/body/apiSubscriptions/320.json"
|
138
138
|
end
|
139
139
|
|
140
140
|
it "creates the correct URL for the :activities collection type" do
|
141
141
|
opts = { :subscription_id => "320", :type => :activities, :use_subscription_id => true }
|
142
|
-
@client.send(:make_subscription_url, opts).
|
142
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/activities/apiSubscriptions/320.json"
|
143
143
|
end
|
144
144
|
|
145
145
|
it "creates the correct URL for the :foods collection type" do
|
146
146
|
opts = { :subscription_id => "320", :type => :foods, :use_subscription_id => true }
|
147
|
-
@client.send(:make_subscription_url, opts).
|
147
|
+
expect(@client.send(:make_subscription_url, opts)).to eq "/user/-/foods/apiSubscriptions/320.json"
|
148
148
|
end
|
149
149
|
|
150
150
|
it "validates the supplied subscription type" do
|
@@ -155,19 +155,19 @@ describe Fitgem::Client do
|
|
155
155
|
expect { @client.send(:make_subscription_url, opts) }.to raise_error Fitgem::InvalidArgumentError
|
156
156
|
|
157
157
|
opts[:type] = :all
|
158
|
-
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
158
|
+
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
159
159
|
|
160
160
|
opts[:type] = :activities
|
161
|
-
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
161
|
+
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
162
162
|
|
163
163
|
opts[:type] = :sleep
|
164
|
-
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
164
|
+
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
165
165
|
|
166
166
|
opts[:type] = :foods
|
167
|
-
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
167
|
+
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
168
168
|
|
169
169
|
opts[:type] = :body
|
170
|
-
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
170
|
+
expect { @client.send(:make_subscription_url, opts) }.not_to raise_error
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
data/spec/fitgem_spec.rb
CHANGED
@@ -3,62 +3,34 @@ require 'spec_helper'
|
|
3
3
|
describe Fitgem do
|
4
4
|
before do
|
5
5
|
@client = Fitgem::Client.new({
|
6
|
-
:consumer_key => '12345',
|
6
|
+
:consumer_key => '12345',
|
7
7
|
:consumer_secret => '67890'
|
8
8
|
})
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'global settings' do
|
12
12
|
it 'should expose the api_version' do
|
13
|
-
@client.api_version.
|
13
|
+
expect(@client.api_version).to eq "1"
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should all clients to set a new api version' do
|
17
17
|
@client.api_version = "2"
|
18
|
-
@client.api_version.
|
18
|
+
expect(@client.api_version).to eq "2"
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should default to the US unit system' do
|
22
|
-
@client.api_unit_system.
|
22
|
+
expect(@client.api_unit_system).to eq Fitgem::ApiUnitSystem.US
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should allow the unit system to be set to other types' do
|
26
26
|
@client.api_unit_system = Fitgem::ApiUnitSystem.UK
|
27
|
-
@client.api_unit_system.
|
27
|
+
expect(@client.api_unit_system).to eq Fitgem::ApiUnitSystem.UK
|
28
28
|
@client.api_unit_system = Fitgem::ApiUnitSystem.METRIC
|
29
|
-
@client.api_unit_system.
|
29
|
+
expect(@client.api_unit_system).to eq Fitgem::ApiUnitSystem.METRIC
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should default to a user id of \'-\', the currently-logged in user' do
|
33
|
-
@client.user_id.
|
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
|
-
|
33
|
+
expect(@client.user_id).to eq '-'
|
62
34
|
end
|
63
35
|
end
|
64
36
|
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.
|
4
|
+
version: 0.10.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: 2014-
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,8 +89,8 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- .gitignore
|
92
|
-
- .yardopts
|
93
92
|
- .travis.yml
|
93
|
+
- .yardopts
|
94
94
|
- Gemfile
|
95
95
|
- Guardfile
|
96
96
|
- LICENSE
|
@@ -99,10 +99,10 @@ files:
|
|
99
99
|
- changelog.md
|
100
100
|
- fitgem.gemspec
|
101
101
|
- lib/fitgem.rb
|
102
|
-
- lib/fitgem/version.rb
|
103
102
|
- lib/fitgem/activities.rb
|
104
103
|
- lib/fitgem/alarms.rb
|
105
104
|
- lib/fitgem/badges.rb
|
105
|
+
- lib/fitgem/blood_pressure.rb
|
106
106
|
- lib/fitgem/body_measurements.rb
|
107
107
|
- lib/fitgem/client.rb
|
108
108
|
- lib/fitgem/devices.rb
|
@@ -110,21 +110,21 @@ files:
|
|
110
110
|
- lib/fitgem/food_form.rb
|
111
111
|
- lib/fitgem/foods.rb
|
112
112
|
- lib/fitgem/friends.rb
|
113
|
+
- lib/fitgem/glucose.rb
|
114
|
+
- lib/fitgem/heart_rate.rb
|
113
115
|
- lib/fitgem/helpers.rb
|
114
116
|
- lib/fitgem/notifications.rb
|
115
117
|
- lib/fitgem/sleep.rb
|
116
118
|
- lib/fitgem/time_range.rb
|
117
119
|
- lib/fitgem/units.rb
|
118
120
|
- lib/fitgem/users.rb
|
121
|
+
- lib/fitgem/version.rb
|
119
122
|
- lib/fitgem/water.rb
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
123
|
+
- spec/fitgem_constructor_spec.rb
|
124
|
+
- spec/fitgem_helper_spec.rb
|
125
|
+
- spec/fitgem_notifications_spec.rb
|
123
126
|
- spec/fitgem_spec.rb
|
124
127
|
- spec/spec_helper.rb
|
125
|
-
- spec/fitgem_notifications_spec.rb
|
126
|
-
- spec/fitgem_helper_spec.rb
|
127
|
-
- spec/fitgem_constructor_spec.rb
|
128
128
|
homepage: http://github.com/whazzmaster/fitgem
|
129
129
|
licenses: []
|
130
130
|
metadata: {}
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project: fitgem
|
147
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.2.2
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: OAuth client library to the data on fitbit.com
|