strava-ruby-client 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +44 -6
- data/bin/{strava-oauth-token.rb → strava-oauth-token} +0 -0
- data/bin/{strava-webhooks.rb → strava-webhooks} +0 -0
- data/lib/strava-ruby-client.rb +2 -0
- data/lib/strava/api/client.rb +1 -0
- data/lib/strava/api/endpoints/activities.rb +15 -0
- data/lib/strava/api/endpoints/oauth.rb +14 -0
- data/lib/strava/models/activity.rb +7 -19
- data/lib/strava/models/activity_total.rb +1 -1
- data/lib/strava/models/authorization.rb +7 -0
- data/lib/strava/models/explorer_segment.rb +1 -1
- data/lib/strava/models/gear.rb +1 -1
- data/lib/strava/models/mixins/distance.rb +4 -34
- data/lib/strava/models/mixins/elevation.rb +5 -14
- data/lib/strava/models/mixins/time.rb +1 -4
- data/lib/strava/models/photo.rb +10 -0
- data/lib/strava/models/route.rb +1 -1
- data/lib/strava/models/running_race.rb +1 -1
- data/lib/strava/models/segment.rb +1 -1
- data/lib/strava/models/segment_effort.rb +1 -1
- data/lib/strava/models/split.rb +0 -14
- data/lib/strava/version.rb +1 -1
- data/lib/strava/web/request.rb +3 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67660b1916a241d6029346ff2da15b8317dbb752974d1772faaba9a48a7441a8
|
4
|
+
data.tar.gz: 4dc208a403ee703bdeeca2c21d9af8fd37a9b3d7c9b851c4e328cbc382529962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17e10865286fad7301c21d51feed1482b01cf8e1fe5345f1b0cbf4b8dd66cfe5ea9351658afd09d2d2bc7f46669914240d764201b1c20f82a32dc5cd310f895f
|
7
|
+
data.tar.gz: a165b273493382cee3b1160f5b3339fda53506110bad84737af77ba4f6505b996d5e1ae0f8562b1c6a17f2b8ac8babc0ae9e44be92b066d2c0cca92f6ad0f2d9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.3.1 (2018/12/05)
|
2
|
+
|
3
|
+
* Added `Strava::Api::Client#activity_photos` - [@dblock](https://github.com/dblock).
|
4
|
+
* [#2](https://github.com/dblock/strava-ruby-client/issues/2): Added `Strava::Api::Client#deauthorize` - [@dblock](https://github.com/dblock).
|
5
|
+
* [#15](https://github.com/dblock/strava-ruby-client/issues/15): Added `strava-oauth-token` and `strava-webhooks` to gem executables - [@dblock](https://github.com/dblock).
|
6
|
+
* Fix: `Strava::Models::Activity#total_elevation_gain` no returns blank for negative and zero elevation differences - [@dblock](https://github.com/dblock).
|
7
|
+
* Fix: `Strava::Models::Split#distance` and `total_elevation_gain` incorrect for `Strava::Models::Activity#splits_standard` - [@dblock](https://github.com/dblock).
|
8
|
+
|
1
9
|
### 0.3.0 (2018/12/03)
|
2
10
|
|
3
11
|
* Added webhooks support - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -15,6 +15,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
15
15
|
- [Activities](#activities)
|
16
16
|
- [Create an Activity](#create-an-activity)
|
17
17
|
- [Get Activity](#get-activity)
|
18
|
+
- [List Activity Photos](#list-activity-photos)
|
18
19
|
- [List Activity Comments](#list-activity-comments)
|
19
20
|
- [List Activity Kudoers](#list-activity-kudoers)
|
20
21
|
- [List Activity Laps](#list-activity-laps)
|
@@ -60,6 +61,8 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
60
61
|
- [Get Upload](#get-upload)
|
61
62
|
- [Pagination](#pagination)
|
62
63
|
- [OAuth](#oauth)
|
64
|
+
- [OAuth Workflow](#oauth-workflow)
|
65
|
+
- [Deauthorize](#deauthorize)
|
63
66
|
- [Webhooks](#webhooks)
|
64
67
|
- [Configuration](#configuration)
|
65
68
|
- [Web Client Options](#web-client-options)
|
@@ -143,6 +146,29 @@ google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadm
|
|
143
146
|
|
144
147
|
See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.
|
145
148
|
|
149
|
+
#### List Activity Photos
|
150
|
+
|
151
|
+
Returns the photos on the given activity. This API is undocumented.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
|
155
|
+
|
156
|
+
photo = photos.first # => Strava::Models::Photo
|
157
|
+
|
158
|
+
photo.id # => nil
|
159
|
+
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
|
160
|
+
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
|
161
|
+
photo.athlete_id # => 26_462_176
|
162
|
+
photo.activity_id # => 1_946_417_534
|
163
|
+
photo.activity_name # => 'TCS NYC Marathon 2018'
|
164
|
+
photo.created_at # => Time
|
165
|
+
photo.uploaded_at # => Time
|
166
|
+
photo.sizes # => { '0' => [29, 64] }
|
167
|
+
photo.default_photo # => false
|
168
|
+
```
|
169
|
+
|
170
|
+
See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.
|
171
|
+
|
146
172
|
#### List Activity Comments
|
147
173
|
|
148
174
|
Returns the comments on the given activity.
|
@@ -760,7 +786,9 @@ end
|
|
760
786
|
|
761
787
|
### OAuth
|
762
788
|
|
763
|
-
|
789
|
+
#### OAuth Workflow
|
790
|
+
|
791
|
+
Obtain a redirect URL using an instance of `Strava::OAuth::Client`.
|
764
792
|
|
765
793
|
```ruby
|
766
794
|
client = Strava::OAuth::Client.new(
|
@@ -800,16 +828,26 @@ response = client.oauth_token(
|
|
800
828
|
grant_type: 'refresh_token'
|
801
829
|
)
|
802
830
|
|
803
|
-
response.access_token # new access token
|
804
|
-
response.refresh_token # new refresh token
|
805
|
-
response.expires_at # new timestamp when the access token expires
|
831
|
+
response.access_token # => String, new access token
|
832
|
+
response.refresh_token # => String, new refresh token
|
833
|
+
response.expires_at # => Time, new timestamp when the access token expires
|
834
|
+
```
|
835
|
+
|
836
|
+
#### Deauthorize
|
837
|
+
|
838
|
+
Revoke access to an athlete's data using an instance of `Strava::API::Client`.
|
839
|
+
|
840
|
+
```ruby
|
841
|
+
authorization = client.deauthorize
|
842
|
+
|
843
|
+
authorization.access_token # => String, access token being revoked
|
806
844
|
```
|
807
845
|
|
808
846
|
### Webhooks
|
809
847
|
|
810
848
|
Strava provides a [Webhook Event API](https://developers.strava.com/docs/webhooks/) that requires special access obtained by emailing [developers@strava.com](mailto:developers@strava.com).
|
811
849
|
|
812
|
-
A complete example that handles subscription creation, deletion and handling can be found in [strava-webhooks
|
850
|
+
A complete example that handles subscription creation, deletion and handling can be found in [strava-webhooks](bin/strava-webhooks). Run `strava-webhooks` to see current registrations, `strava-webhooks handle` to run an HTTP server that handles both challenges and event data, `strava-webhooks create [url]` to create a new subscription and `strava-webhooks delete [id]` to delete it.
|
813
851
|
|
814
852
|
Before creating a webhook subscription you must implement and run an HTTP server that will handle a `GET` challenge at the subscription URL.
|
815
853
|
|
@@ -997,7 +1035,7 @@ end
|
|
997
1035
|
|
998
1036
|
### Strava OAuth Token
|
999
1037
|
|
1000
|
-
Use [strava-oauth-token](bin/strava-outh-token
|
1038
|
+
Use [strava-oauth-token](bin/strava-outh-token) to obtain a token from the command-line. This will open a new browser window, navigate to Strava, request the appropriate permissions, then handle OAuth in a local redirect. The token type, refresh token, access token and token expiration will be displayed in the browser.
|
1001
1039
|
|
1002
1040
|
```bash
|
1003
1041
|
$ STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-token
|
File without changes
|
File without changes
|
data/lib/strava-ruby-client.rb
CHANGED
@@ -55,6 +55,7 @@ require_relative 'strava/models/explorer_segment'
|
|
55
55
|
require_relative 'strava/models/stream_set'
|
56
56
|
require_relative 'strava/models/stream'
|
57
57
|
require_relative 'strava/models/upload'
|
58
|
+
require_relative 'strava/models/authorization'
|
58
59
|
|
59
60
|
require_relative 'strava/web/raise_error'
|
60
61
|
require_relative 'strava/web/connection'
|
@@ -84,5 +85,6 @@ require_relative 'strava/api/endpoints/segment_efforts'
|
|
84
85
|
require_relative 'strava/api/endpoints/segments'
|
85
86
|
require_relative 'strava/api/endpoints/streams'
|
86
87
|
require_relative 'strava/api/endpoints/uploads'
|
88
|
+
require_relative 'strava/api/endpoints/oauth'
|
87
89
|
|
88
90
|
require_relative 'strava/api/client'
|
data/lib/strava/api/client.rb
CHANGED
@@ -35,6 +35,21 @@ module Strava
|
|
35
35
|
paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
|
36
36
|
end
|
37
37
|
|
38
|
+
#
|
39
|
+
# List activity photos.
|
40
|
+
#
|
41
|
+
# @option options [String] :id
|
42
|
+
# Activity id.
|
43
|
+
# @option options [Integer] :page
|
44
|
+
# Page number.
|
45
|
+
# @option options [Integer] :per_page
|
46
|
+
# Number of items per page. Defaults to 30.
|
47
|
+
#
|
48
|
+
def activity_photos(id_or_options, options = {}, &block)
|
49
|
+
id, options = parse_args(id_or_options, options)
|
50
|
+
paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
|
51
|
+
end
|
52
|
+
|
38
53
|
#
|
39
54
|
# List activity kudoers.
|
40
55
|
#
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Strava
|
2
|
+
module Api
|
3
|
+
module Endpoints
|
4
|
+
module OAuth
|
5
|
+
#
|
6
|
+
# Revoke access to an athlete's data.
|
7
|
+
#
|
8
|
+
def deauthorize(options = {})
|
9
|
+
Strava::Models::Authorization.new(post('deauthorize', { endpoint: Strava::OAuth.config.endpoint }.merge(options)))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Strava
|
2
2
|
module Models
|
3
3
|
class Activity < Model
|
4
|
-
include Mixins::
|
4
|
+
include Mixins::Distance
|
5
5
|
include Mixins::Time
|
6
6
|
include Mixins::Elevation
|
7
7
|
|
@@ -60,8 +60,8 @@ module Strava
|
|
60
60
|
property 'similar_activities', transform_with: ->(v) { Strava::Models::SimilarActivities.new(v) }
|
61
61
|
property 'embed_token'
|
62
62
|
property 'available_zones'
|
63
|
-
property 'splits_metric', transform_with: ->(v) { v.map { |r| Strava::Models::Split
|
64
|
-
property 'splits_standard', transform_with: ->(v) { v.map { |r| Strava::Models::Split
|
63
|
+
property 'splits_metric', transform_with: ->(v) { v.map { |r| Strava::Models::Split.new(r) } }
|
64
|
+
property 'splits_standard', transform_with: ->(v) { v.map { |r| Strava::Models::Split.new(r) } }
|
65
65
|
property 'laps', transform_with: ->(v) { v.map { |r| Strava::Models::Lap.new(r) } }
|
66
66
|
property 'gear', transform_with: ->(v) { Strava::Models::Gear.new(v) }
|
67
67
|
property 'device_name'
|
@@ -78,30 +78,18 @@ module Strava
|
|
78
78
|
|
79
79
|
def distance_s
|
80
80
|
if type == 'Swim'
|
81
|
-
|
82
|
-
when :metric then distance_in_meters_s
|
83
|
-
when :imperial then distance_in_yards_s
|
84
|
-
end
|
81
|
+
distance_in_meters_s
|
85
82
|
else
|
86
|
-
|
87
|
-
when :metric then distance_in_kilometers_s
|
88
|
-
when :imperial then distance_in_miles_s
|
89
|
-
end
|
83
|
+
distance_in_kilometers_s
|
90
84
|
end
|
91
85
|
end
|
92
86
|
|
93
87
|
def pace_s
|
94
88
|
case type
|
95
89
|
when 'Swim'
|
96
|
-
|
97
|
-
when :metric then pace_per_100_meters_s
|
98
|
-
when :imperial then pace_per_100_yards_s
|
99
|
-
end
|
90
|
+
pace_per_100_meters_s
|
100
91
|
else
|
101
|
-
|
102
|
-
when :metric then pace_per_kilometer_s
|
103
|
-
when :imperial then pace_per_mile_s
|
104
|
-
end
|
92
|
+
pace_per_kilometer_s
|
105
93
|
end
|
106
94
|
end
|
107
95
|
|
data/lib/strava/models/gear.rb
CHANGED
@@ -9,24 +9,15 @@ module Strava
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def distance_in_meters
|
12
|
-
|
13
|
-
when :metric then distance
|
14
|
-
when :imperial then distance / 3.28084
|
15
|
-
end
|
12
|
+
distance
|
16
13
|
end
|
17
14
|
|
18
15
|
def distance_in_feet
|
19
|
-
|
20
|
-
when :metric then distance * 3.28084
|
21
|
-
when :imperial then distance
|
22
|
-
end
|
16
|
+
distance * 3.28084
|
23
17
|
end
|
24
18
|
|
25
19
|
def distance_in_miles
|
26
|
-
|
27
|
-
when :metric then distance_in_meters * 0.00062137
|
28
|
-
when :imperial then distance_in_feet / 5280
|
29
|
-
end
|
20
|
+
distance_in_meters * 0.00062137
|
30
21
|
end
|
31
22
|
|
32
23
|
def distance_in_miles_s
|
@@ -62,28 +53,7 @@ module Strava
|
|
62
53
|
end
|
63
54
|
|
64
55
|
def distance_s
|
65
|
-
|
66
|
-
when :metric then distance_in_kilometers_s
|
67
|
-
when :imperial then distance_in_miles_s
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
module MetricDistance
|
73
|
-
extend ActiveSupport::Concern
|
74
|
-
include Strava::Models::Mixins::Distance
|
75
|
-
|
76
|
-
def units
|
77
|
-
:metric
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
module ImperialDistance
|
82
|
-
extend ActiveSupport::Concern
|
83
|
-
include Strava::Models::Mixins::Distance
|
84
|
-
|
85
|
-
def units
|
86
|
-
:imperial
|
56
|
+
distance_in_kilometers_s
|
87
57
|
end
|
88
58
|
end
|
89
59
|
end
|
@@ -9,36 +9,27 @@ module Strava
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def total_elevation_gain_in_feet
|
12
|
-
|
13
|
-
when :metric then total_elevation_gain * 3.28084
|
14
|
-
when :imperial then total_elevation_gain
|
15
|
-
end
|
12
|
+
total_elevation_gain * 3.28084
|
16
13
|
end
|
17
14
|
|
18
15
|
def total_elevation_gain_in_meters
|
19
|
-
|
20
|
-
when :metric then total_elevation_gain
|
21
|
-
when :imperial then total_elevation_gain / 3.28084
|
22
|
-
end
|
16
|
+
total_elevation_gain
|
23
17
|
end
|
24
18
|
|
25
19
|
def total_elevation_gain_in_meters_s
|
26
|
-
return
|
20
|
+
return if total_elevation_gain.nil?
|
27
21
|
|
28
22
|
format('%gm', format('%.1f', total_elevation_gain_in_meters))
|
29
23
|
end
|
30
24
|
|
31
25
|
def total_elevation_gain_in_feet_s
|
32
|
-
return
|
26
|
+
return if total_elevation_gain.nil?
|
33
27
|
|
34
28
|
format('%gft', format('%.1f', total_elevation_gain_in_feet))
|
35
29
|
end
|
36
30
|
|
37
31
|
def total_elevation_gain_s
|
38
|
-
|
39
|
-
when :metric then total_elevation_gain_in_meters_s
|
40
|
-
when :imperial then total_elevation_gain_in_feet_s
|
41
|
-
end
|
32
|
+
total_elevation_gain_in_meters_s
|
42
33
|
end
|
43
34
|
end
|
44
35
|
end
|
data/lib/strava/models/photo.rb
CHANGED
@@ -5,6 +5,16 @@ module Strava
|
|
5
5
|
property 'unique_id'
|
6
6
|
property 'urls'
|
7
7
|
property 'source'
|
8
|
+
property 'athlete_id'
|
9
|
+
property 'activity_id'
|
10
|
+
property 'activity_name'
|
11
|
+
property 'resource_state'
|
12
|
+
property 'caption'
|
13
|
+
property 'created_at', transform_with: ->(v) { Time.parse(v) }
|
14
|
+
property 'created_at_local', transform_with: ->(v) { Time.parse(v) }
|
15
|
+
property 'uploaded_at', transform_with: ->(v) { Time.parse(v) }
|
16
|
+
property 'sizes'
|
17
|
+
property 'default_photo'
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
data/lib/strava/models/route.rb
CHANGED
data/lib/strava/models/split.rb
CHANGED
@@ -10,20 +10,6 @@ module Strava
|
|
10
10
|
property 'split'
|
11
11
|
property 'average_heartrate'
|
12
12
|
property 'pace_zone'
|
13
|
-
|
14
|
-
class Standard < Split
|
15
|
-
private
|
16
|
-
|
17
|
-
def units
|
18
|
-
:imperial
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Metric < Split
|
23
|
-
def units
|
24
|
-
:metric
|
25
|
-
end
|
26
|
-
end
|
27
13
|
end
|
28
14
|
end
|
29
15
|
end
|
data/lib/strava/version.rb
CHANGED
data/lib/strava/web/request.rb
CHANGED
@@ -20,7 +20,9 @@ module Strava
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def request(method, path, options)
|
23
|
-
|
23
|
+
options = options.dup if options.key?(:request) || options.key?(:endpoint)
|
24
|
+
root = options.delete(:endpoint) || endpoint
|
25
|
+
path = [root, path].join('/')
|
24
26
|
response = connection.send(method) do |request|
|
25
27
|
case method
|
26
28
|
when :get, :delete
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strava-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -68,15 +68,17 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
description:
|
70
70
|
email: dblock@dblock.org
|
71
|
-
executables:
|
71
|
+
executables:
|
72
|
+
- strava-oauth-token
|
73
|
+
- strava-webhooks
|
72
74
|
extensions: []
|
73
75
|
extra_rdoc_files: []
|
74
76
|
files:
|
75
77
|
- CHANGELOG.md
|
76
78
|
- LICENSE.md
|
77
79
|
- README.md
|
78
|
-
- bin/strava-oauth-token
|
79
|
-
- bin/strava-webhooks
|
80
|
+
- bin/strava-oauth-token
|
81
|
+
- bin/strava-webhooks
|
80
82
|
- lib/strava-ruby-client.rb
|
81
83
|
- lib/strava/api/client.rb
|
82
84
|
- lib/strava/api/config.rb
|
@@ -85,6 +87,7 @@ files:
|
|
85
87
|
- lib/strava/api/endpoints/athletes.rb
|
86
88
|
- lib/strava/api/endpoints/clubs.rb
|
87
89
|
- lib/strava/api/endpoints/gears.rb
|
90
|
+
- lib/strava/api/endpoints/oauth.rb
|
88
91
|
- lib/strava/api/endpoints/routes.rb
|
89
92
|
- lib/strava/api/endpoints/running_races.rb
|
90
93
|
- lib/strava/api/endpoints/segment_efforts.rb
|
@@ -99,6 +102,7 @@ files:
|
|
99
102
|
- lib/strava/models/activity_total.rb
|
100
103
|
- lib/strava/models/activity_zone.rb
|
101
104
|
- lib/strava/models/athlete.rb
|
105
|
+
- lib/strava/models/authorization.rb
|
102
106
|
- lib/strava/models/club.rb
|
103
107
|
- lib/strava/models/club_admin.rb
|
104
108
|
- lib/strava/models/club_member.rb
|