strava-ruby-client 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eae71d27881be5526b289574a16cbb6897d987008f4941d8b32172f7e40971d2
4
- data.tar.gz: 8643756679123f7f0ddcd29f4755358eb27534ce48bdb0be085c080ba76c8d13
3
+ metadata.gz: cf5d841beeb197335a49b5f4ae7fa7bd79b3bf80c1a89cb3aa5bc30cfebfb2c6
4
+ data.tar.gz: bd93eaa177d2d0a8cb246044b85a925bf41048b52a3302d79c96a7457165c9d2
5
5
  SHA512:
6
- metadata.gz: 92743308394842b6b9a8d6c975141537c14dd3dc857ba5085a050dc0622855e9454b8bee9a4a3ba5e4747daf206d715e16dd75b67112a152b72a011564c99453
7
- data.tar.gz: 493fc2d1558ad057c1ed78ef77df83f175d47dd23e97cfd9502c4b11249f84e8651c8a9319552a7c16ec5ba8369ee70d7d6ed567eddd94cb1e4ea6e9fecc4979
6
+ metadata.gz: 0e043d78ea904e7c8b9f52b657ba78e10acfed435e6b29101091ba62f0eb45b1594ce9b52c51b7ca3d7b7ddf3a080d2dd95c141f3a6aa99dacc21a35466fd809
7
+ data.tar.gz: d5d736e51985381b95e30a5893bb15b0e37e1d41d71b8eab0e5e580a83ce2c95930a821e16b6621ff41d1f70bc3ec62d26b3c4fc09f0be6a96124279c24b5733
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  ### 2.2.0 (2024/9/17)
2
8
 
3
9
  * [#83](https://github.com/dblock/strava-ruby-client/pull/83): Adds back activity photos - [@dillon-co](https://github.com/dillon-co).
data/README.md CHANGED
@@ -97,6 +97,23 @@ Use an access token obtained from [My API Application](https://www.strava.com/se
97
97
  client = Strava::Api::Client.new(
98
98
  access_token: "12345678987654321"
99
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
100
117
  ```
101
118
 
102
119
  ### Activities
@@ -137,15 +154,22 @@ See [Strava::Models::Activity](lib/strava/models/activity.rb) for all available
137
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.
138
155
 
139
156
  ```ruby
157
+ require 'cgi'
158
+ require 'polylines'
159
+
140
160
  map = activity.map # => Strava::Models::Map
141
161
 
142
162
  decoded_summary_polyline = Polylines::Decoder.decode_polyline(map.summary_polyline)
143
163
  start_latlng = decoded_summary_polyline[0]
144
164
  end_latlng = decoded_summary_polyline[-1]
145
165
 
166
+ # Google Maps Static API
146
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}"
147
169
 
148
- google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{map.summary_polyline}&key=#{google_maps_api_key}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}"
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}"
149
173
  ```
150
174
 
151
175
  See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.
@@ -1098,6 +1122,12 @@ rescue Strava::Errors::Fault => e
1098
1122
  end
1099
1123
  ```
1100
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
+
1101
1131
  ## Tools
1102
1132
 
1103
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
@@ -3,17 +3,11 @@
3
3
  module Strava
4
4
  module Errors
5
5
  class RatelimitError < ::Faraday::ClientError
6
- attr_reader :http_response, :ratelimit, :error_message
6
+ attr_reader :ratelimit
7
7
 
8
- def initialize(http_response, error_message = nil)
9
- @response = http_response.response
10
- @ratelimit = Strava::Api::Ratelimit.new(@response)
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) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strava
4
- VERSION = '2.2.0'
4
+ VERSION = '2.3.0'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  module Strava
4
4
  module Web
5
5
  class RaiseResponseError < ::Faraday::Middleware
6
+ DEFAULT_OPTIONS = Faraday::Response::RaiseError::DEFAULT_OPTIONS
6
7
  CLIENT_ERROR_STATUSES = (400...600)
7
8
 
8
9
  def on_complete(env)
@@ -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, 'Too Many Requests')
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
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.2.0
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: 2024-09-17 00:00:00.000000000 Z
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
@@ -179,8 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
177
  - !ruby/object:Gem::Version
180
178
  version: '2.5'
181
179
  requirements: []
182
- rubygems_version: 3.5.11
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: []