nike_v2_neura 0.3.7
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 +100 -0
- data/Rakefile +13 -0
- data/lib/ext/core_ext.rb +18 -0
- data/lib/nike_v2.rb +33 -0
- data/lib/nike_v2/activities.rb +102 -0
- data/lib/nike_v2/activity.rb +73 -0
- data/lib/nike_v2/base.rb +17 -0
- data/lib/nike_v2/experience_type.rb +27 -0
- data/lib/nike_v2/gps_data.rb +17 -0
- data/lib/nike_v2/metric.rb +48 -0
- data/lib/nike_v2/metrics.rb +45 -0
- data/lib/nike_v2/person.rb +18 -0
- data/lib/nike_v2/resource.rb +69 -0
- data/lib/nike_v2/summary.rb +40 -0
- data/lib/nike_v2/version.rb +3 -0
- data/nike_v2.gemspec +28 -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 +370 -0
- data/spec/fixtures/nike_api_cassettes/activity.yml +153 -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/activites_spec.rb +38 -0
- data/spec/nike_v2/activity_spec.rb +24 -0
- data/spec/nike_v2/base_spec.rb +11 -0
- data/spec/nike_v2/gps_data_spec.rb +15 -0
- data/spec/nike_v2/metric_spec.rb +29 -0
- data/spec/nike_v2/metrics_spec.rb +22 -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 +240 -0
@@ -0,0 +1,153 @@
|
|
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":
|
34
|
+
257, "fuel": 662, "distance": 3.1317999362945557, "steps": 10, "duration":
|
35
|
+
"0:14:31.000", "activityType": "RUN", "startTime": "2011-08-11T07:00:00Z",
|
36
|
+
"activityTimeZone": "America/Phoenix", "status": "COMPLETE", "deviceType": "SPORTWATCH",
|
37
|
+
"tags": [ { "tagType": "NOTE", "value": "text string" }, { "tagType": "COURT",
|
38
|
+
"value": "DUNK" }, { "tagType": "TERRAIN", "value": "TRAIL" }, { "tagType":
|
39
|
+
"EMOTION", "value": "HAPPY" }, { "tagType": "SHOES", "value": "AirMax" },
|
40
|
+
{ "tagType": "WEATHER", "value": "RAINY" } ], "metrics": [ { "intervalMetric":
|
41
|
+
10, "intervalUnit": "SEC", "metricType": "DISTANCE", "values": [ 0.0299, 0.0562,
|
42
|
+
0.0794, 0.114, 3.0967, 3.1296 ] }, { "intervalMetric": 1, "intervalUnit":
|
43
|
+
"MIN", "metricType": "FUEL", "values": [ "21", "8", "21", "3", "19", "19",
|
44
|
+
"8", "25", "8", "3", "16", "14", "23", "26", "28", "24", "14", "19", "16",
|
45
|
+
"0", "2", "20", "22", "3", "21", "7", "24", "26", "25", "8", "21", "22", "20",
|
46
|
+
"6", "22", "17", "15", "2", "22", "4", "18", "16", "9", "10", "0", "24", "7",
|
47
|
+
"25", "9", "8", "15", "3", "7", "12", "22", "18", "13", "28", "15", "0", "22",
|
48
|
+
"24", "16", "14", "12", "14", "18", "5", "8", "24", "9", "18", "25", "15",
|
49
|
+
"6", "3", "28", "5", "8", "6", "19", "6", "18", "18", "21", "24", "26", "0",
|
50
|
+
"24", "12", "5", "11", "3", "12", "22", "22", "22", "23", "1", "1", "16",
|
51
|
+
"6", "26", "14", "11", "23", "15", "4", "13", "2", "3", "28", "2", "7", "9",
|
52
|
+
"0", "4", "25", "18", "10", "25", "3", "23", "27", "10", "20", "2", "15",
|
53
|
+
"23", "1", "21", "14", "4", "1", "26", "20", "20", "28", "24", "18", "9",
|
54
|
+
"24", "23", "16", "0", "11", "14", "14", "12", "15", "12", "3", "14", "21",
|
55
|
+
"17", "22", "28", "28", "27", "21", "15", "25", "24", "2", "25", "21", "20",
|
56
|
+
"3", "20", "6", "2", "6", "1", "25", "20", "20", "23", "9", "8", "17", "5",
|
57
|
+
"15", "2", "15", "21", "21", "25", "13", "10", "22", "10", "6", "25", "27",
|
58
|
+
"6", "24", "0", "20", "27", "12", "23", "7", "20", "11", "15", "23", "20",
|
59
|
+
"21", "24", "25", "21", "20", "12", "7", "16", "24", "16", "26", "15", "16",
|
60
|
+
"15", "7", "11", "17", "26", "24", "17", "25", "12", "23", "12", "5", "23",
|
61
|
+
"7", "11", "1", "6", "14", "18", "14", "8", "11", "13", "0", "17", "15", "26",
|
62
|
+
"25", "0", "17", "27", "6", "14", "19", "16", "12", "15", "1", "12", "15",
|
63
|
+
"12", "0", "7", "16", "12", "22", "10", "14", "27", "9", "6", "16", "4", "18",
|
64
|
+
"18", "19", "16", "7", "12", "12", "4", "17", "25", "20", "28", "7", "9",
|
65
|
+
"5", "2", "14", "7", "28", "11", "11", "3", "25", "13", "1", "15", "3", "27",
|
66
|
+
"8", "6", "17", "24", "6", "19", "25", "2", "3", "12", "2", "18", "15", "25",
|
67
|
+
"25", "26", "28", "22", "18", "0", "0", "24", "25", "7", "2", "28", "0", "21",
|
68
|
+
"23", "26", "25", "7", "22", "27", "11", "4", "15", "12", "3", "2", "26",
|
69
|
+
"6", "13", "26", "1", "18", "14", "22", "9", "9", "1", "19", "12", "27", "10",
|
70
|
+
"6", "6", "25", "1", "21", "21", "6", "20", "22", "1", "3", "8", "1", "7",
|
71
|
+
"11", "10", "16", "5", "14", "19", "21", "23", "3", "3", "4", "10", "20",
|
72
|
+
"6", "1", "19", "0", "8", "28", "10", "19", "14", "17", "3", "13", "7", "24",
|
73
|
+
"26", "8", "1", "27", "5", "2", "9", "13", "0", "20", "9", "23", "13", "27",
|
74
|
+
"13", "1", "2", "12", "13", "17", "20", "21", "22", "1", "13", "14", "2",
|
75
|
+
"16", "12", "9", "19", "10", "2", "28", "27", "23", "25", "27", "9", "28",
|
76
|
+
"25", "3", "28", "13", "18", "3", "25", "25", "3", "10", "20", "5", "27",
|
77
|
+
"14", "24", "10", "4", "11", "16", "11", "6", "16", "24", "20", "14", "23",
|
78
|
+
"8", "13", "5", "25", "7", "11", "23", "10", "0", "27", "1", "22", "28", "26",
|
79
|
+
"13", "16", "23", "13", "2", "22", "23", "25", "2", "7", "1", "9", "28", "13",
|
80
|
+
"24", "16", "1", "24", "4", "21", "25", "12", "7", "26", "0", "1", "13", "23",
|
81
|
+
"12", "2", "4", "1", "12", "23", "12", "21", "21", "2", "10", "5", "16", "1",
|
82
|
+
"17", "1", "2", "4", "1", "27", "14", "12", "13", "27", "28", "8", "21", "18",
|
83
|
+
"6", "15", "10", "12", "7", "0", "26", "4", "12", "1", "1", "20", "22", "10",
|
84
|
+
"19", "27", "16", "7", "24", "14", "25", "0", "10", "5", "5", "8", "5", "3",
|
85
|
+
"16", "15", "6", "7", "5", "14", "6", "11", "18", "17", "11", "7", "7", "2",
|
86
|
+
"24", "11", "13", "17", "26", "6", "13", "9", "16", "18", "3", "12", "14",
|
87
|
+
"3", "13", "11", "20", "8", "18", "12", "0", "3", "22", "17", "4", "0", "8",
|
88
|
+
"3", "21", "28", "5", "14", "8", "20", "17", "24", "15", "7", "1", "1", "27",
|
89
|
+
"12", "12", "4", "4", "27", "25", "0", "5", "9", "2", "9", "26", "13", "11",
|
90
|
+
"9", "21", "14", "27", "28", "25", "10", "17", "5", "18", "10", "3", "13",
|
91
|
+
"14", "28", "9", "9", "22", "20", "0", "28", "25", "25", "14", "18", "7",
|
92
|
+
"28", "28", "16", "13", "2", "21", "24", "19", "16", "27", "5", "9", "22",
|
93
|
+
"11", "24", "24", "12", "18", "10", "6", "2", "18", "8", "27", "8", "10",
|
94
|
+
"5", "2", "7", "21", "4", "7", "13", "27", "20", "25", "19", "4", "9", "28",
|
95
|
+
"11", "15", "13", "17", "7", "12", "27", "6", "3", "15", "22", "14", "2",
|
96
|
+
"17", "21", "16", "17", "7", "10", "24", "26", "16", "11", "27", "11", "28",
|
97
|
+
"25", "27", "9", "3", "19", "20", "23", "4", "24", "27", "14", "20", "15",
|
98
|
+
"15", "3", "22", "18", "9", "17", "22", "16", "28", "1", "14", "13", "8",
|
99
|
+
"21", "25", "16", "24", "16", "15", "16", "13", "17", "8", "24", "0", "19",
|
100
|
+
"5", "18", "18", "3", "16", "18", "10", "22", "3", "24", "27", "15", "28",
|
101
|
+
"9", "17", "24", "15", "3", "15", "16", "24", "25", "25", "28", "20", "10",
|
102
|
+
"19", "1", "12", "12", "28", "23", "17", "24", "4", "10", "25", "19", "25",
|
103
|
+
"5", "5", "10", "23", "17", "18", "17", "4", "5", "26", "27", "6", "9", "23",
|
104
|
+
"3", "5", "12", "21", "22", "7", "4", "22", "10", "4", "14", "23", "9", "20",
|
105
|
+
"26", "2", "5", "21", "4", "11", "18", "19", "14", "21", "16", "9", "13",
|
106
|
+
"0", "14", "19", "14", "2", "10", "9", "4", "23", "8", "0", "10", "12", "24",
|
107
|
+
"6", "3", "1", "20", "28", "24", "11", "5", "14", "23", "0", "20", "24", "4",
|
108
|
+
"6", "5", "21", "13", "5", "28", "9", "11", "5", "12", "1", "10", "8", "24",
|
109
|
+
"23", "28", "14", "2", "2", "10", "3", "21", "23", "2", "0", "12", "20", "20",
|
110
|
+
"17", "18", "27", "20", "0", "27", "28", "11", "15", "5", "0", "1", "4", "3",
|
111
|
+
"21", "22", "22", "22", "1", "7", "19", "8", "6", "11", "5", "19", "16", "6",
|
112
|
+
"11", "20", "23", "5", "25", "27", "16", "5", "18", "17", "18", "25", "11",
|
113
|
+
"25", "5", "16", "13", "16", "8", "7", "0", "13", "27", "14", "20", "26",
|
114
|
+
"26", "11", "12", "16", "25", "6", "24", "16", "20", "26", "14", "22", "16",
|
115
|
+
"12", "21", "23", "15", "20", "24", "23", "14", "10", "1", "11", "0", "16",
|
116
|
+
"15", "9", "24", "14", "11", "9", "21", "18", "13", "26", "4", "16", "7",
|
117
|
+
"16", "14", "11", "6", "13", "2", "6", "19", "21", "4", "4", "14", "22", "28",
|
118
|
+
"23", "1", "2", "11", "24", "13", "20", "7", "28", "15", "6", "14", "25",
|
119
|
+
"5", "21", "17", "25", "23", "18", "4", "11", "28", "5", "24", "19", "17",
|
120
|
+
"4", "1", "1", "9", "15", "16", "12", "26", "4", "12", "21", "9", "11", "4",
|
121
|
+
"19", "13", "25", "11", "13", "3", "10", "13", "22", "21", "22", "5", "18",
|
122
|
+
"9", "18", "26", "15", "9", "12", "3", "27", "25", "19", "11", "28", "23",
|
123
|
+
"19", "2", "16", "18", "21", "26", "28", "25", "18", "23", "23", "5", "22",
|
124
|
+
"13", "15", "12", "24", "25", "20", "9", "16", "13", "21", "15", "17", "25",
|
125
|
+
"11", "21", "21", "13", "25", "24", "26", "12", "1", "28", "6", "19", "19",
|
126
|
+
"22", "15", "9", "0", "16", "0", "4", "8", "4", "8", "7", "21", "23", "15",
|
127
|
+
"19", "5", "13", "19", "19", "22", "14", "8", "2", "4", "15", "27", "19",
|
128
|
+
"21", "27", "1", "7", "5", "15", "15", "6", "25", "11", "7", "19", "17", "17",
|
129
|
+
"3", "10", "26", "1", "25", "6", "0", "20", "0", "23", "20", "0", "13", "27",
|
130
|
+
"2", "12", "4", "16", "13", "22", "19", "15", "11", "27", "21", "26", "26",
|
131
|
+
"9", "8", "24", "10", "20", "21", "7", "17", "28", "21", "19", "3", "21",
|
132
|
+
"7", "9", "21", "6", "13", "26", "20", "6", "7", "4", "0", "7", "17", "12",
|
133
|
+
"21", "12", "14", "17", "21", "4", "12", "8", "20", "2", "4", "6", "23", "27",
|
134
|
+
"16", "16", "19", "10", "14", "9", "8", "14", "18", "19", "22", "21", "24",
|
135
|
+
"0", "14", "15", "17", "10", "17", "28", "27", "26", "16", "10", "14", "6",
|
136
|
+
"25", "20", "22", "26", "5", "0", "26", "1", "16", "4", "1", "13", "24", "9",
|
137
|
+
"25", "19", "26", "16", "27", "28", "5", "8", "27", "9", "16", "24", "2",
|
138
|
+
"3", "23", "15", "10", "17", "11", "24", "1", "2", "19", "5", "25", "27",
|
139
|
+
"16", "17", "27", "15", "15", "27", "8", "2", "7", "25", "14", "3", "12",
|
140
|
+
"16", "17", "20", "19", "9", "11", "1", "22", "13", "7", "7", "21", "18",
|
141
|
+
"15", "14", "18", "23", "5", "11", "17", "15", "7", "17", "17", "15", "16",
|
142
|
+
"17", "4", "10", "21", "13", "25", "0", "17", "17", "5", "15", "27", "25",
|
143
|
+
"24", "5", "0", "18", "8", "6", "25", "25", "20", "27", "21", "25", "3", "5",
|
144
|
+
"0", "13", "6", "7", "9", "7", "19", "13", "13", "4", "24", "0", "23", "17",
|
145
|
+
"0", "7", "1", "16", "4", "21", "10", "23", "6", "12", "21", "1", "5", "11",
|
146
|
+
"25", "8", "15", "26", "3", "2", "0", "22", "16", "8", "19", "16", "2", "9",
|
147
|
+
"28", "14", "9", "15", "1", "8", "18", "9", "4", "9", "19", "18", "16", "28",
|
148
|
+
"4", "10", "23", "22", "9", "21", "25", "8", "9", "16", "16", "21", "18",
|
149
|
+
"8", "20", "17", "3", "15", "23", "16", "24", "10", "10", "28", "27", "18",
|
150
|
+
"4", "25", "22", "19", "11", "2", "23" ] } ] }'
|
151
|
+
http_version:
|
152
|
+
recorded_at: Sun, 20 Jan 2013 04:21:05 GMT
|
153
|
+
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,38 @@
|
|
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, :allow_playback_repeats => true }
|
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
|
+
|
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 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
|
+
|
28
|
+
it 'should accept the start_date parameter, camelcase it and return an array of Nike::Activity' do
|
29
|
+
person.activities(:count => 1, :start_date => '2013-03-29', :end_date => '2013-03-29').should be_kind_of(NikeV2::Activities)
|
30
|
+
person.activities(:count => 1).first.should be_kind_of(NikeV2::Activity)
|
31
|
+
person.activities(:count => 1).length.should == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should calculate all the fuels' do
|
35
|
+
person.activities(:count => 1).total_fuel.should == 20491.0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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, :allow_playback_repeats => true }
|
8
|
+
after{ VCR.eject_cassette }
|
9
|
+
|
10
|
+
it 'should load the activity metrics from the api' do
|
11
|
+
activity.load_data.should be_true
|
12
|
+
activity.calories.should == 257
|
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.load_data.should be_true
|
21
|
+
activity.total_fuel_during(Time.parse('2011-08-11T00:00:00-07:00'), Time.parse('2011-08-11T01:00:00-07:00'), true).should == 883.0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Metric do
|
4
|
+
let(:activity){ build(:activity) }
|
5
|
+
|
6
|
+
describe 'fetch_data' do
|
7
|
+
before do
|
8
|
+
VCR.insert_cassette 'activity', record: :new_episodes, :allow_playback_repeats => true
|
9
|
+
activity.load_data
|
10
|
+
end
|
11
|
+
|
12
|
+
after{ VCR.eject_cassette }
|
13
|
+
|
14
|
+
it 'should build the metrics from the activity' do
|
15
|
+
metric = activity.metrics.last
|
16
|
+
metric.type.should == 'FUEL'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should give an array of values during a time range' do
|
20
|
+
metric = activity.metrics.last
|
21
|
+
metric.during(Time.at(activity.started_at.to_i + (60 * 60)), Time.at(activity.started_at.to_i + (60 * 120))).length.should == 60
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should total the values during a time range' do
|
25
|
+
metric = activity.metrics.last
|
26
|
+
metric.total_during(Time.at(activity.started_at.to_i + (60 * 60)), Time.at(activity.started_at.to_i + (60 * 120))).should == 806
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NikeV2::Metrics do
|
4
|
+
let(:activity){ build(:activity) }
|
5
|
+
|
6
|
+
describe 'fetch_data' do
|
7
|
+
before do
|
8
|
+
VCR.insert_cassette 'activity', record: :new_episodes, :allow_playback_repeats => true
|
9
|
+
activity.load_data
|
10
|
+
end
|
11
|
+
|
12
|
+
after{ VCR.eject_cassette }
|
13
|
+
|
14
|
+
it 'should build the metrics from the activity' do
|
15
|
+
activity.metrics.length.should == 2
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should sum the metrics of a given type' do
|
19
|
+
activity.metrics.total_distance.should == 6.5058
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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, :allow_playback_repeats => true }
|
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.activity_types.collect(&:to_s).include?('Fuel Band').should be_true
|
13
|
+
person.summary.fuelband.should_not be_nil
|
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
|