mini_strava 0.1.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.
@@ -0,0 +1,103 @@
1
+ {
2
+ "id": 12,
3
+ "resource_state": 3,
4
+ "external_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
5
+ "athlete": {
6
+ "id": 101,
7
+ "resource_state": 1
8
+ },
9
+ "name": "Morning Commute",
10
+ "distance": 1850.6,
11
+ "moving_time": 443,
12
+ "elapsed_time": 443,
13
+ "total_elevation_gain": 12.6,
14
+ "type": "Ride",
15
+ "start_date": "2014-08-08T09:14:08Z",
16
+ "start_date_local": "2014-08-08T10:14:08Z",
17
+ "timezone": "(GMT+00:00) Europe/London",
18
+ "start_latlng": [50.0, -1],
19
+ "end_latlng": [52.0, -2],
20
+ "location_city": "London",
21
+ "location_state": "England",
22
+ "location_country": "United Kingdom",
23
+ "start_latitude": 50.0,
24
+ "start_longitude": -1,
25
+ "achievement_count": 0,
26
+ "comment_count": 0,
27
+ "athlete_count": 1,
28
+ "photo_count": 0,
29
+ "map": {
30
+ "id": "a177190357",
31
+ "polyline": "test-test-test",
32
+ "resource_state": 3,
33
+ "summary_polyline": "test"
34
+ },
35
+ "trainer": false,
36
+ "commute": false,
37
+ "manual": false,
38
+ "private": false,
39
+ "flagged": false,
40
+ "gear_id": "12345",
41
+ "average_speed": 4.177,
42
+ "max_speed": 13.6,
43
+ "average_watts": 70.7,
44
+ "kilojoules": 31.3,
45
+ "truncated": 183,
46
+ "has_kudoed": false,
47
+ "description": "",
48
+ "calories": 34.9,
49
+ "segment_efforts": [
50
+ {
51
+ "id": 3333,
52
+ "resource_state": 2,
53
+ "name": "Up Lower Caledonian Rd",
54
+ "activity": {
55
+ "id": 12
56
+ },
57
+ "athlete": {
58
+ "id": 101
59
+ },
60
+ "elapsed_time": 197,
61
+ "moving_time": 197,
62
+ "start_date": "2014-08-19T12:00:11Z",
63
+ "start_date_local": "2014-08-19T13:00:11Z",
64
+ "distance": 1156.0,
65
+ "start_index": 36,
66
+ "end_index": 213,
67
+ "average_watts": 135.9,
68
+ "segment": {
69
+ "id": 1364097,
70
+ "resource_state": 2,
71
+ "name": "Up Lower Caledonian Rd",
72
+ "activity_type": "Ride",
73
+ "distance": 1144.2,
74
+ "average_grade": 1.2,
75
+ "maximum_grade": 3.2,
76
+ "elevation_high": 37.0,
77
+ "elevation_low": 23.5,
78
+ "start_latlng": [51.53377859853208, -0.11831676587462425],
79
+ "end_latlng": [51.54375683516264, -0.11777026578783989],
80
+ "start_latitude": 51.53377859853208,
81
+ "start_longitude": -0.11831676587462425,
82
+ "end_latitude": 51.54375683516264,
83
+ "end_longitude": -0.11777026578783989,
84
+ "climb_category": 0,
85
+ "city": "London",
86
+ "state": "Greater London",
87
+ "country": "United Kingdom",
88
+ "private": false,
89
+ "starred": false
90
+ },
91
+ "kom_rank": null,
92
+ "pr_rank": null,
93
+ "hidden": false
94
+ }
95
+ ],
96
+ "gear": {
97
+ "id": "12345",
98
+ "primary": false,
99
+ "name": "Bike 1",
100
+ "resource_state": 2,
101
+ "distance": 270403.0
102
+ }
103
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": 1,
3
+ "resource_state": 3,
4
+ "firstname": "Foo",
5
+ "lastname": "Bar",
6
+ "profile_medium": "http://example.com/medium.jpg",
7
+ "profile": "http://example.com/profile.jpg",
8
+ "city": "London",
9
+ "state": "UK",
10
+ "country": "United Kingdom",
11
+ "sex": "M",
12
+ "friend": null,
13
+ "follower": null,
14
+ "premium": true,
15
+ "created_at": "2014-05-24T16:02:11Z",
16
+ "updated_at": "2014-08-03T00:09:09Z",
17
+ "follower_count": 5,
18
+ "friend_count": 7,
19
+ "mutual_friend_count": 0,
20
+ "date_preference": "%m/%d/%Y",
21
+ "measurement_preference": "meters",
22
+ "email": "foo@example.com",
23
+ "ftp": null,
24
+ "clubs": [],
25
+ "bikes": [{
26
+ "id": "10",
27
+ "primary": false,
28
+ "name": "Bike 1",
29
+ "resource_state": 2,
30
+ "distance": 268552.0
31
+ }, {
32
+ "id": "20",
33
+ "primary": true,
34
+ "name": "Bike 2",
35
+ "resource_state": 2,
36
+ "distance": 426398.0
37
+ }],
38
+ "shoes": [{
39
+ "id":"g449084",
40
+ "primary":true,
41
+ "name":"Nike Flex 2014 RUN Flex Blue",
42
+ "resource_state":2,
43
+ "distance":0.0}]
44
+ }
45
+
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "a1",
3
+ "primary": true,
4
+ "name": "Bike 1",
5
+ "resource_state": 3,
6
+ "distance": 428313.0,
7
+ "brand_name": "Giant",
8
+ "model_name": "TCR 1 Compact",
9
+ "frame_type": 3,
10
+ "description": "hello world"
11
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "id": 1364097,
3
+ "resource_state": 3,
4
+ "name": "Up Lower Caledonian Rd",
5
+ "activity_type": "Ride",
6
+ "distance": 1144.2,
7
+ "average_grade": 1.2,
8
+ "maximum_grade": 3.2,
9
+ "elevation_high": 37.0,
10
+ "elevation_low": 23.5,
11
+ "start_latlng": [51.53377859853208, -0.11831676587462425],
12
+ "end_latlng": [51.54375683516264, -0.11777026578783989],
13
+ "start_latitude": 51.53377859853208,
14
+ "start_longitude": -0.11831676587462425,
15
+ "end_latitude": 51.54375683516264,
16
+ "end_longitude": -0.11777026578783989,
17
+ "climb_category": 0,
18
+ "city": "London",
19
+ "state": "Greater London",
20
+ "country": "United Kingdom",
21
+ "private": false,
22
+ "starred": false,
23
+ "created_at": "2012-05-11T19:02:39Z",
24
+ "updated_at": "2014-07-05T13:02:13Z",
25
+ "total_elevation_gain": 14.9671,
26
+ "map": {
27
+ "id": "s1364097",
28
+ "polyline": "aepyHnbVaAkAiAiA{@q@e@g@]UqAGcB[k@AwASg@Ai@Lk@Fm@JuBCk@BeDBi@Je@@uCV{APcCNk@DyB^i@@c@CwB^gA^W@",
29
+ "resource_state": 3
30
+ },
31
+ "effort_count": 3976,
32
+ "athlete_count": 537,
33
+ "hazardous": false,
34
+ "star_count": 0
35
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": 33,
3
+ "resource_state": 3,
4
+ "name": "REGENTS PARK LOOP",
5
+ "activity": {
6
+ "id": 44
7
+ },
8
+ "athlete": {
9
+ "id": 55
10
+ },
11
+ "elapsed_time": 656,
12
+ "moving_time": 656,
13
+ "start_date": "2014-08-11T17:48:40Z",
14
+ "start_date_local": "2014-08-11T18:48:40Z",
15
+ "distance": 4430.1,
16
+ "start_index": 239,
17
+ "end_index": 354,
18
+ "average_watts": 104.8,
19
+ "segment": {
20
+ "id": 6694602,
21
+ "resource_state": 2,
22
+ "name": "REGENTS PARK LOOP",
23
+ "activity_type": "Ride",
24
+ "distance": 4447.6,
25
+ "average_grade": 0.0,
26
+ "maximum_grade": 6.0,
27
+ "elevation_high": 45.5,
28
+ "elevation_low": 32.0,
29
+ "start_latlng": [51.535617, -0.148373],
30
+ "end_latlng": [51.53561, -0.148366],
31
+ "start_latitude": 51.535617,
32
+ "start_longitude": -0.148373,
33
+ "end_latitude": 51.53561,
34
+ "end_longitude": -0.148366,
35
+ "climb_category": 0,
36
+ "city": "London, UK",
37
+ "state": "England",
38
+ "country": "United Kingdom",
39
+ "private": false,
40
+ "starred": false
41
+ },
42
+ "kom_rank": null,
43
+ "pr_rank": null
44
+ }
45
+
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ module MiniStrava
4
+ module Models
5
+ class TestModelBike
6
+ include MiniStrava::Model
7
+
8
+ model_attr :name
9
+ end
10
+
11
+ class TestModelAthlete
12
+ include MiniStrava::Model
13
+
14
+ model_attr :name, default: "No Name"
15
+ model_attr :bikes, type: :TestModelBike, default: []
16
+ end
17
+ end
18
+
19
+ describe Model do
20
+ context 'default types' do
21
+ it 'should set default model attribute types' do
22
+ expect(Models::TestModelBike.model_attributes).to eq([
23
+ {
24
+ name: 'name',
25
+ type: MiniStrava::Model::DefaultAttrType,
26
+ default: nil
27
+ }
28
+ ])
29
+ end
30
+
31
+ it 'should parse and use default values' do
32
+ bike = Models::TestModelBike.build({})
33
+ expect(bike.name).to eq(nil)
34
+
35
+ athlete = Models::TestModelAthlete.build({})
36
+ expect(athlete.name).to eq('No Name')
37
+ end
38
+ end
39
+
40
+ context 'Custom attribute type' do
41
+ it 'should set custom model attributes' do
42
+ expect(Models::TestModelAthlete.model_attributes).to eq([
43
+ {
44
+ name: 'name',
45
+ type: MiniStrava::Model::DefaultAttrType,
46
+ default: 'No Name'
47
+ },
48
+ {
49
+ name: 'bikes',
50
+ type: :TestModelBike,
51
+ default: []
52
+ }
53
+ ])
54
+ end
55
+
56
+ it 'should parse custom types' do
57
+ attributes = {
58
+ 'name' => 'Foo',
59
+ 'bikes' => [
60
+ {
61
+ 'name' => 'Bike 1'
62
+ }
63
+ ]
64
+ }
65
+ athlete = Models::TestModelAthlete.build attributes
66
+ expect(athlete.name).to eq('Foo')
67
+ expect(athlete.bikes.class).to eq(Array)
68
+ expect(athlete.bikes[0].name).to eq('Bike 1')
69
+ end
70
+ end
71
+
72
+ context 'Default values' do
73
+ it 'should use default values for model attributes' do
74
+ athlete = Models::TestModelAthlete.build({})
75
+ expect(athlete.bikes).to eq([])
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ module MiniStrava
4
+ module Models
5
+ describe Activity do
6
+ describe 'model attributes' do
7
+ it 'should set model attributes' do
8
+ expected = [
9
+ {
10
+ name: 'athlete',
11
+ type: :Athlete,
12
+ default: nil
13
+ },
14
+ {
15
+ name: 'segment_efforts',
16
+ type: :SegmentEffort,
17
+ default: []
18
+ },
19
+ ]
20
+
21
+ [:id, :resource_state, :external_id,
22
+ :name, :distance, :moving_time,
23
+ :elapsed_time, :total_elevation_gain,
24
+ :type, :start_date, :start_date_local,
25
+ :timezone, :start_latlng, :end_latlng,
26
+ :location_city, :location_state, :location_country,
27
+ :start_latitude, :start_longitude, :average_speed, :max_speed].each do |attr|
28
+ expected << {
29
+ name: attr.to_s,
30
+ type: Model::DefaultAttrType,
31
+ default: nil
32
+ }
33
+ end
34
+
35
+ expect(Activity.model_attributes).to match_array(expected)
36
+ end
37
+ end
38
+
39
+ describe 'build from attributes' do
40
+ subject { Activity.build parse_fixture('activity') }
41
+
42
+ it 'should set attributes values' do
43
+ expect(subject.athlete.id).to eq(101)
44
+ expect(subject.athlete.resource_state).to eq(1)
45
+ expect(subject.id).to eq(12)
46
+ expect(subject.resource_state).to eq(3)
47
+ expect(subject.external_id).to eq('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
48
+ expect(subject.name).to eq('Morning Commute')
49
+ expect(subject.distance).to eq(1850.6)
50
+ expect(subject.moving_time).to eq(443)
51
+ expect(subject.elapsed_time).to eq(443)
52
+ expect(subject.total_elevation_gain).to eq(12.6)
53
+ expect(subject.type).to eq('Ride')
54
+ expect(subject.start_date).to eq('2014-08-08T09:14:08Z')
55
+ expect(subject.start_date_local).to eq('2014-08-08T10:14:08Z')
56
+ expect(subject.timezone).to eq('(GMT+00:00) Europe/London')
57
+ expect(subject.start_latlng).to eq([50.0, -1])
58
+ expect(subject.end_latlng).to eq([52.0, -2])
59
+ expect(subject.location_city).to eq('London')
60
+ expect(subject.location_state).to eq('England')
61
+ expect(subject.location_country).to eq('United Kingdom')
62
+ expect(subject.start_latitude).to eq(50.0)
63
+ expect(subject.start_longitude).to eq(-1)
64
+ expect(subject.average_speed).to eq(4.177)
65
+ expect(subject.max_speed).to eq(13.6)
66
+
67
+ expect(subject.segment_efforts.class).to eq(Array)
68
+ expect(subject.segment_efforts.size).to eq(1)
69
+ expect(subject.segment_efforts[0].id).to eq(3333)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ module MiniStrava
4
+ module Models
5
+ describe Athlete do
6
+ describe 'model attributes' do
7
+ it 'should set model attributes' do
8
+ attributes = Athlete.model_attributes
9
+ expect(attributes).to eq([
10
+ {
11
+ name: 'id',
12
+ type: Model::DefaultAttrType,
13
+ default: nil
14
+ },
15
+ {
16
+ name: 'firstname',
17
+ type: Model::DefaultAttrType,
18
+ default: nil
19
+ },
20
+ {
21
+ name: 'lastname',
22
+ type: Model::DefaultAttrType,
23
+ default: nil
24
+ },
25
+ {
26
+ name: 'resource_state',
27
+ type: Model::DefaultAttrType,
28
+ default: nil
29
+ },
30
+ {
31
+ name: 'profile_medium',
32
+ type: Model::DefaultAttrType,
33
+ default: nil
34
+ },
35
+ {
36
+ name: 'profile',
37
+ type: Model::DefaultAttrType,
38
+ default: nil
39
+ },
40
+ {
41
+ name: 'city',
42
+ type: Model::DefaultAttrType,
43
+ default: nil
44
+ },
45
+ {
46
+ name: 'state',
47
+ type: Model::DefaultAttrType,
48
+ default: nil
49
+ },
50
+ {
51
+ name: 'country',
52
+ type: Model::DefaultAttrType,
53
+ default: nil
54
+ },
55
+ {
56
+ name: 'sex',
57
+ type: Model::DefaultAttrType,
58
+ default: nil
59
+ },
60
+ {
61
+ name: 'date_preference',
62
+ type: Model::DefaultAttrType,
63
+ default: nil
64
+ },
65
+ {
66
+ name: 'measurement_preference',
67
+ type: Model::DefaultAttrType,
68
+ default: nil
69
+ },
70
+ {
71
+ name: 'email',
72
+ type: Model::DefaultAttrType,
73
+ default: nil
74
+ },
75
+ {
76
+ name: 'bikes',
77
+ type: :Gear,
78
+ default: []
79
+ },
80
+ {
81
+ name: 'shoes',
82
+ type: :Gear,
83
+ default: []
84
+ },
85
+ ])
86
+ end
87
+ end
88
+
89
+ describe 'build from attributes' do
90
+ subject { Athlete.build parse_fixture('athlete') }
91
+
92
+ it 'should set attributes values' do
93
+ expect(subject.id).to eq(1)
94
+ expect(subject.firstname).to eq('Foo')
95
+ expect(subject.lastname).to eq('Bar')
96
+ expect(subject.profile_medium).to eq('http://example.com/medium.jpg')
97
+ expect(subject.profile).to eq('http://example.com/profile.jpg')
98
+
99
+ bikes = subject.bikes
100
+ expect(bikes.class).to eq(Array)
101
+
102
+ expect(bikes[0].class).to eq(Gear)
103
+ expect(bikes[0].id).to eq('10')
104
+ expect(bikes[0].primary).to eq(false)
105
+ expect(bikes[0].name).to eq('Bike 1')
106
+ expect(bikes[0].resource_state).to eq(2)
107
+ expect(bikes[0].distance).to eq(268552.0)
108
+
109
+ expect(bikes[1].class).to eq(Gear)
110
+ expect(bikes[1].id).to eq('20')
111
+ expect(bikes[1].primary).to eq(true)
112
+ expect(bikes[1].name).to eq('Bike 2')
113
+ expect(bikes[1].resource_state).to eq(2)
114
+ expect(bikes[1].distance).to eq(426398.0)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module MiniStrava
4
+ module Models
5
+ describe Gear do
6
+ describe 'model attributes' do
7
+ it 'should set model attributes' do
8
+ attributes = Gear.model_attributes
9
+ expect(attributes).to eq([
10
+ {
11
+ name: 'id',
12
+ type: Model::DefaultAttrType,
13
+ default: nil
14
+ },
15
+ {
16
+ name: 'primary',
17
+ type: Model::DefaultAttrType,
18
+ default: nil
19
+ },
20
+ {
21
+ name: 'name',
22
+ type: Model::DefaultAttrType,
23
+ default: nil
24
+ },
25
+ {
26
+ name: 'resource_state',
27
+ type: Model::DefaultAttrType,
28
+ default: nil
29
+ },
30
+ {
31
+ name: 'distance',
32
+ type: Model::DefaultAttrType,
33
+ default: nil
34
+ },
35
+ {
36
+ name: 'brand_name',
37
+ type: Model::DefaultAttrType,
38
+ default: nil
39
+ },
40
+ {
41
+ name: 'model_name',
42
+ type: Model::DefaultAttrType,
43
+ default: nil
44
+ },
45
+ {
46
+ name: 'frame_type',
47
+ type: Model::DefaultAttrType,
48
+ default: nil
49
+ },
50
+ {
51
+ name: 'description',
52
+ type: Model::DefaultAttrType,
53
+ default: nil
54
+ }
55
+ ])
56
+ end
57
+ end
58
+
59
+ describe 'build from attributes' do
60
+ subject { Gear.build parse_fixture('gear') }
61
+
62
+ it 'should set attributes values' do
63
+ expect(subject.id).to eq('a1')
64
+ expect(subject.primary).to eq(true)
65
+ expect(subject.resource_state).to eq(3)
66
+ expect(subject.distance).to eq(428313.0)
67
+ expect(subject.brand_name).to eq('Giant')
68
+ expect(subject.model_name).to eq('TCR 1 Compact')
69
+ expect(subject.frame_type).to eq(3)
70
+ expect(subject.description).to eq('hello world')
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ module MiniStrava
4
+ module Models
5
+ describe SegmentEffort do
6
+ describe 'model attributes' do
7
+ it 'should set model attributes' do
8
+ expected = [
9
+ {
10
+ name: 'activity',
11
+ type: :Activity,
12
+ default: nil
13
+ },
14
+ {
15
+ name: 'athlete',
16
+ type: :Athlete,
17
+ default: nil
18
+ },
19
+ {
20
+ name: 'segment',
21
+ type: :Segment,
22
+ default: nil
23
+ }
24
+ ]
25
+
26
+ [
27
+ :id, :resource_state, :name,
28
+ :elapsed_time, :moving_time, :start_date,
29
+ :start_date_local, :distance
30
+ ].each do |attr|
31
+ expected << {
32
+ name: attr.to_s,
33
+ type: Model::DefaultAttrType,
34
+ default: nil
35
+ }
36
+ end
37
+
38
+ expect(SegmentEffort.model_attributes).to match_array(expected)
39
+ end
40
+ end
41
+
42
+ describe 'build from attributes' do
43
+ subject { SegmentEffort.build parse_fixture('segment_effort') }
44
+
45
+ it 'should set attributes values' do
46
+ expect(subject.id).to eq(33)
47
+ expect(subject.resource_state).to eq(3)
48
+ expect(subject.name).to eq('REGENTS PARK LOOP')
49
+ expect(subject.elapsed_time).to eq(656)
50
+ expect(subject.moving_time).to eq(656)
51
+ expect(subject.start_date).to eq('2014-08-11T17:48:40Z')
52
+ expect(subject.start_date_local).to eq('2014-08-11T18:48:40Z')
53
+ expect(subject.distance).to eq(4430.1)
54
+
55
+ expect(subject.activity.class).to eq(Activity)
56
+ expect(subject.activity.id).to eq(44)
57
+
58
+ expect(subject.athlete.class).to eq(Athlete)
59
+ expect(subject.athlete.id).to eq(55)
60
+
61
+ expect(subject.segment.class).to eq(Segment)
62
+ expect(subject.segment.id).to eq(6694602)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end