strava-ruby-client 2.1.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +57 -1
- data/bin/strava-activities.rb +13 -0
- data/bin/strava-webhooks +1 -1
- data/lib/strava/api/endpoints/activities.rb +16 -0
- data/lib/strava/api/pagination.rb +2 -2
- data/lib/strava/errors/ratelimit_error.rb +4 -10
- data/lib/strava/models/club_event.rb +1 -0
- data/lib/strava/version.rb +1 -1
- data/lib/strava/web/raise_response_error.rb +24 -3
- data/lib/strava/web/response.rb +5 -5
- data/lib/strava/webhooks/client.rb +1 -1
- metadata +6 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf5d841beeb197335a49b5f4ae7fa7bd79b3bf80c1a89cb3aa5bc30cfebfb2c6
|
|
4
|
+
data.tar.gz: bd93eaa177d2d0a8cb246044b85a925bf41048b52a3302d79c96a7457165c9d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e043d78ea904e7c8b9f52b657ba78e10acfed435e6b29101091ba62f0eb45b1594ce9b52c51b7ca3d7b7ddf3a080d2dd95c141f3a6aa99dacc21a35466fd809
|
|
7
|
+
data.tar.gz: d5d736e51985381b95e30a5893bb15b0e37e1d41d71b8eab0e5e580a83ce2c95930a821e16b6621ff41d1f70bc3ec62d26b3c4fc09f0be6a96124279c24b5733
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
### 2.3.0 (2025/10/16)
|
|
2
|
+
|
|
3
|
+
* [#91](https://github.com/dblock/strava-ruby-client/pull/91): Respects `Faraday::Response::RaiseError::DEFAULT_OPTIONS` when raising errors - [@dblock](https://github.com/dblock).
|
|
4
|
+
* [#87](https://github.com/dblock/strava-ruby-client/pull/87): Prepares v2.3.0 by improving the event specs - [@simonneutert](https://github.com/simonneutert).
|
|
5
|
+
* [#86](https://github.com/dblock/strava-ruby-client/pull/86): Adds description to club event model - [@tobiaszwaszak](https://github.com/tobiaszwaszak).
|
|
6
|
+
|
|
7
|
+
### 2.2.0 (2024/9/17)
|
|
8
|
+
|
|
9
|
+
* [#83](https://github.com/dblock/strava-ruby-client/pull/83): Adds back activity photos - [@dillon-co](https://github.com/dillon-co).
|
|
10
|
+
* [#84](https://github.com/dblock/strava-ruby-client/pull/84): Adds back activity photos (finished PR #83) - [@simonneutert](https://github.com/simonneutert).
|
|
11
|
+
* [#85](https://github.com/dblock/strava-ruby-client/pull/85): Lays groundwork to v3.0.0 of the gem (ruby3, newest rubocop, rubocop-rake and rubocop-rspec) - [@simonneutert](https://github.com/simonneutert).
|
|
12
|
+
|
|
1
13
|
### 2.1.0 (2024/3/20)
|
|
2
14
|
|
|
3
15
|
* [#80](https://github.com/dblock/strava-ruby-client/pull/80): Removes default values for Faraday's SSL settings `ca_file` and `ca_path` - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
|
14
14
|
- [Activities](#activities)
|
|
15
15
|
- [Create an Activity](#create-an-activity)
|
|
16
16
|
- [Get Activity](#get-activity)
|
|
17
|
+
- [List Activity Photos](#list-activity-photos)
|
|
17
18
|
- [List Activity Comments](#list-activity-comments)
|
|
18
19
|
- [List Activity Kudoers](#list-activity-kudoers)
|
|
19
20
|
- [List Activity Laps](#list-activity-laps)
|
|
@@ -96,6 +97,23 @@ Use an access token obtained from [My API Application](https://www.strava.com/se
|
|
|
96
97
|
client = Strava::Api::Client.new(
|
|
97
98
|
access_token: "12345678987654321"
|
|
98
99
|
)
|
|
100
|
+
|
|
101
|
+
client.athlete # => Strava::Models::Athlete
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Note that the token from the Strava website does not have enough permissions to retrieve your own activities. Use the [strava-oauth-token tool](#strava-oauth-token) to obtain a short lived with more access scopes.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export STRAVA_CLIENT_ID=...
|
|
108
|
+
export STRAVA_CLIENT_SECRET=...
|
|
109
|
+
bundle exec ruby bin/strava-oauth-token
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Note the `access_token` from the browser window.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
export STRAVA_ACCESS_TOKEN=...
|
|
116
|
+
bundle exec ruby bin/strava-activities.rb
|
|
99
117
|
```
|
|
100
118
|
|
|
101
119
|
### Activities
|
|
@@ -136,19 +154,51 @@ See [Strava::Models::Activity](lib/strava/models/activity.rb) for all available
|
|
|
136
154
|
Use `map.summary_polyline` and combine with [polylines](https://github.com/joshuaclayton/polylines) to parse the activity map and to construct a Google maps URL with start and end markers.
|
|
137
155
|
|
|
138
156
|
```ruby
|
|
157
|
+
require 'cgi'
|
|
158
|
+
require 'polylines'
|
|
159
|
+
|
|
139
160
|
map = activity.map # => Strava::Models::Map
|
|
140
161
|
|
|
141
162
|
decoded_summary_polyline = Polylines::Decoder.decode_polyline(map.summary_polyline)
|
|
142
163
|
start_latlng = decoded_summary_polyline[0]
|
|
143
164
|
end_latlng = decoded_summary_polyline[-1]
|
|
144
165
|
|
|
166
|
+
# Google Maps Static API
|
|
145
167
|
google_maps_api_key = ENV['GOOGLE_STATIC_MAPS_API_KEY']
|
|
168
|
+
google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{CGI.escape(map.summary_polyline)}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}&key=#{google_maps_api_key}"
|
|
146
169
|
|
|
147
|
-
|
|
170
|
+
# MapBox Static API
|
|
171
|
+
mapbox_access_token = ENV['MAPBOX_ACCESS_TOKEN']
|
|
172
|
+
mapbox_image_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-5+787af2-1.0(#{CGI.escape(map.summary_polyline)}),pin-s-s+e5b22e(#{start_latlng[1]},#{start_latlng[0]}),pin-s-f+89ae00(#{end_latlng[1]},#{end_latlng[0]})/auto/800x800?access_token=#{mapbox_access_token}"
|
|
148
173
|
```
|
|
149
174
|
|
|
150
175
|
See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.
|
|
151
176
|
|
|
177
|
+
#### List Activity Photos
|
|
178
|
+
|
|
179
|
+
Returns the photos on the given activity. This API is undocumented in Strava's docs. But there is a discussion in the [strava community hub](https://communityhub.strava.com/t5/developer-discussions/download-all-photos-of-my-own-activities/m-p/11262).
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
|
|
183
|
+
# in order to request a certain size (by default it will return the biggest size possible):
|
|
184
|
+
# photos = client.activity_photos(1982980795, {size: 1920}) # => Array[Strava::Models::Photo]
|
|
185
|
+
|
|
186
|
+
photo = photos.first # => Strava::Models::Photo
|
|
187
|
+
|
|
188
|
+
photo.id # => nil
|
|
189
|
+
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
|
|
190
|
+
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
|
|
191
|
+
photo.athlete_id # => 26_462_176
|
|
192
|
+
photo.activity_id # => 1_946_417_534
|
|
193
|
+
photo.activity_name # => 'TCS NYC Marathon 2018'
|
|
194
|
+
photo.created_at # => Time
|
|
195
|
+
photo.uploaded_at # => Time
|
|
196
|
+
photo.sizes # => { '0' => [29, 64] }
|
|
197
|
+
photo.default_photo # => false
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.
|
|
201
|
+
|
|
152
202
|
#### List Activity Comments
|
|
153
203
|
|
|
154
204
|
Returns the comments on the given activity.
|
|
@@ -1072,6 +1122,12 @@ rescue Strava::Errors::Fault => e
|
|
|
1072
1122
|
end
|
|
1073
1123
|
```
|
|
1074
1124
|
|
|
1125
|
+
Faraday can optionally exclude HTTP method, path and query params from the errors raised. The client implementation options will now default to `Faraday::Response::RaiseError::DEFAULT_OPTIONS` with `include_request` set to `true`. You can change this behavior by setting `Strava::Web::RaiseResponseError::DEFAULT_OPTIONS`.
|
|
1126
|
+
|
|
1127
|
+
```ruby
|
|
1128
|
+
Strava::Web::RaiseResponseError::DEFAULT_OPTIONS = { include_request: false }
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1075
1131
|
## Tools
|
|
1076
1132
|
|
|
1077
1133
|
For a complete set of command-line tools, check out [strava-ruby-cli](https://github.com/dblock/strava-ruby-cli) built on top of this gem.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'strava-ruby-client'
|
|
4
|
+
|
|
5
|
+
access_token = ENV['STRAVA_ACCESS_TOKEN'] || raise("Missing ENV['STRAVA_ACCESS_TOKEN'].")
|
|
6
|
+
|
|
7
|
+
client = Strava::Api::Client.new(
|
|
8
|
+
access_token: access_token
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
client.athlete_activities.each do |activity|
|
|
12
|
+
puts activity.name
|
|
13
|
+
end
|
data/bin/strava-webhooks
CHANGED
|
@@ -37,6 +37,22 @@ module Strava
|
|
|
37
37
|
paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
#
|
|
41
|
+
# List activity photos.
|
|
42
|
+
#
|
|
43
|
+
# @option options [String] :id
|
|
44
|
+
# Activity id.
|
|
45
|
+
# @option options [Integer] :page
|
|
46
|
+
# Page number.
|
|
47
|
+
# @option options [Integer] :per_page
|
|
48
|
+
# Number of items per page. Defaults to 30.
|
|
49
|
+
#
|
|
50
|
+
def activity_photos(id_or_options, options = {}, &block)
|
|
51
|
+
id, options = parse_args(id_or_options, options)
|
|
52
|
+
options[:size] = 5000 unless options[:size] # to retrieve full size photos
|
|
53
|
+
paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
|
|
54
|
+
end
|
|
55
|
+
|
|
40
56
|
#
|
|
41
57
|
# List activity kudoers.
|
|
42
58
|
#
|
|
@@ -48,8 +48,8 @@ module Strava
|
|
|
48
48
|
|
|
49
49
|
private
|
|
50
50
|
|
|
51
|
-
def method_missing(method_symbol,
|
|
52
|
-
@collection.send(method_symbol,
|
|
51
|
+
def method_missing(method_symbol, ...)
|
|
52
|
+
@collection.send(method_symbol, ...)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def respond_to_missing?(method_name, include_private = false)
|
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Errors
|
|
5
5
|
class RatelimitError < ::Faraday::ClientError
|
|
6
|
-
attr_reader :
|
|
6
|
+
attr_reader :ratelimit
|
|
7
7
|
|
|
8
|
-
def initialize(
|
|
9
|
-
@
|
|
10
|
-
|
|
11
|
-
@error_message = error_message || message
|
|
12
|
-
super({
|
|
13
|
-
status: http_response.status,
|
|
14
|
-
headers: http_response.response_headers,
|
|
15
|
-
body: http_response.body
|
|
16
|
-
})
|
|
8
|
+
def initialize(env, response)
|
|
9
|
+
@ratelimit = Strava::Api::Ratelimit.new(env.response)
|
|
10
|
+
super(response)
|
|
17
11
|
end
|
|
18
12
|
|
|
19
13
|
def message
|
|
@@ -6,6 +6,7 @@ module Strava
|
|
|
6
6
|
property 'id'
|
|
7
7
|
property 'resource_state'
|
|
8
8
|
property 'title'
|
|
9
|
+
property 'description'
|
|
9
10
|
property 'club_id'
|
|
10
11
|
property 'club', transform_with: ->(c) { Strava::Models::Club.new(c) }
|
|
11
12
|
property 'organizing_athlete', transform_with: ->(oa) { Strava::Models::Athlete.new(oa) }
|
data/lib/strava/version.rb
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Web
|
|
5
5
|
class RaiseResponseError < ::Faraday::Middleware
|
|
6
|
-
|
|
6
|
+
DEFAULT_OPTIONS = Faraday::Response::RaiseError::DEFAULT_OPTIONS
|
|
7
|
+
CLIENT_ERROR_STATUSES = (400...600)
|
|
7
8
|
|
|
8
9
|
def on_complete(env)
|
|
9
10
|
case env[:status]
|
|
@@ -13,18 +14,38 @@ module Strava
|
|
|
13
14
|
# mimic the behavior that we get with proxy requests with HTTPS
|
|
14
15
|
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
|
15
16
|
when 429
|
|
16
|
-
raise Strava::Errors::RatelimitError.new(env,
|
|
17
|
+
raise Strava::Errors::RatelimitError.new(env, response_values(env))
|
|
17
18
|
when CLIENT_ERROR_STATUSES
|
|
18
19
|
raise Strava::Errors::Fault, response_values(env)
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def response_values(env)
|
|
23
|
-
{
|
|
24
|
+
response = {
|
|
24
25
|
status: env.status,
|
|
25
26
|
headers: env.response_headers,
|
|
26
27
|
body: env.body
|
|
27
28
|
}
|
|
29
|
+
|
|
30
|
+
# Include the request data by default. If the middleware was explicitly
|
|
31
|
+
# configured to _not_ include request data, then omit it.
|
|
32
|
+
return response unless options[:include_request]
|
|
33
|
+
|
|
34
|
+
response.merge(
|
|
35
|
+
request: {
|
|
36
|
+
method: env.method,
|
|
37
|
+
url: env.url,
|
|
38
|
+
url_path: env.url.path,
|
|
39
|
+
params: query_params(env),
|
|
40
|
+
headers: env.request_headers,
|
|
41
|
+
body: env.request_body
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def query_params(env)
|
|
47
|
+
env.request.params_encoder ||= Faraday::Utils.default_params_encoder
|
|
48
|
+
env.params_encoder.decode(env.url.query)
|
|
28
49
|
end
|
|
29
50
|
end
|
|
30
51
|
end
|
data/lib/strava/web/response.rb
CHANGED
|
@@ -51,10 +51,10 @@ module Strava
|
|
|
51
51
|
# @raise [NoMethodError]
|
|
52
52
|
# @return [any]
|
|
53
53
|
#
|
|
54
|
-
def operate_on_response_body!(method_symbol,
|
|
54
|
+
def operate_on_response_body!(method_symbol, ...)
|
|
55
55
|
case @response.body
|
|
56
56
|
when Hash
|
|
57
|
-
@response.body.send(method_symbol,
|
|
57
|
+
@response.body.send(method_symbol, ...)
|
|
58
58
|
else
|
|
59
59
|
raise NoMethodError
|
|
60
60
|
end
|
|
@@ -75,12 +75,12 @@ module Strava
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
def method_missing(method_symbol,
|
|
78
|
+
def method_missing(method_symbol, ...)
|
|
79
79
|
case @response
|
|
80
80
|
when Array
|
|
81
|
-
@response.send(method_symbol,
|
|
81
|
+
@response.send(method_symbol, ...)
|
|
82
82
|
else
|
|
83
|
-
operate_on_response_body!(method_symbol,
|
|
83
|
+
operate_on_response_body!(method_symbol, ...)
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
@@ -13,7 +13,7 @@ module Strava
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def request(method, path, options)
|
|
16
|
-
super
|
|
16
|
+
super(method, path, { client_id: client_id, client_secret: client_secret }.merge(options))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
#
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: strava-ruby-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Doubrovkine
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -66,7 +65,6 @@ dependencies:
|
|
|
66
65
|
- - ">="
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
69
|
-
description:
|
|
70
68
|
email: dblock@dblock.org
|
|
71
69
|
executables:
|
|
72
70
|
- strava-oauth-token
|
|
@@ -77,6 +75,7 @@ files:
|
|
|
77
75
|
- CHANGELOG.md
|
|
78
76
|
- LICENSE.md
|
|
79
77
|
- README.md
|
|
78
|
+
- bin/strava-activities.rb
|
|
80
79
|
- bin/strava-oauth-token
|
|
81
80
|
- bin/strava-webhooks
|
|
82
81
|
- lib/strava-ruby-client.rb
|
|
@@ -164,7 +163,6 @@ licenses:
|
|
|
164
163
|
- MIT
|
|
165
164
|
metadata:
|
|
166
165
|
rubygems_mfa_required: 'true'
|
|
167
|
-
post_install_message:
|
|
168
166
|
rdoc_options: []
|
|
169
167
|
require_paths:
|
|
170
168
|
- lib
|
|
@@ -172,15 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
172
170
|
requirements:
|
|
173
171
|
- - ">="
|
|
174
172
|
- !ruby/object:Gem::Version
|
|
175
|
-
version: '
|
|
173
|
+
version: '3.0'
|
|
176
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
175
|
requirements:
|
|
178
176
|
- - ">="
|
|
179
177
|
- !ruby/object:Gem::Version
|
|
180
|
-
version:
|
|
178
|
+
version: '2.5'
|
|
181
179
|
requirements: []
|
|
182
|
-
rubygems_version: 3.
|
|
183
|
-
signing_key:
|
|
180
|
+
rubygems_version: 3.6.9
|
|
184
181
|
specification_version: 4
|
|
185
182
|
summary: Strava API Ruby client.
|
|
186
183
|
test_files: []
|