nike_v2 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ext/core_ext.rb +19 -0
- data/lib/nike_v2/activities.rb +43 -12
- data/lib/nike_v2/activity.rb +11 -0
- data/lib/nike_v2/metric.rb +3 -3
- data/lib/nike_v2/metrics.rb +11 -9
- data/lib/nike_v2/person.rb +3 -3
- data/lib/nike_v2/resource.rb +14 -8
- data/lib/nike_v2/summary.rb +12 -5
- data/lib/nike_v2/version.rb +3 -0
- data/lib/nike_v2.rb +7 -8
- data/spec/fixtures/nike_api_cassettes/activities.yml +66 -0
- data/spec/fixtures/nike_api_cassettes/activity.yml +1 -1
- data/spec/nike_v2/acitivites_spec.rb +13 -1
- data/spec/nike_v2/activity_spec.rb +10 -2
- data/spec/nike_v2/metrics_spec.rb +1 -1
- data/spec/nike_v2/summary_spec.rb +1 -1
- metadata +3 -2
data/lib/ext/core_ext.rb
CHANGED
@@ -6,4 +6,23 @@ class String
|
|
6
6
|
tr("-", "_").
|
7
7
|
downcase
|
8
8
|
end
|
9
|
+
def camelize(first_letter_in_uppercase = false)
|
10
|
+
lower_case_and_underscored_word = self.to_s
|
11
|
+
if first_letter_in_uppercase
|
12
|
+
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
13
|
+
else
|
14
|
+
lower_case_and_underscored_word[0].downcase + lower_case_and_underscored_word.camelize[1..-1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Symbol
|
20
|
+
def camelize(first_letter_in_uppercase = false)
|
21
|
+
lower_case_and_underscored_word = self.to_s
|
22
|
+
if first_letter_in_uppercase
|
23
|
+
lower_case_and_underscored_word.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }.to_sym
|
24
|
+
else
|
25
|
+
(lower_case_and_underscored_word[0].downcase + lower_case_and_underscored_word.camelize[1..-1]).to_sym
|
26
|
+
end
|
27
|
+
end
|
9
28
|
end
|
data/lib/nike_v2/activities.rb
CHANGED
@@ -4,38 +4,69 @@ module NikeV2
|
|
4
4
|
include Enumerable
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
|
7
|
+
API_ARGS = [:offset, :count, :start_date, :end_date]
|
8
|
+
|
9
|
+
def_delegators :@activities_array, :[]=, :<<, :[], :count, :length, :each, :first, :last, :collect
|
8
10
|
def_delegator :@person, :access_token
|
9
11
|
|
10
12
|
API_URL = '/me/sport/activities'
|
11
13
|
|
12
14
|
def initialize(attributes = {})
|
13
15
|
raise "#{self.class} requires a person." unless attributes.keys.include?(:person)
|
16
|
+
@build_metrics = attributes.delete(:build_metrics) || false
|
17
|
+
api_args = extract_api_args(attributes)
|
14
18
|
set_attributes(attributes)
|
15
19
|
@activities_array = []
|
16
20
|
|
17
|
-
#TODO: make it pass blocks
|
18
|
-
activities = fetch_data
|
19
|
-
build_activities(activities.delete('data'))
|
20
21
|
|
21
|
-
|
22
|
+
#TODO: make it pass blocks
|
23
|
+
activities = fetch_data(api_args)
|
24
|
+
if !activities.nil? && !activities['data'].nil?
|
25
|
+
build_activities(activities.delete('data'))
|
26
|
+
super(activities)
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
def fetch_more
|
25
31
|
unless self.paging['next'].blank?
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
fetch_and_build_activities
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch_all
|
37
|
+
until self.paging['next'].blank? do
|
38
|
+
fetch_and_build_activities
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
42
|
+
def fuelpoints_during(start_time, end_time)
|
43
|
+
#reject activities that are not on the right date
|
44
|
+
end
|
45
|
+
|
34
46
|
private
|
35
47
|
def build_activities(data)
|
36
|
-
data
|
37
|
-
|
48
|
+
if data
|
49
|
+
data.each do |activity|
|
50
|
+
self << NikeV2::Activity.new({:person => self}.merge(activity))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
if @build_metrics
|
54
|
+
self.collect(&:load_data)
|
38
55
|
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_api_args(args)
|
60
|
+
args.inject({}){|h,a| h[a.first.camelize] = a.last if API_ARGS.include?(a.first); h}
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch_and_build_activities
|
64
|
+
url, query = self.paging['next'].match(/^(.*?)\?(.*)$/)[1,2]
|
65
|
+
query = query.split(/&/).inject({}){|h,item| k, v = item.split(/\=/); h[k] = v;h}
|
66
|
+
activities = fetch_data(url, {query: query})
|
67
|
+
build_activities(activities.delete('data'))
|
68
|
+
|
69
|
+
@paging = activities.delete('paging')
|
39
70
|
end
|
40
71
|
end
|
41
72
|
end
|
data/lib/nike_v2/activity.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
+
require 'nike_v2/metrics'
|
1
2
|
module NikeV2
|
2
3
|
class Activity < Resource
|
3
4
|
extend Forwardable
|
4
5
|
def_delegator :@person, :access_token
|
5
6
|
|
7
|
+
Metrics::METRIC_TYPES.each do |type|
|
8
|
+
self.class_eval do
|
9
|
+
def_delegator :metrics, "total_#{type.downcase}"
|
10
|
+
def_delegator :metrics, type.downcase
|
11
|
+
def_delegator :metrics, "total_#{type.downcase}_during"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
6
15
|
API_URL = '/me/sport/activities'
|
7
16
|
|
8
17
|
def initialize(attributes = {})
|
9
18
|
raise "#{self.class} requires s person." unless attributes.keys.include?(:person)
|
10
19
|
raise "#{self.class} requires an activityId." unless attributes.keys.include?('activityId')
|
20
|
+
|
11
21
|
super(attributes)
|
12
22
|
end
|
13
23
|
|
@@ -16,6 +26,7 @@ module NikeV2
|
|
16
26
|
end
|
17
27
|
|
18
28
|
def metrics
|
29
|
+
load_data unless @metrics
|
19
30
|
@metrics
|
20
31
|
end
|
21
32
|
|
data/lib/nike_v2/metric.rb
CHANGED
@@ -5,7 +5,7 @@ module NikeV2
|
|
5
5
|
@activity = activity
|
6
6
|
@unit = data['intervalUnit']
|
7
7
|
@type = data ['metricType']
|
8
|
-
@values = data['values']
|
8
|
+
@values = data['values'].collect(&:to_f)
|
9
9
|
end
|
10
10
|
|
11
11
|
def type
|
@@ -21,7 +21,7 @@ module NikeV2
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def total_during(start, stop)
|
24
|
-
during(start, stop).collect(&:
|
24
|
+
during(start, stop).collect(&:to_f).inject(:+) rescue 0
|
25
25
|
end
|
26
26
|
|
27
27
|
def during(start, stop)
|
@@ -31,7 +31,7 @@ module NikeV2
|
|
31
31
|
private
|
32
32
|
def time_to_index(time)
|
33
33
|
difference = time.to_i - @activity.started_at.to_i
|
34
|
-
difference.
|
34
|
+
difference.s.to.send(@unit.downcase).to_s.to_i
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/nike_v2/metrics.rb
CHANGED
@@ -6,22 +6,20 @@ module NikeV2
|
|
6
6
|
|
7
7
|
def_delegators :@metrics_array, :[]=, :<<, :[], :count, :length, :each, :first, :last
|
8
8
|
|
9
|
+
METRIC_TYPES = %w(FUEL CALORIES DISTANCE STEPS)
|
10
|
+
|
9
11
|
def initialize(activity, data_set)
|
10
12
|
@activity = activity
|
11
13
|
@metrics_array = []
|
12
14
|
build_metrics(data_set)
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def calories
|
20
|
-
@fuel_points ||= sum_of_type('CALORIES')
|
21
|
-
end
|
17
|
+
METRIC_TYPES.each do |type|
|
18
|
+
method_var_name = 'total_' + type.downcase
|
19
|
+
instance_variable_set('@' + method_var_name, 0.00)
|
20
|
+
define_method(method_var_name){ ivar = instance_variable_get('@' + method_var_name); ivar ||= sum_of_type(type)}
|
22
21
|
|
23
|
-
|
24
|
-
@fuel_points ||= sum_of_type('DISTANCE')
|
22
|
+
define_method(method_var_name + '_during'){|*args| sum_of_type_during(type, *args)}
|
25
23
|
end
|
26
24
|
|
27
25
|
private
|
@@ -34,5 +32,9 @@ module NikeV2
|
|
34
32
|
def sum_of_type(type)
|
35
33
|
@metrics_array.select{|m| m.type == type}.collect(&:total).inject(:+) || 0.00
|
36
34
|
end
|
35
|
+
|
36
|
+
def sum_of_type_during(type, *args)
|
37
|
+
@metrics_array.select{|m| m.type == type}.collect{|m| m.total_during(*args)}.inject(:+) || 0.00
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
data/lib/nike_v2/person.rb
CHANGED
@@ -7,11 +7,11 @@ module NikeV2
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def summary
|
10
|
-
|
10
|
+
NikeV2::Summary.new(:person => self)
|
11
11
|
end
|
12
12
|
|
13
|
-
def activities
|
14
|
-
|
13
|
+
def activities(args = {})
|
14
|
+
NikeV2::Activities.new(args.merge(:person => self))
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
data/lib/nike_v2/resource.rb
CHANGED
@@ -4,13 +4,20 @@ module NikeV2
|
|
4
4
|
|
5
5
|
base_uri 'https://api.nike.com'
|
6
6
|
|
7
|
+
RESP_MSG_INVALID_TOKEN = 'invalid_token'
|
8
|
+
|
7
9
|
def initialize(attributes={})
|
8
10
|
super(attributes)
|
9
11
|
end
|
10
12
|
|
11
13
|
def fetch_data(*args)
|
12
|
-
args
|
13
|
-
get(*args).parsed_response
|
14
|
+
args.unshift(api_url)
|
15
|
+
resp = get(*args).parsed_response
|
16
|
+
|
17
|
+
if !resp['error'].nil? && resp['error'] == RESP_MSG_INVALID_TOKEN
|
18
|
+
raise "#{self.class} invalid or expired token, can not fetch data from server."
|
19
|
+
end
|
20
|
+
resp
|
14
21
|
end
|
15
22
|
|
16
23
|
def get(*args, &block)
|
@@ -21,14 +28,13 @@ module NikeV2
|
|
21
28
|
private
|
22
29
|
|
23
30
|
def build_options(args)
|
24
|
-
query =
|
31
|
+
query = has_options?(args) ? args.pop : {}
|
32
|
+
|
33
|
+
query.merge!('access_token' => access_token)
|
25
34
|
headers = { 'Accept' => 'application/json', 'appid' => app_id }
|
26
35
|
options = { query: query, headers: headers }
|
27
|
-
|
28
|
-
|
29
|
-
else
|
30
|
-
args << options
|
31
|
-
end
|
36
|
+
|
37
|
+
args << options
|
32
38
|
end
|
33
39
|
|
34
40
|
|
data/lib/nike_v2/summary.rb
CHANGED
@@ -14,11 +14,18 @@ module NikeV2
|
|
14
14
|
private
|
15
15
|
def initialize_data
|
16
16
|
fuel_data = fetch_data
|
17
|
-
initialization_data = {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
initialization_data = {}
|
18
|
+
if fuel_data
|
19
|
+
if fuel_data.has_key?('experienceTypes')
|
20
|
+
initialization_data = {
|
21
|
+
'activity_types' => fuel_data['experienceTypes'].collect{|a| ExperienceType.new(a)}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
if fuel_data.has_key?('summaries')
|
25
|
+
fuel_data['summaries'].each do |data|
|
26
|
+
initialization_data[data['experienceType'].downcase] = data['records']
|
27
|
+
end
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
31
|
initialization_data
|
data/lib/nike_v2.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
+
require 'nike_v2/version'
|
2
|
+
|
1
3
|
require 'httparty'
|
2
4
|
require 'forwardable'
|
3
5
|
require 'alchemist'
|
4
6
|
require 'ext/core_ext'
|
7
|
+
|
5
8
|
require 'nike_v2/base'
|
9
|
+
require 'nike_v2/metric'
|
10
|
+
require 'nike_v2/metrics'
|
6
11
|
require 'nike_v2/experience_type'
|
7
12
|
require 'nike_v2/resource'
|
8
13
|
require 'nike_v2/person'
|
9
|
-
require 'nike_v2/activities'
|
10
14
|
require 'nike_v2/activity'
|
15
|
+
require 'nike_v2/activities'
|
11
16
|
require 'nike_v2/summary'
|
12
|
-
require 'nike_v2/gps_data'
|
13
|
-
require 'nike_v2/metrics'
|
14
|
-
require 'nike_v2/metric'
|
15
|
-
|
16
|
-
module NikeV2
|
17
|
-
VERSION = '0.1.2'
|
18
|
-
end
|
17
|
+
require 'nike_v2/gps_data'
|
@@ -33,4 +33,70 @@ http_interactions:
|
|
33
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
34
|
http_version:
|
35
35
|
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
|
+
- request:
|
37
|
+
method: get
|
38
|
+
uri: https://api.nike.com/me/sport/activities?access_token=foobar&count=1
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: ''
|
42
|
+
headers:
|
43
|
+
Accept:
|
44
|
+
- application/json
|
45
|
+
Appid:
|
46
|
+
- nike
|
47
|
+
response:
|
48
|
+
status:
|
49
|
+
code: 200
|
50
|
+
message: OK
|
51
|
+
headers:
|
52
|
+
Content-Type:
|
53
|
+
- application/json;charset=UTF-8
|
54
|
+
Date:
|
55
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
56
|
+
Server:
|
57
|
+
- Apache
|
58
|
+
X-Swooshlet:
|
59
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
60
|
+
Content-Length:
|
61
|
+
- '340'
|
62
|
+
Connection:
|
63
|
+
- keep-alive
|
64
|
+
body:
|
65
|
+
encoding: US-ASCII
|
66
|
+
string: ! '{ "data": [ { "activityId": "c3337642-72db-41f7-b4a2-4da4600dfc9f", "calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659, "duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-02-26T07:00:00Z", "activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType": "FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?count=1&access_token=2159f27a88a8cc3b410e1529412b86f5&offset=2" } }'
|
67
|
+
http_version:
|
68
|
+
recorded_at: Wed, 27 Feb 2013 16:18:07 GMT
|
69
|
+
- request:
|
70
|
+
method: get
|
71
|
+
uri: https://api.nike.com/me/sport/activities?access_token=foobar&startDate=2013-01-01
|
72
|
+
body:
|
73
|
+
encoding: US-ASCII
|
74
|
+
string: ''
|
75
|
+
headers:
|
76
|
+
Accept:
|
77
|
+
- application/json
|
78
|
+
Appid:
|
79
|
+
- nike
|
80
|
+
response:
|
81
|
+
status:
|
82
|
+
code: 200
|
83
|
+
message: OK
|
84
|
+
headers:
|
85
|
+
Content-Type:
|
86
|
+
- application/json;charset=UTF-8
|
87
|
+
Date:
|
88
|
+
- Sun, 20 Jan 2013 04:21:04 GMT
|
89
|
+
Server:
|
90
|
+
- Apache
|
91
|
+
X-Swooshlet:
|
92
|
+
- app-msp-api-0 prd sin-82-app-msp-api-0
|
93
|
+
Content-Length:
|
94
|
+
- '340'
|
95
|
+
Connection:
|
96
|
+
- keep-alive
|
97
|
+
body:
|
98
|
+
encoding: US-ASCII
|
99
|
+
string: ! '{ "data": [ { "activityId": "c3337642-72db-41f7-b4a2-4da4600dfc9f", "calories": 581, "fuel": 1653, "distance": 2.0936965942382812, "steps": 2659, "duration": "7:02:00.000", "activityType": "ALL_DAY", "startTime": "2013-01-01T07:00:00Z", "activityTimeZone": "America/Phoenix", "status": "IN_PROGRESS", "deviceType": "FUELBAND", "tags": [], "metrics": [] } ], "paging": { "next": "/me/sport/activities?startDate=2013-01-01&access_token=2159f27a88a8cc3b410e1529412b86f5&offset=2" } }'
|
100
|
+
http_version:
|
101
|
+
recorded_at: Wed, 27 Feb 2013 16:18:07 GMT
|
36
102
|
recorded_with: VCR 2.4.0
|
@@ -30,7 +30,7 @@ http_interactions:
|
|
30
30
|
- keep-alive
|
31
31
|
body:
|
32
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-
|
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-11T00:00:00Z", "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 ] }, { "intervalMetric": 1, "intervalUnit": "MIN", "metricType": "FUEL", "values": [ "21", "8", "21", "3", "19", "19", "8", "25", "8", "3", "16", "14", "23", "26", "28", "24", "14", "19", "16", "0", "2", "20", "22", "3", "21", "7", "24", "26", "25", "8", "21", "22", "20", "6", "22", "17", "15", "2", "22", "4", "18", "16", "9", "10", "0", "24", "7", "25", "9", "8", "15", "3", "7", "12", "22", "18", "13", "28", "15", "0", "22", "24", "16", "14", "12", "14", "18", "5", "8", "24", "9", "18", "25", "15", "6", "3", "28", "5", "8", "6", "19", "6", "18", "18", "21", "24", "26", "0", "24", "12", "5", "11", "3", "12", "22", "22", "22", "23", "1", "1", "16", "6", "26", "14", "11", "23", "15", "4", "13", "2", "3", "28", "2", "7", "9", "0", "4", "25", "18", "10", "25", "3", "23", "27", "10", "20", "2", "15", "23", "1", "21", "14", "4", "1", "26", "20", "20", "28", "24", "18", "9", "24", "23", "16", "0", "11", "14", "14", "12", "15", "12", "3", "14", "21", "17", "22", "28", "28", "27", "21", "15", "25", "24", "2", "25", "21", "20", "3", "20", "6", "2", "6", "1", "25", "20", "20", "23", "9", "8", "17", "5", "15", "2", "15", "21", "21", "25", "13", "10", "22", "10", "6", "25", "27", "6", "24", "0", "20", "27", "12", "23", "7", "20", "11", "15", "23", "20", "21", "24", "25", "21", "20", "12", "7", "16", "24", "16", "26", "15", "16", "15", "7", "11", "17", "26", "24", "17", "25", "12", "23", "12", "5", "23", "7", "11", "1", "6", "14", "18", "14", "8", "11", "13", "0", "17", "15", "26", "25", "0", "17", "27", "6", "14", "19", "16", "12", "15", "1", "12", "15", "12", "0", "7", "16", "12", "22", "10", "14", "27", "9", "6", "16", "4", "18", "18", "19", "16", "7", "12", "12", "4", "17", "25", "20", "28", "7", "9", "5", "2", "14", "7", "28", "11", "11", "3", "25", "13", "1", "15", "3", "27", "8", "6", "17", "24", "6", "19", "25", "2", "3", "12", "2", "18", "15", "25", "25", "26", "28", "22", "18", "0", "0", "24", "25", "7", "2", "28", "0", "21", "23", "26", "25", "7", "22", "27", "11", "4", "15", "12", "3", "2", "26", "6", "13", "26", "1", "18", "14", "22", "9", "9", "1", "19", "12", "27", "10", "6", "6", "25", "1", "21", "21", "6", "20", "22", "1", "3", "8", "1", "7", "11", "10", "16", "5", "14", "19", "21", "23", "3", "3", "4", "10", "20", "6", "1", "19", "0", "8", "28", "10", "19", "14", "17", "3", "13", "7", "24", "26", "8", "1", "27", "5", "2", "9", "13", "0", "20", "9", "23", "13", "27", "13", "1", "2", "12", "13", "17", "20", "21", "22", "1", "13", "14", "2", "16", "12", "9", "19", "10", "2", "28", "27", "23", "25", "27", "9", "28", "25", "3", "28", "13", "18", "3", "25", "25", "3", "10", "20", "5", "27", "14", "24", "10", "4", "11", "16", "11", "6", "16", "24", "20", "14", "23", "8", "13", "5", "25", "7", "11", "23", "10", "0", "27", "1", "22", "28", "26", "13", "16", "23", "13", "2", "22", "23", "25", "2", "7", "1", "9", "28", "13", "24", "16", "1", "24", "4", "21", "25", "12", "7", "26", "0", "1", "13", "23", "12", "2", "4", "1", "12", "23", "12", "21", "21", "2", "10", "5", "16", "1", "17", "1", "2", "4", "1", "27", "14", "12", "13", "27", "28", "8", "21", "18", "6", "15", "10", "12", "7", "0", "26", "4", "12", "1", "1", "20", "22", "10", "19", "27", "16", "7", "24", "14", "25", "0", "10", "5", "5", "8", "5", "3", "16", "15", "6", "7", "5", "14", "6", "11", "18", "17", "11", "7", "7", "2", "24", "11", "13", "17", "26", "6", "13", "9", "16", "18", "3", "12", "14", "3", "13", "11", "20", "8", "18", "12", "0", "3", "22", "17", "4", "0", "8", "3", "21", "28", "5", "14", "8", "20", "17", "24", "15", "7", "1", "1", "27", "12", "12", "4", "4", "27", "25", "0", "5", "9", "2", "9", "26", "13", "11", "9", "21", "14", "27", "28", "25", "10", "17", "5", "18", "10", "3", "13", "14", "28", "9", "9", "22", "20", "0", "28", "25", "25", "14", "18", "7", "28", "28", "16", "13", "2", "21", "24", "19", "16", "27", "5", "9", "22", "11", "24", "24", "12", "18", "10", "6", "2", "18", "8", "27", "8", "10", "5", "2", "7", "21", "4", "7", "13", "27", "20", "25", "19", "4", "9", "28", "11", "15", "13", "17", "7", "12", "27", "6", "3", "15", "22", "14", "2", "17", "21", "16", "17", "7", "10", "24", "26", "16", "11", "27", "11", "28", "25", "27", "9", "3", "19", "20", "23", "4", "24", "27", "14", "20", "15", "15", "3", "22", "18", "9", "17", "22", "16", "28", "1", "14", "13", "8", "21", "25", "16", "24", "16", "15", "16", "13", "17", "8", "24", "0", "19", "5", "18", "18", "3", "16", "18", "10", "22", "3", "24", "27", "15", "28", "9", "17", "24", "15", "3", "15", "16", "24", "25", "25", "28", "20", "10", "19", "1", "12", "12", "28", "23", "17", "24", "4", "10", "25", "19", "25", "5", "5", "10", "23", "17", "18", "17", "4", "5", "26", "27", "6", "9", "23", "3", "5", "12", "21", "22", "7", "4", "22", "10", "4", "14", "23", "9", "20", "26", "2", "5", "21", "4", "11", "18", "19", "14", "21", "16", "9", "13", "0", "14", "19", "14", "2", "10", "9", "4", "23", "8", "0", "10", "12", "24", "6", "3", "1", "20", "28", "24", "11", "5", "14", "23", "0", "20", "24", "4", "6", "5", "21", "13", "5", "28", "9", "11", "5", "12", "1", "10", "8", "24", "23", "28", "14", "2", "2", "10", "3", "21", "23", "2", "0", "12", "20", "20", "17", "18", "27", "20", "0", "27", "28", "11", "15", "5", "0", "1", "4", "3", "21", "22", "22", "22", "1", "7", "19", "8", "6", "11", "5", "19", "16", "6", "11", "20", "23", "5", "25", "27", "16", "5", "18", "17", "18", "25", "11", "25", "5", "16", "13", "16", "8", "7", "0", "13", "27", "14", "20", "26", "26", "11", "12", "16", "25", "6", "24", "16", "20", "26", "14", "22", "16", "12", "21", "23", "15", "20", "24", "23", "14", "10", "1", "11", "0", "16", "15", "9", "24", "14", "11", "9", "21", "18", "13", "26", "4", "16", "7", "16", "14", "11", "6", "13", "2", "6", "19", "21", "4", "4", "14", "22", "28", "23", "1", "2", "11", "24", "13", "20", "7", "28", "15", "6", "14", "25", "5", "21", "17", "25", "23", "18", "4", "11", "28", "5", "24", "19", "17", "4", "1", "1", "9", "15", "16", "12", "26", "4", "12", "21", "9", "11", "4", "19", "13", "25", "11", "13", "3", "10", "13", "22", "21", "22", "5", "18", "9", "18", "26", "15", "9", "12", "3", "27", "25", "19", "11", "28", "23", "19", "2", "16", "18", "21", "26", "28", "25", "18", "23", "23", "5", "22", "13", "15", "12", "24", "25", "20", "9", "16", "13", "21", "15", "17", "25", "11", "21", "21", "13", "25", "24", "26", "12", "1", "28", "6", "19", "19", "22", "15", "9", "0", "16", "0", "4", "8", "4", "8", "7", "21", "23", "15", "19", "5", "13", "19", "19", "22", "14", "8", "2", "4", "15", "27", "19", "21", "27", "1", "7", "5", "15", "15", "6", "25", "11", "7", "19", "17", "17", "3", "10", "26", "1", "25", "6", "0", "20", "0", "23", "20", "0", "13", "27", "2", "12", "4", "16", "13", "22", "19", "15", "11", "27", "21", "26", "26", "9", "8", "24", "10", "20", "21", "7", "17", "28", "21", "19", "3", "21", "7", "9", "21", "6", "13", "26", "20", "6", "7", "4", "0", "7", "17", "12", "21", "12", "14", "17", "21", "4", "12", "8", "20", "2", "4", "6", "23", "27", "16", "16", "19", "10", "14", "9", "8", "14", "18", "19", "22", "21", "24", "0", "14", "15", "17", "10", "17", "28", "27", "26", "16", "10", "14", "6", "25", "20", "22", "26", "5", "0", "26", "1", "16", "4", "1", "13", "24", "9", "25", "19", "26", "16", "27", "28", "5", "8", "27", "9", "16", "24", "2", "3", "23", "15", "10", "17", "11", "24", "1", "2", "19", "5", "25", "27", "16", "17", "27", "15", "15", "27", "8", "2", "7", "25", "14", "3", "12", "16", "17", "20", "19", "9", "11", "1", "22", "13", "7", "7", "21", "18", "15", "14", "18", "23", "5", "11", "17", "15", "7", "17", "17", "15", "16", "17", "4", "10", "21", "13", "25", "0", "17", "17", "5", "15", "27", "25", "24", "5", "0", "18", "8", "6", "25", "25", "20", "27", "21", "25", "3", "5", "0", "13", "6", "7", "9", "7", "19", "13", "13", "4", "24", "0", "23", "17", "0", "7", "1", "16", "4", "21", "10", "23", "6", "12", "21", "1", "5", "11", "25", "8", "15", "26", "3", "2", "0", "22", "16", "8", "19", "16", "2", "9", "28", "14", "9", "15", "1", "8", "18", "9", "4", "9", "19", "18", "16", "28", "4", "10", "23", "22", "9", "21", "25", "8", "9", "16", "16", "21", "18", "8", "20", "17", "3", "15", "23", "16", "24", "10", "10", "28", "27", "18", "4", "25", "22", "19", "11", "2", "23" ] } ] }'
|
34
34
|
http_version:
|
35
35
|
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
36
36
|
recorded_with: VCR 2.4.0
|
@@ -4,7 +4,7 @@ describe NikeV2::Activities do
|
|
4
4
|
let(:person){ build(:person) }
|
5
5
|
|
6
6
|
describe 'new from person' do
|
7
|
-
before{ VCR.insert_cassette 'activities', record: :new_episodes }
|
7
|
+
before{ VCR.insert_cassette 'activities', record: :new_episodes, :allow_playback_repeats => true }
|
8
8
|
after{ VCR.eject_cassette }
|
9
9
|
|
10
10
|
it 'should return an array of Nike::Activity' do
|
@@ -12,5 +12,17 @@ describe NikeV2::Activities do
|
|
12
12
|
person.activities.first.should be_kind_of(NikeV2::Activity)
|
13
13
|
person.activities.length.should == 5
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'should accept the count parameter and return an array of Nike::Activity' do
|
17
|
+
person.activities(:count => 1).should be_kind_of(NikeV2::Activities)
|
18
|
+
person.activities(:count => 1).first.should be_kind_of(NikeV2::Activity)
|
19
|
+
person.activities(:count => 1).length.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should accept the start_date parameter, camelcase it and return an array of Nike::Activity' do
|
23
|
+
person.activities(:count => 1).should be_kind_of(NikeV2::Activities)
|
24
|
+
person.activities(:count => 1).first.should be_kind_of(NikeV2::Activity)
|
25
|
+
person.activities(:count => 1).length.should == 1
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
@@ -4,12 +4,20 @@ describe NikeV2::Activity do
|
|
4
4
|
let(:activity){ build(:activity) }
|
5
5
|
|
6
6
|
describe 'fetch_data' do
|
7
|
-
before{ VCR.insert_cassette 'activity', record: :new_episodes }
|
7
|
+
before{ VCR.insert_cassette 'activity', record: :new_episodes, :allow_playback_repeats => true }
|
8
8
|
after{ VCR.eject_cassette }
|
9
9
|
|
10
|
-
it 'should load the activity from the api' do
|
10
|
+
it 'should load the activity metrics from the api' do
|
11
11
|
activity.load_data.should be_true
|
12
12
|
activity.calories.should == 257
|
13
13
|
end
|
14
|
+
|
15
|
+
it 'should load the activity metrics from the api without explicit call' do
|
16
|
+
activity.total_fuel.should == 20491.0
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should sum the metrics during a time period' do
|
20
|
+
activity.total_fuel_during(Time.parse('2011-08-11T00:00:00'), Time.parse('2011-08-11T01:00:00')).should == 934.0
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
@@ -4,7 +4,7 @@ describe NikeV2::Summary do
|
|
4
4
|
let(:person){ build(:person) }
|
5
5
|
|
6
6
|
describe 'new' do
|
7
|
-
before{ VCR.insert_cassette 'summary', record: :new_episodes }
|
7
|
+
before{ VCR.insert_cassette 'summary', record: :new_episodes, :allow_playback_repeats => true }
|
8
8
|
after{ VCR.eject_cassette }
|
9
9
|
|
10
10
|
it 'should return a Summary of user data' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nike_v2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/nike_v2/person.rb
|
147
147
|
- lib/nike_v2/resource.rb
|
148
148
|
- lib/nike_v2/summary.rb
|
149
|
+
- lib/nike_v2/version.rb
|
149
150
|
- nike_v2.gemspec
|
150
151
|
- spec/factories/activity_factory.rb
|
151
152
|
- spec/factories/person_factory.rb
|