nike_v2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +2 -0
- data/README.md +62 -0
- data/Rakefile +13 -0
- data/lib/ext/core_ext.rb +9 -0
- data/lib/nike_v2/activities.rb +25 -0
- data/lib/nike_v2/activity.rb +28 -0
- data/lib/nike_v2/base.rb +17 -0
- data/lib/nike_v2/gps_data.rb +17 -0
- data/lib/nike_v2/person.rb +18 -0
- data/lib/nike_v2/resource.rb +40 -0
- data/lib/nike_v2/summary.rb +14 -0
- data/lib/nike_v2.rb +14 -0
- data/nike_v2.gemspec +26 -0
- data/spec/factories/activity_factory.rb +7 -0
- data/spec/factories/person_factory.rb +6 -0
- data/spec/fixtures/nike_api_cassettes/activities.yml +36 -0
- data/spec/fixtures/nike_api_cassettes/activity.yml +36 -0
- data/spec/fixtures/nike_api_cassettes/gps_data.yml +36 -0
- data/spec/fixtures/nike_api_cassettes/summary.yml +36 -0
- data/spec/nike_v2/acitivites_spec.rb +16 -0
- data/spec/nike_v2/activity_spec.rb +15 -0
- data/spec/nike_v2/base_spec.rb +11 -0
- data/spec/nike_v2/gps_data_spec.rb +15 -0
- data/spec/nike_v2/person_spec.rb +22 -0
- data/spec/nike_v2/resource_spec.rb +13 -0
- data/spec/nike_v2/summary_spec.rb +16 -0
- data/spec/spec_helper.rb +16 -0
- metadata +183 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
NikeV2
|
2
|
+
====================
|
3
|
+
|
4
|
+
![Build Status](https://travis-ci.org/fuelxc/nike_v2.png)
|
5
|
+
|
6
|
+
Learn more about the Nike+ API at [https://developer.nike.com/](https://developer.nike.com/).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
``` bash
|
10
|
+
gem install nike_v2
|
11
|
+
```
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
In order to utilize the Nike+ API in its current state, you'll need to do the following:
|
16
|
+
* Sign up for a Nike+ account at [http://nikeplus.nike.com/plus/](http://nikeplus.nike.com/plus/)
|
17
|
+
* Log into the developer portal and generate an access token at [https://developer.nike.com/](https://developer.nike.com/)
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
require 'nike_v2'
|
21
|
+
|
22
|
+
# Initialize a person
|
23
|
+
person = NikeV2::Person.new(access_token: 'a1b2c3d4')
|
24
|
+
# Fetch persons summary
|
25
|
+
person.summary
|
26
|
+
# Fetch a persons activities
|
27
|
+
person.activities
|
28
|
+
# Load more data for an activity
|
29
|
+
activity = person.activities.first
|
30
|
+
activity.fetch_data
|
31
|
+
# Fetch GPS Data for an activity
|
32
|
+
activity.gps_data
|
33
|
+
```
|
34
|
+
|
35
|
+
## Making it Better
|
36
|
+
|
37
|
+
* Fork the project.
|
38
|
+
* Make your feature addition or bug fix in a new topic branch within your repo.
|
39
|
+
* Add specs for any new or modified functionality.
|
40
|
+
* Commit and push your changes to Github
|
41
|
+
* Send a pull request
|
42
|
+
|
43
|
+
## Inspiration
|
44
|
+
I used Kevin Thompson's NikeApi gem as inspiration. Find it here: https://github.com/kevinthompson/nike_api
|
45
|
+
|
46
|
+
|
47
|
+
## Copyright
|
48
|
+
|
49
|
+
Copyright (c) 2013 SmashTank Apps, LLC.
|
50
|
+
|
51
|
+
This program is free software: you can redistribute it and/or modify
|
52
|
+
it under the terms of the GNU General Public License as published by
|
53
|
+
the Free Software Foundation, either version 3 of the License, or
|
54
|
+
(at your option) any later version.
|
55
|
+
|
56
|
+
This program is distributed in the hope that it will be useful,
|
57
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
58
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
59
|
+
GNU General Public License for more details.
|
60
|
+
|
61
|
+
You should have received a copy of the GNU General Public License
|
62
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
RSpec::Core::RakeTask.new(:spec)
|
3
|
+
task default: :spec
|
4
|
+
|
5
|
+
require 'rdoc/task'
|
6
|
+
Rake::RDocTask.new do |rdoc|
|
7
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
8
|
+
|
9
|
+
rdoc.rdoc_dir = 'rdoc'
|
10
|
+
rdoc.title = "nike_v2 #{version}"
|
11
|
+
rdoc.rdoc_files.include('README*')
|
12
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
13
|
+
end
|
data/lib/ext/core_ext.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'enumerator'
|
2
|
+
module NikeV2
|
3
|
+
class Activities < Resource
|
4
|
+
include Enumerable
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :@activities_array, :[]=, :<<, :[], :count, :length, :each
|
8
|
+
def_delegator :@person, :access_token
|
9
|
+
|
10
|
+
API_URL = '/me/sport/activities'
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
raise "#{self.class} requires a person." unless attributes.keys.include?(:person)
|
14
|
+
set_attributes(attributes)
|
15
|
+
@activities_array = []
|
16
|
+
|
17
|
+
#TODO: make it pass blocks
|
18
|
+
activities = fetch_data
|
19
|
+
activities.delete('data').each do |data|
|
20
|
+
self << NikeV2::Activity.new({:person => self}.merge(data))
|
21
|
+
end
|
22
|
+
super(activities)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class Activity < Resource
|
3
|
+
extend Forwardable
|
4
|
+
def_delegator :@person, :access_token
|
5
|
+
|
6
|
+
API_URL = '/me/sport/activities'
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
raise "#{self.class} requires s person." unless attributes.keys.include?(:person)
|
10
|
+
raise "#{self.class} requires an activityId." unless attributes.keys.include?('activityId')
|
11
|
+
super(attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
def gps_data
|
15
|
+
@gps_data ||= NikeV2::GpsData.new(:activity => self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_data
|
19
|
+
set_attributes(fetch_data)
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def api_url
|
25
|
+
API_URL + "/#{self.activity_id}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/nike_v2/base.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class Base
|
3
|
+
def initialize(attributes={})
|
4
|
+
@created_at = attributes.delete('created_at')
|
5
|
+
set_attributes(attributes)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def set_attributes(attributes)
|
10
|
+
attributes.each do |(attr, val)|
|
11
|
+
attr = attr.to_s.underscore
|
12
|
+
instance_variable_set("@#{attr}", val)
|
13
|
+
instance_eval "def #{attr}() @#{attr} end"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class GpsData < Resource
|
3
|
+
extend Forwardable
|
4
|
+
def_delegator :@activity, :access_token
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
raise "#{self.class} requires an activity." unless attributes.keys.include?(:activity)
|
8
|
+
set_attributes(attributes)
|
9
|
+
super(fetch_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def api_url
|
14
|
+
self.activity.send(:api_url) + '/gps'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class Person < Resource
|
3
|
+
|
4
|
+
def initialize(attributes = {})
|
5
|
+
raise "#{self.class} requires an access_token." unless attributes.keys.include?(:access_token)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def summary
|
10
|
+
@summary ||= NikeV2::Summary.new(:person => self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def activities
|
14
|
+
@activities ||= NikeV2::Activities.new(:person => self)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class Resource < Base
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
base_uri 'https://api.nike.com'
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
super(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch_data
|
12
|
+
get(api_url).parsed_response
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(*args, &block)
|
16
|
+
unless has_options?(args)
|
17
|
+
query = { 'access_token' => access_token }
|
18
|
+
headers = { 'Accept' => 'application/json', 'appid' => app_id }
|
19
|
+
options = { query: query, headers: headers }
|
20
|
+
args << options
|
21
|
+
end
|
22
|
+
self.class.get(*args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def app_id
|
28
|
+
#TODO: make this a config yaml
|
29
|
+
'nike'
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_options?(args)
|
33
|
+
args.last.class.is_a?(Hash) && args.last.keys.any?{ |key| %w[basic_auth body headers no_follow query].include?(key) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_url
|
37
|
+
self.class.const_get('API_URL')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module NikeV2
|
2
|
+
class Summary < Resource
|
3
|
+
extend Forwardable
|
4
|
+
def_delegator :@person, :access_token
|
5
|
+
|
6
|
+
API_URL = '/me/sport'
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
raise "#{self.class} requires a person." unless attributes.keys.include?(:person)
|
10
|
+
set_attributes(attributes)
|
11
|
+
super(fetch_data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/nike_v2.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'ext/core_ext'
|
4
|
+
require 'nike_v2/base'
|
5
|
+
require 'nike_v2/resource'
|
6
|
+
require 'nike_v2/person'
|
7
|
+
require 'nike_v2/activities'
|
8
|
+
require 'nike_v2/activity'
|
9
|
+
require 'nike_v2/summary'
|
10
|
+
require 'nike_v2/gps_data'
|
11
|
+
|
12
|
+
module NikeV2
|
13
|
+
VERSION = '0.1.0'
|
14
|
+
end
|
data/nike_v2.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'nike_v2'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'nike_v2'
|
7
|
+
s.version = NikeV2::VERSION
|
8
|
+
s.authors = ["Eric Harrison"]
|
9
|
+
s.email = ["eric@rubynooby.com"]
|
10
|
+
s.homepage = 'https://github.com/fuelxc/nike_v2'
|
11
|
+
s.summary = 'Nike+ API V2 Gem'
|
12
|
+
s.description = 'Nike+ API V2 Gem'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'httparty', '>= 0.10.0'
|
20
|
+
|
21
|
+
s.add_development_dependency 'factory_girl', '~> 4.2.0'
|
22
|
+
s.add_development_dependency 'rake', '~> 10.0.3'
|
23
|
+
s.add_development_dependency 'rspec', '~> 2.12.0'
|
24
|
+
s.add_development_dependency 'vcr', '~> 2.4.0'
|
25
|
+
s.add_development_dependency 'webmock', '~> 1.9.0'
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.nike.com/me/sport/activities?access_token=foobar
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Appid:
|
13
|
+
- nike
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Date:
|
22
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Swooshlet:
|
26
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
27
|
+
Content-Length:
|
28
|
+
- '340'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
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":[]},{"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=68d1b7f5ec3e6a1ad3b349cd73983b34&offset=6&count=5","previous":null}}'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.nike.com/me/sport/activities/91b501dc-4a38-44aa-b537-6095418713d8?access_token=foobar
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Appid:
|
13
|
+
- nike
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Date:
|
22
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Swooshlet:
|
26
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
27
|
+
Content-Length:
|
28
|
+
- '340'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ! '{ "activityId": "91b501dc-4a38-44aa-b537-6095418713d8", "calories": 257, "fuel": 662, "distance": 3.1317999362945557, "steps": 10, "duration": "0:14:31.000", "activityType": "RUN", "startTime": "2011-08-11T02:44:39Z", "activityTimeZone": "GMT-08:00", "status": "COMPLETE", "deviceType": "SPORTWATCH", "tags": [ { "tagType": "NOTE", "value": "text string" }, { "tagType": "COURT", "value": "DUNK" }, { "tagType": "TERRAIN", "value": "TRAIL" }, { "tagType": "EMOTION", "value": "HAPPY" }, { "tagType": "SHOES", "value": "AirMax" }, { "tagType": "WEATHER", "value": "RAINY" } ], "metrics": [ { "intervalMetric": 10, "intervalUnit": "SEC", "metricType": "DISTANCE", "values": [ 0.0299, 0.0562, 0.0794, 0.114, 3.0967, 3.1296 ] } ] }'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.nike.com/me/sport/activities/91b501dc-4a38-44aa-b537-6095418713d8/gps?access_token=foobar
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Appid:
|
13
|
+
- nike
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Date:
|
22
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Swooshlet:
|
26
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
27
|
+
Content-Length:
|
28
|
+
- '340'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ! '{ "elevationLoss": 54.089367, "elevationGain": 57.98948, "elevationMin": 52.071926, "elevationMax": 71.568146, "intervalMetric": 10, "intervalUnit": "SEC", "wayPoints": [ { "latitude": 45.508057, "longitude": -122.83315, "elevation": 53.09316 }, { "latitude": 45.508034, "longitude": -122.83313, "elevation": 53.151 }, { "latitude": 45.50786, "longitude": -122.832954, "elevation": 53.86401 }, { "latitude": 45.508175, "longitude": -122.833206, "elevation": 56.81296 }, { "latitude": 45.508156, "longitude": -122.83318, "elevation": 56.870304 }, { "latitude": 45.508133, "longitude": -122.83316, "elevation": 56.99327 } ] }'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.nike.com/me/sport?access_token=foobar
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Appid:
|
13
|
+
- nike
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Date:
|
22
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Swooshlet:
|
26
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
27
|
+
Content-Length:
|
28
|
+
- '340'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ! '{"experienceTypes":["FUELBAND"],"summaries":[{"experienceType":"ALL","records":{"lifetimeFuel":142358}},{"experienceType":"FUELBAND","records":{"dailyGoalTargetValue":4000.0,"currentStreak":0,"totalDailyGoalsAchieved":16,"lifetimeAverageFuelDay":3552,"lifetimeAverageFuelWeek":26149,"lifetimeAverageFuelMonth":75138,"numOfActivities":41}}]}'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Activities do
|
4
|
+
let(:person){ build(:person) }
|
5
|
+
|
6
|
+
describe 'new from person' do
|
7
|
+
before{ VCR.insert_cassette 'activities', record: :new_episodes }
|
8
|
+
after{ VCR.eject_cassette }
|
9
|
+
|
10
|
+
it 'should return an array of Nike::Activity' do
|
11
|
+
person.activities.should be_kind_of(NikeV2::Activities)
|
12
|
+
person.activities.first.should be_kind_of(NikeV2::Activity)
|
13
|
+
person.activities.length.should == 5
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Activity do
|
4
|
+
let(:activity){ build(:activity) }
|
5
|
+
|
6
|
+
describe 'fetch_data' do
|
7
|
+
before{ VCR.insert_cassette 'activity', record: :new_episodes }
|
8
|
+
after{ VCR.eject_cassette }
|
9
|
+
|
10
|
+
it 'should load the activity from the api' do
|
11
|
+
activity.load_data.should be_true
|
12
|
+
activity.calories.should == 257
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Base do
|
4
|
+
it 'should make its attributes available through accessor methods' do
|
5
|
+
base = NikeV2::Base.new(first_name: 'Foo', last_name: 'Bar')
|
6
|
+
base.should respond_to(:first_name)
|
7
|
+
base.should respond_to(:last_name)
|
8
|
+
base.first_name.should == 'Foo'
|
9
|
+
base.last_name.should == 'Bar'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Activity do
|
4
|
+
let(:activity){ build(:activity) }
|
5
|
+
|
6
|
+
describe 'reload' do
|
7
|
+
before{ VCR.insert_cassette 'gps_data', record: :new_episodes }
|
8
|
+
after{ VCR.eject_cassette }
|
9
|
+
|
10
|
+
it 'should load the activity from the api' do
|
11
|
+
activity.gps_data.should be_an_instance_of(NikeV2::GpsData)
|
12
|
+
activity.gps_data.elevation_loss.should == 54.089367
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Person do
|
4
|
+
let(:access_token){ 'bazquux' }
|
5
|
+
let(:person){ build(:person) }
|
6
|
+
|
7
|
+
describe '.new' do
|
8
|
+
context 'with an access_token attribute' do
|
9
|
+
it 'should return a NikeApi::Person object' do
|
10
|
+
person = NikeV2::Person.new(access_token: access_token)
|
11
|
+
person.should be_an_instance_of(NikeV2::Person)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without an access_token attribute' do
|
16
|
+
it 'should raise an error' do
|
17
|
+
expect{ NikeV2::Person.new }.to raise_error('NikeV2::Person requires an access_token.')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Resource do
|
4
|
+
it 'should include HTTParty' do
|
5
|
+
NikeV2::Resource.should include(HTTParty)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#base_uri' do
|
9
|
+
it 'should be set to https://api.nike.com' do
|
10
|
+
NikeV2::Resource.base_uri.should == 'https://api.nike.com'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Summary do
|
4
|
+
let(:person){ build(:person) }
|
5
|
+
|
6
|
+
describe 'new' do
|
7
|
+
before{ VCR.insert_cassette 'summary', record: :new_episodes }
|
8
|
+
after{ VCR.eject_cassette }
|
9
|
+
|
10
|
+
it 'should return a Summary of user data' do
|
11
|
+
person.summary.should be_kind_of(NikeV2::Summary)
|
12
|
+
person.summary.experience_types.include?('FUELBAND').should be_true
|
13
|
+
person.summary.summaries.length.should == 2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../lib/nike_v2'
|
2
|
+
require 'factory_girl'
|
3
|
+
require 'rspec'
|
4
|
+
require 'vcr'
|
5
|
+
require 'webmock'
|
6
|
+
|
7
|
+
FactoryGirl.find_definitions
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include FactoryGirl::Syntax::Methods
|
11
|
+
end
|
12
|
+
|
13
|
+
VCR.configure do |config|
|
14
|
+
config.cassette_library_dir = 'spec/fixtures/nike_api_cassettes'
|
15
|
+
config.hook_into :webmock
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nike_v2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Harrison
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: factory_girl
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.2.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 10.0.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.0.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.12.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.12.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: vcr
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.4.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.4.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.9.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.0
|
110
|
+
description: Nike+ API V2 Gem
|
111
|
+
email:
|
112
|
+
- eric@rubynooby.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- lib/ext/core_ext.rb
|
122
|
+
- lib/nike_v2.rb
|
123
|
+
- lib/nike_v2/activities.rb
|
124
|
+
- lib/nike_v2/activity.rb
|
125
|
+
- lib/nike_v2/base.rb
|
126
|
+
- lib/nike_v2/gps_data.rb
|
127
|
+
- lib/nike_v2/person.rb
|
128
|
+
- lib/nike_v2/resource.rb
|
129
|
+
- lib/nike_v2/summary.rb
|
130
|
+
- nike_v2.gemspec
|
131
|
+
- spec/factories/activity_factory.rb
|
132
|
+
- spec/factories/person_factory.rb
|
133
|
+
- spec/fixtures/nike_api_cassettes/activities.yml
|
134
|
+
- spec/fixtures/nike_api_cassettes/activity.yml
|
135
|
+
- spec/fixtures/nike_api_cassettes/gps_data.yml
|
136
|
+
- spec/fixtures/nike_api_cassettes/summary.yml
|
137
|
+
- spec/nike_v2/acitivites_spec.rb
|
138
|
+
- spec/nike_v2/activity_spec.rb
|
139
|
+
- spec/nike_v2/base_spec.rb
|
140
|
+
- spec/nike_v2/gps_data_spec.rb
|
141
|
+
- spec/nike_v2/person_spec.rb
|
142
|
+
- spec/nike_v2/resource_spec.rb
|
143
|
+
- spec/nike_v2/summary_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: https://github.com/fuelxc/nike_v2
|
146
|
+
licenses: []
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.23
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Nike+ API V2 Gem
|
169
|
+
test_files:
|
170
|
+
- spec/factories/activity_factory.rb
|
171
|
+
- spec/factories/person_factory.rb
|
172
|
+
- spec/fixtures/nike_api_cassettes/activities.yml
|
173
|
+
- spec/fixtures/nike_api_cassettes/activity.yml
|
174
|
+
- spec/fixtures/nike_api_cassettes/gps_data.yml
|
175
|
+
- spec/fixtures/nike_api_cassettes/summary.yml
|
176
|
+
- spec/nike_v2/acitivites_spec.rb
|
177
|
+
- spec/nike_v2/activity_spec.rb
|
178
|
+
- spec/nike_v2/base_spec.rb
|
179
|
+
- spec/nike_v2/gps_data_spec.rb
|
180
|
+
- spec/nike_v2/person_spec.rb
|
181
|
+
- spec/nike_v2/resource_spec.rb
|
182
|
+
- spec/nike_v2/summary_spec.rb
|
183
|
+
- spec/spec_helper.rb
|