nike_v2 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README.md +21 -0
- data/lib/nike_v2/activities.rb +8 -2
- data/lib/nike_v2/version.rb +1 -1
- data/spec/fixtures/nike_api_cassettes/activities.yml +79 -3
- data/spec/nike_v2/acitivites_spec.rb +6 -0
- metadata +1 -1
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,27 @@ person.activities.total_fuel #fetches the metrics if they aren't already loaded
|
|
49
49
|
=> 394
|
50
50
|
```
|
51
51
|
|
52
|
+
As of version 0.3.0 you can cache calls to the Nike+ V2 api. We use the ApiCache (https://github.com/mloughran/api_cache) gem for this and all options in cache directive are passed to the api_cache config. Setting config.cache false disables the cache
|
53
|
+
``` ruby
|
54
|
+
# config/initializers/nike_v2.rb
|
55
|
+
NikeV2.configure do |config|
|
56
|
+
config.cache = {
|
57
|
+
:cache => 3600
|
58
|
+
}
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
Possible options:
|
63
|
+
```
|
64
|
+
{
|
65
|
+
:cache => 600, # 10 minutes After this time fetch new data
|
66
|
+
:valid => 86400, # 1 day Maximum time to use old data
|
67
|
+
# :forever is a valid option
|
68
|
+
:period => 60, # 1 minute Maximum frequency to call API
|
69
|
+
:timeout => 5 # 5 seconds API response timeout
|
70
|
+
:fail => # Value returned instead of exception on failure
|
71
|
+
}
|
72
|
+
```
|
52
73
|
## Making it Better
|
53
74
|
|
54
75
|
* Fork the project.
|
data/lib/nike_v2/activities.rb
CHANGED
@@ -42,15 +42,21 @@ module NikeV2
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def fetch_more
|
45
|
-
unless self.paging['next'].
|
45
|
+
unless self.paging['next'].nil? || self.paging['next'] == ''
|
46
46
|
fetch_and_build_activities
|
47
47
|
end
|
48
|
+
self
|
48
49
|
end
|
49
50
|
|
50
51
|
def fetch_all
|
51
|
-
until self.paging['next'].
|
52
|
+
until (self.paging['next'].nil? || self.paging['next'] == '') do
|
52
53
|
fetch_and_build_activities
|
53
54
|
end
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def paging
|
59
|
+
@paging ||= ''
|
54
60
|
end
|
55
61
|
|
56
62
|
private
|
data/lib/nike_v2/version.rb
CHANGED
@@ -30,7 +30,7 @@ http_interactions:
|
|
30
30
|
- keep-alive
|
31
31
|
body:
|
32
32
|
encoding: US-ASCII
|
33
|
-
string: ! '{"data":[{"activityId":"91b501dc-4a38-44aa-b537-6095418713d8","calories":2475,"fuel":7500,"distance":19.665315,"steps":24975,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-26T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[],"metrics":[]},{"activityId":"8554c3bb-f985-4700-a52d-6235475a10f0","calories":1848,"fuel":5555,"distance":14.6834352,"steps":18648,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-25T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"b7511567-9414-429a-9b7b-40ebc15af985","calories":396,"fuel":1200,"distance":3.1464504,"steps":3996,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-24T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"b87bb409-a618-47ee-a75e-1bb5f8daf9a6","calories":300,"fuel":900,"distance":2.3621999999999996,"steps":3000,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-23T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"6c6eb89c-fa42-49a6-8b04-2596297a7c3a","calories":200,"fuel":600,"distance":1.5748,"steps":2000,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-22T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]}],"paging":{"next":"/me/sport/activities?access_token=
|
33
|
+
string: ! '{"data":[{"activityId":"91b501dc-4a38-44aa-b537-6095418713d8","calories":2475,"fuel":7500,"distance":19.665315,"steps":24975,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-26T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[],"metrics":[]},{"activityId":"8554c3bb-f985-4700-a52d-6235475a10f0","calories":1848,"fuel":5555,"distance":14.6834352,"steps":18648,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-25T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"b7511567-9414-429a-9b7b-40ebc15af985","calories":396,"fuel":1200,"distance":3.1464504,"steps":3996,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-24T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"b87bb409-a618-47ee-a75e-1bb5f8daf9a6","calories":300,"fuel":900,"distance":2.3621999999999996,"steps":3000,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-23T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]},{"activityId":"6c6eb89c-fa42-49a6-8b04-2596297a7c3a","calories":200,"fuel":600,"distance":1.5748,"steps":2000,"duration":"0:01:00.0000","activityType":"ALL_DAY","startTime":"2012-02-22T08:00:00Z","activityTimeZone":"America/Los_Angeles","status":"COMPLETE","deviceType":"FUELBAND","tags":[],"streams":[]}],"paging":{"next":"/me/sport/activities?access_token=foobar&offset=6&count=5","previous":null}}'
|
34
34
|
http_version:
|
35
35
|
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
36
|
- request:
|
@@ -67,7 +67,7 @@ http_interactions:
|
|
67
67
|
"calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659,
|
68
68
|
"duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-02-26T07:00:00Z",
|
69
69
|
"activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType":
|
70
|
-
"FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?count=1&access_token=
|
70
|
+
"FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?count=1&access_token=foobar&offset=2"
|
71
71
|
} }'
|
72
72
|
http_version:
|
73
73
|
recorded_at: Wed, 27 Feb 2013 16:18:07 GMT
|
@@ -105,7 +105,7 @@ http_interactions:
|
|
105
105
|
"calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659,
|
106
106
|
"duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-01-01T07:00:00Z",
|
107
107
|
"activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType":
|
108
|
-
"FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?startDate=2013-01-01&access_token=
|
108
|
+
"FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?startDate=2013-01-01&access_token=foobar&offset=2"
|
109
109
|
} }'
|
110
110
|
http_version:
|
111
111
|
recorded_at: Wed, 27 Feb 2013 16:18:07 GMT
|
@@ -259,4 +259,80 @@ http_interactions:
|
|
259
259
|
"4", "25", "22", "19", "11", "2", "23" ] } ] }'
|
260
260
|
http_version:
|
261
261
|
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
262
|
+
- request:
|
263
|
+
method: get
|
264
|
+
uri: https://api.nike.com/me/sport/activities?access_token=foobar&count=1&offset=2
|
265
|
+
body:
|
266
|
+
encoding: US-ASCII
|
267
|
+
string: ''
|
268
|
+
headers:
|
269
|
+
Accept:
|
270
|
+
- application/json
|
271
|
+
Appid:
|
272
|
+
- nike
|
273
|
+
response:
|
274
|
+
status:
|
275
|
+
code: 200
|
276
|
+
message: OK
|
277
|
+
headers:
|
278
|
+
Content-Type:
|
279
|
+
- application/json;charset=UTF-8
|
280
|
+
Date:
|
281
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
282
|
+
Server:
|
283
|
+
- Apache
|
284
|
+
X-Swooshlet:
|
285
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
286
|
+
Content-Length:
|
287
|
+
- '340'
|
288
|
+
Connection:
|
289
|
+
- keep-alive
|
290
|
+
body:
|
291
|
+
encoding: US-ASCII
|
292
|
+
string: ! '{ "data": [ { "activityId": "c3337642-72db-41f7-b4a2-4da4600dfc91",
|
293
|
+
"calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659,
|
294
|
+
"duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-02-26T07:00:00Z",
|
295
|
+
"activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType":
|
296
|
+
"FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?count=1&access_token=foobar&offset=3"
|
297
|
+
} }'
|
298
|
+
http_version:
|
299
|
+
recorded_at: Thu, 14 Mar 2013 00:45:14 GMT
|
300
|
+
- request:
|
301
|
+
method: get
|
302
|
+
uri: https://api.nike.com/me/sport/activities?access_token=foobar&count=1&offset=3
|
303
|
+
body:
|
304
|
+
encoding: US-ASCII
|
305
|
+
string: ''
|
306
|
+
headers:
|
307
|
+
Accept:
|
308
|
+
- application/json
|
309
|
+
Appid:
|
310
|
+
- nike
|
311
|
+
response:
|
312
|
+
status:
|
313
|
+
code: 200
|
314
|
+
message: OK
|
315
|
+
headers:
|
316
|
+
Content-Type:
|
317
|
+
- application/json;charset=UTF-8
|
318
|
+
Date:
|
319
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
320
|
+
Server:
|
321
|
+
- Apache
|
322
|
+
X-Swooshlet:
|
323
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
324
|
+
Content-Length:
|
325
|
+
- '340'
|
326
|
+
Connection:
|
327
|
+
- keep-alive
|
328
|
+
body:
|
329
|
+
encoding: US-ASCII
|
330
|
+
string: ! '{ "data": [ { "activityId": "c3337642-72db-41f7-b4a2-4da4600dfc92",
|
331
|
+
"calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659,
|
332
|
+
"duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-02-26T07:00:00Z",
|
333
|
+
"activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType":
|
334
|
+
"FUELBAND", "tags": [], "metrics": [] } ], "paging": {
|
335
|
+
} }'
|
336
|
+
http_version:
|
337
|
+
recorded_at: Thu, 14 Mar 2013 00:45:14 GMT
|
262
338
|
recorded_with: VCR 2.4.0
|
@@ -19,6 +19,12 @@ describe NikeV2::Activities do
|
|
19
19
|
person.activities(:count => 1).length.should == 1
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should fetch_all and return an array of Nike::Activity' do
|
23
|
+
(a = person.activities(:count => 1).fetch_all).should be_kind_of(NikeV2::Activities)
|
24
|
+
a.first.should be_kind_of(NikeV2::Activity)
|
25
|
+
a.length.should == 3
|
26
|
+
end
|
27
|
+
|
22
28
|
it 'should accept the start_date parameter, camelcase it and return an array of Nike::Activity' do
|
23
29
|
pending
|
24
30
|
# person.activities(:count => 1).should be_kind_of(NikeV2::Activities)
|