Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-02-02 03:09:26 UTC using RuboCop version 1.68.0.
# on 2025-10-16 14:15:33 UTC using RuboCop version 1.68.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: (?-mix:(exactly|at_least|at_most)\(\d+\)\.times)
Lint/UnreachableLoop:
RSpec/AnyInstance:
Exclude:
- 'bin/strava-activities.rb'

# Offense count: 13
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/strava/models/athlete_spec.rb'
- 'spec/strava/oauth/client_spec.rb'
- 'spec/strava/webhooks/client_spec.rb'

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/strava/api/client/endpoints/activities/activity_spec.rb'
- 'spec/strava/api/client_spec.rb'

# Offense count: 5
# Configuration parameters: AllowedGroups.
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### 2.3.0 (Next)

* [#91](https://github.com/dblock/strava-ruby-client/pull/91): Respects `Faraday::Response::RaiseError::DEFAULT_OPTIONS` when raising errors - [@dblock](https://github.com/dblock).
* [#87](https://github.com/dblock/strava-ruby-client/pull/87): Prepares v2.3.0 by improving the event specs - [@simonneutert](https://github.com/simonneutert).
* [#86](https://github.com/dblock/strava-ruby-client/pull/86): Add description to club event model - [@tobiaszwaszak](https://github.com/tobiaszwaszak).
* [#86](https://github.com/dblock/strava-ruby-client/pull/86): Adds description to club event model - [@tobiaszwaszak](https://github.com/tobiaszwaszak).
* Your contribution here.

### 2.2.0 (2024/9/17)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'http://rubygems.org'
gemspec

group :development, :test do
gem 'csv'
gem 'dotenv'
gem 'faraday-retry'
gem 'gpx'
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,12 @@ rescue Strava::Errors::Fault => e
end
```

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`.

```ruby
Strava::Web::RaiseResponseError::DEFAULT_OPTIONS = { include_request: false }
```

## Tools

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.
Expand Down
12 changes: 11 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Upgrading Strava-Ruby-Client

### Upgrading to >= 2.3.0

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`.

```ruby
Strava::Web::RaiseResponseError::DEFAULT_OPTIONS = { include_request: false }
```

See [#91](https://github.com/dblock/strava-ruby-client/pull/91) for details.

### Upgrading to >= 2.2.0

Support for Ruby 2.x has been dropped. The minimum required Ruby version is now 3.0.0.
Expand Down Expand Up @@ -45,4 +55,4 @@ client = Strava::Api::Client.new(ca_file: OpenSSL::X509::DEFAULT_CERT_FILE, ca_p

The library was upgraded to require Faraday 1.0 or newer. Change all references to `Faraday::Error::ResourceNotFound` or `Faraday::Error::ConnectionFailed` to `Faraday::ConnectionFailed` and `Faraday::ResourceNotFound` respectively.

See [#30](https://github.com/dblock/strava-ruby-client/pull/30) for more details.
See [#30](https://github.com/dblock/strava-ruby-client/pull/30) for details.
14 changes: 4 additions & 10 deletions lib/strava/errors/ratelimit_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
module Strava
module Errors
class RatelimitError < ::Faraday::ClientError
attr_reader :http_response, :ratelimit, :error_message
attr_reader :ratelimit

def initialize(http_response, error_message = nil)
@response = http_response.response
@ratelimit = Strava::Api::Ratelimit.new(@response)
@error_message = error_message || message
super({
status: http_response.status,
headers: http_response.response_headers,
body: http_response.body
})
def initialize(env, response)
@ratelimit = Strava::Api::Ratelimit.new(env.response)
super(response)
end

def message
Expand Down
25 changes: 23 additions & 2 deletions lib/strava/web/raise_response_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Strava
module Web
class RaiseResponseError < ::Faraday::Middleware
DEFAULT_OPTIONS = Faraday::Response::RaiseError::DEFAULT_OPTIONS
CLIENT_ERROR_STATUSES = (400...600)

def on_complete(env)
Expand All @@ -13,18 +14,38 @@ def on_complete(env)
# mimic the behavior that we get with proxy requests with HTTPS
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
when 429
raise Strava::Errors::RatelimitError.new(env, 'Too Many Requests')
raise Strava::Errors::RatelimitError.new(env, response_values(env))
when CLIENT_ERROR_STATUSES
raise Strava::Errors::Fault, response_values(env)
end
end

def response_values(env)
{
response = {
status: env.status,
headers: env.response_headers,
body: env.body
}

# Include the request data by default. If the middleware was explicitly
# configured to _not_ include request data, then omit it.
return response unless options[:include_request]

response.merge(
request: {
method: env.method,
url: env.url,
url_path: env.url.path,
params: query_params(env),
headers: env.request_headers,
body: env.request_body
}
)
end

def query_params(env)
env.request.params_encoder ||= Faraday::Utils.default_params_encoder
env.params_encoder.decode(env.url.query)
end
end
end
Expand Down
Loading