strava-ruby-client 3.0.0 → 3.2.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.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +44 -995
  4. data/bin/strava-webhooks +50 -38
  5. data/lib/strava/api/client.rb +69 -0
  6. data/lib/strava/api/config.rb +40 -0
  7. data/lib/strava/api/cursor.rb +32 -1
  8. data/lib/strava/api/endpoints/activities.rb +197 -57
  9. data/lib/strava/api/endpoints/athletes.rb +64 -8
  10. data/lib/strava/api/endpoints/clubs.rb +24 -59
  11. data/lib/strava/api/endpoints/gears.rb +11 -2
  12. data/lib/strava/api/endpoints/oauth.rb +45 -0
  13. data/lib/strava/api/endpoints/routes.rb +20 -13
  14. data/lib/strava/api/endpoints/segment_efforts.rb +15 -8
  15. data/lib/strava/api/endpoints/segments.rb +74 -21
  16. data/lib/strava/api/endpoints/streams.rb +22 -18
  17. data/lib/strava/api/endpoints/uploads.rb +12 -2
  18. data/lib/strava/api/pagination.rb +26 -2
  19. data/lib/strava/api/ratelimit.rb +34 -0
  20. data/lib/strava/deep_copyable.rb +20 -1
  21. data/lib/strava/errors/fault.rb +32 -0
  22. data/lib/strava/errors/ratelimit_error.rb +35 -0
  23. data/lib/strava/errors/upload_error.rb +55 -0
  24. data/lib/strava/logger.rb +27 -0
  25. data/lib/strava/models/achievement.rb +28 -1
  26. data/lib/strava/models/activity_stats.rb +47 -1
  27. data/lib/strava/models/activity_total.rb +32 -1
  28. data/lib/strava/models/activity_zone.rb +46 -2
  29. data/lib/strava/models/authorization.rb +13 -0
  30. data/lib/strava/models/base_stream.rb +22 -1
  31. data/lib/strava/models/club_event.rb +66 -3
  32. data/lib/strava/models/comment.rb +40 -2
  33. data/lib/strava/models/destination.rb +28 -1
  34. data/lib/strava/models/detailed_activity.rb +211 -3
  35. data/lib/strava/models/detailed_athlete.rb +106 -4
  36. data/lib/strava/models/detailed_club.rb +76 -2
  37. data/lib/strava/models/detailed_gear.rb +45 -2
  38. data/lib/strava/models/detailed_photo.rb +64 -4
  39. data/lib/strava/models/detailed_photos.rb +36 -1
  40. data/lib/strava/models/detailed_segment.rb +98 -4
  41. data/lib/strava/models/detailed_segment_effort.rb +93 -4
  42. data/lib/strava/models/explorer_segment.rb +55 -2
  43. data/lib/strava/models/heart_rate_zone_ranges.rb +29 -1
  44. data/lib/strava/models/kudoser.rb +29 -1
  45. data/lib/strava/models/lap.rb +63 -3
  46. data/lib/strava/models/lat_lng.rb +42 -4
  47. data/lib/strava/models/local_legend.rb +41 -1
  48. data/lib/strava/models/map.rb +31 -0
  49. data/lib/strava/models/meta_activity.rb +15 -2
  50. data/lib/strava/models/meta_athlete.rb +17 -2
  51. data/lib/strava/models/meta_club.rb +15 -1
  52. data/lib/strava/models/mixins/average_speed.rb +81 -3
  53. data/lib/strava/models/mixins/distance.rb +25 -0
  54. data/lib/strava/models/mixins/elapsed_time.rb +18 -0
  55. data/lib/strava/models/mixins/elevation_difference.rb +42 -0
  56. data/lib/strava/models/mixins/elevation_gain.rb +39 -0
  57. data/lib/strava/models/mixins/estimated_moving_time.rb +18 -0
  58. data/lib/strava/models/mixins/http_response.rb +36 -0
  59. data/lib/strava/models/mixins/moving_time.rb +18 -0
  60. data/lib/strava/models/mixins/sport_type.rb +39 -1
  61. data/lib/strava/models/mixins/start_date_local.rb +41 -25
  62. data/lib/strava/models/mixins/time_in_hours.rb +23 -0
  63. data/lib/strava/models/mixins/total_elevation_gain.rb +42 -0
  64. data/lib/strava/models/model.rb +29 -0
  65. data/lib/strava/models/photos_summary.rb +33 -2
  66. data/lib/strava/models/photos_summary_primary.rb +28 -2
  67. data/lib/strava/models/power_zone_ranges.rb +23 -1
  68. data/lib/strava/models/response.rb +18 -0
  69. data/lib/strava/models/route.rb +72 -4
  70. data/lib/strava/models/similar_activities.rb +57 -1
  71. data/lib/strava/models/split.rb +27 -2
  72. data/lib/strava/models/stats_visibility.rb +24 -1
  73. data/lib/strava/models/stream.rb +107 -0
  74. data/lib/strava/models/stream_set.rb +52 -1
  75. data/lib/strava/models/summary_activity.rb +153 -3
  76. data/lib/strava/models/summary_athlete.rb +56 -3
  77. data/lib/strava/models/summary_club.rb +61 -2
  78. data/lib/strava/models/summary_gear.rb +31 -2
  79. data/lib/strava/models/summary_pr_segment_effort.rb +32 -2
  80. data/lib/strava/models/summary_segment.rb +81 -3
  81. data/lib/strava/models/summary_segment_effort.rb +33 -2
  82. data/lib/strava/models/timed_zone_range.rb +38 -1
  83. data/lib/strava/models/token.rb +31 -0
  84. data/lib/strava/models/trend.rb +38 -1
  85. data/lib/strava/models/updatable_activity.rb +36 -1
  86. data/lib/strava/models/upload.rb +50 -1
  87. data/lib/strava/models/waypoint.rb +31 -1
  88. data/lib/strava/models/xoms.rb +35 -1
  89. data/lib/strava/models/zone_range.rb +34 -1
  90. data/lib/strava/models/zones.rb +32 -1
  91. data/lib/strava/oauth/client.rb +107 -19
  92. data/lib/strava/oauth/config.rb +41 -0
  93. data/lib/strava/version.rb +1 -1
  94. data/lib/strava/web/api_response.rb +28 -2
  95. data/lib/strava/web/client.rb +73 -3
  96. data/lib/strava/web/config.rb +44 -0
  97. data/lib/strava/web/connection.rb +46 -2
  98. data/lib/strava/web/filter.rb +72 -0
  99. data/lib/strava/web/log_formatter.rb +20 -0
  100. data/lib/strava/web/raise_response_error.rb +73 -9
  101. data/lib/strava/web/request.rb +56 -0
  102. data/lib/strava/web/response.rb +30 -29
  103. data/lib/strava/webhooks/client.rb +108 -7
  104. data/lib/strava/webhooks/config.rb +44 -0
  105. data/lib/strava/webhooks/models/challenge.rb +40 -0
  106. data/lib/strava/webhooks/models/event.rb +58 -0
  107. data/lib/strava/webhooks/models/subscription.rb +29 -2
  108. data/lib/strava-ruby-client.rb +2 -2
  109. metadata +7 -11
  110. data/lib/strava/models/club_activity.rb +0 -22
  111. data/lib/strava/models/club_athlete.rb +0 -21
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strava
4
- VERSION = '3.0.0'
4
+ VERSION = '3.2.0'
5
5
  end
@@ -2,11 +2,37 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # Wraps an HTTP response with rate limit information.
7
+ #
8
+ # This class provides access to both the raw HTTP response and
9
+ # parsed rate limit data from the response headers.
10
+ #
11
+ # @see Strava::Api::Ratelimit
12
+ # @see Strava::Models::Mixins::HttpResponse
13
+ #
14
+ # @example Accessing response data
15
+ # activity = client.activity(1234567890)
16
+ # api_response = activity.http_response
17
+ #
18
+ # # Access raw HTTP response
19
+ # status = api_response.response.status
20
+ # headers = api_response.response.headers
21
+ #
22
+ # # Access rate limit information
23
+ # puts "Requests remaining: #{api_response.ratelimit.fifteen_minutes_remaining}"
24
+ #
5
25
  class ApiResponse
6
- attr_accessor :response, :ratelimit
26
+ # @return [Faraday::Response] The raw HTTP response
27
+ attr_accessor :response
7
28
 
29
+ # @return [Strava::Api::Ratelimit] Rate limit information extracted from response headers
30
+ attr_accessor :ratelimit
31
+
32
+ #
33
+ # Initialize a new ApiResponse with an HTTP response.
8
34
  #
9
- # @param [Faraday::Response] http_response
35
+ # @param http_response [Faraday::Response] HTTP response from the Strava API
10
36
  #
11
37
  def initialize(http_response)
12
38
  @response = http_response
@@ -2,39 +2,109 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # Base web client class for making HTTP requests to Strava APIs.
7
+ #
8
+ # This class provides the foundation for all Strava client implementations
9
+ # (API, OAuth, and Webhooks clients). It handles HTTP connection management,
10
+ # request execution, and configuration management.
11
+ #
12
+ # The client includes mixins for connection handling and HTTP request methods,
13
+ # and manages configuration attributes like endpoint URLs, user agents, and
14
+ # authentication tokens.
15
+ #
16
+ # @see Strava::Web::Connection
17
+ # @see Strava::Web::Request
18
+ #
5
19
  class Client
6
20
  include Strava::Web::Connection
7
21
  include Strava::Web::Request
8
22
 
9
23
  attr_accessor(*Config::ATTRIBUTES)
10
24
 
25
+ #
26
+ # Initialize a new client instance.
27
+ #
28
+ # @param options [Hash] Configuration options for the client
29
+ # @option options [String] :endpoint The API endpoint URL
30
+ # @option options [String] :user_agent The user agent string
31
+ # @option options [String] :token The access token for authentication
32
+ # @option options [Logger] :logger Custom logger instance
33
+ #
11
34
  def initialize(options = {})
12
35
  Strava::Web::Config::ATTRIBUTES.each do |key|
13
- send("#{key}=", options[key] || Strava::Web.config.send(key))
36
+ send("#{key}=", options[key].nil? ? Strava::Web.config.send(key) : options[key])
14
37
  end
15
38
  @logger ||= Strava::Logger.logger
16
39
  end
17
40
 
41
+ #
42
+ # Returns the API endpoint URL for this client.
43
+ #
44
+ # @note This method must be implemented by subclasses
45
+ # @raise [NotImplementedError] if not implemented by subclass
46
+ # @return [String] The API endpoint URL
47
+ #
18
48
  def endpoint
19
49
  raise NotImplementedError
20
50
  end
21
51
 
22
52
  class << self
53
+ #
54
+ # Configure the client with a block or return the configuration.
55
+ #
56
+ # @yield [Config] Yields the configuration module for setup
57
+ # @return [Module] The Config module
58
+ #
59
+ # @example Configure the client
60
+ # Strava::Web::Client.configure do |config|
61
+ # config.endpoint = 'https://www.strava.com/api/v3'
62
+ # end
63
+ #
23
64
  def configure
24
65
  block_given? ? yield(Config) : Config
25
66
  end
26
67
 
68
+ #
69
+ # Returns the current configuration.
70
+ #
71
+ # @return [Module] The Config module
72
+ #
27
73
  def config
28
74
  Config
29
75
  end
30
76
  end
31
77
 
78
+ #
79
+ # Parse method arguments that can be either (id, options) or (options).
80
+ #
81
+ # This helper method standardizes the common pattern where Strava API methods
82
+ # accept either a resource ID as the first parameter followed by an options hash,
83
+ # or just an options hash containing an :id key.
84
+ #
85
+ # @param id_or_options [String, Integer, Hash] Either a resource ID or options hash
86
+ # @param options [Hash] Options hash (when first param is an ID)
87
+ #
88
+ # @raise [ArgumentError] if the :id is missing from the options hash
89
+ #
90
+ # @return [Array<(String, Hash)>] Tuple of [id, options]
91
+ #
92
+ # @example With separate ID and options
93
+ # parse_args('12345', {per_page: 10})
94
+ # # => ['12345', {per_page: 10}]
95
+ #
96
+ # @example With ID in options hash
97
+ # parse_args({id: '12345', per_page: 10})
98
+ # # => ['12345', {per_page: 10}]
99
+ #
32
100
  def parse_args(id_or_options, options = {})
33
101
  if id_or_options.is_a?(Hash)
34
- throw ArgumentError.new('Required argument :id missing') if id_or_options[:id].nil?
102
+ raise ArgumentError, 'Required argument :id missing' if id_or_options[:id].nil?
103
+
35
104
  [id_or_options[:id], id_or_options.except(:id)]
36
105
  else
37
- throw ArgumentError.new('Required argument :id missing') if id_or_options.nil?
106
+ raise ArgumentError, 'Required argument :id missing' if id_or_options.nil?
107
+
38
108
  [id_or_options, options]
39
109
  end
40
110
  end
@@ -2,9 +2,24 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # Configuration module for web client HTTP settings.
7
+ #
8
+ # This module manages HTTP-related configuration settings shared across
9
+ # all Strava web clients (API, OAuth, Webhooks), including proxy settings,
10
+ # SSL certificate validation, timeouts, and logging.
11
+ #
12
+ # @example Configure web client settings
13
+ # Strava::Web.configure do |config|
14
+ # config.user_agent = 'MyApp/1.0'
15
+ # config.timeout = 30
16
+ # config.logger = Logger.new(STDOUT)
17
+ # end
18
+ #
5
19
  module Config
6
20
  extend self
7
21
 
22
+ # @return [Array<Symbol>] List of configurable HTTP attributes
8
23
  ATTRIBUTES = %i[
9
24
  proxy
10
25
  user_agent
@@ -13,10 +28,20 @@ module Strava
13
28
  logger
14
29
  timeout
15
30
  open_timeout
31
+ filter_credentials
32
+ log_formatter
16
33
  ].freeze
17
34
 
18
35
  attr_accessor(*Config::ATTRIBUTES)
19
36
 
37
+ #
38
+ # Reset configuration to default values.
39
+ #
40
+ # Sets the user agent to the default client identifier and clears
41
+ # all optional settings (proxy, SSL certificates, timeouts, logger).
42
+ #
43
+ # @return [void]
44
+ #
20
45
  def reset
21
46
  self.user_agent = "Strava Ruby Client/#{Strava::VERSION}"
22
47
  self.ca_path = nil
@@ -25,14 +50,33 @@ module Strava
25
50
  self.logger = nil
26
51
  self.timeout = nil
27
52
  self.open_timeout = nil
53
+ self.filter_credentials = true
54
+ self.log_formatter = nil
28
55
  end
29
56
  end
30
57
 
31
58
  class << self
59
+ #
60
+ # Configure the web client with a block.
61
+ #
62
+ # @yield [Config] Yields the configuration module for setup
63
+ # @return [Module] The Config module
64
+ #
65
+ # @example
66
+ # Strava::Web.configure do |config|
67
+ # config.proxy = 'http://proxy.example.com:8080'
68
+ # config.ca_file = '/path/to/ca-bundle.crt'
69
+ # end
70
+ #
32
71
  def configure
33
72
  block_given? ? yield(Config) : Config
34
73
  end
35
74
 
75
+ #
76
+ # Returns the current web client configuration.
77
+ #
78
+ # @return [Module] The Config module
79
+ #
36
80
  def config
37
81
  Config
38
82
  end
@@ -2,13 +2,52 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # HTTP connection management for Strava web clients.
7
+ #
8
+ # This module provides connection handling and configuration for making HTTP
9
+ # requests to Strava APIs. It sets up a Faraday connection with proper headers,
10
+ # middleware, SSL configuration, and timeout settings.
11
+ #
12
+ # The connection is configured with:
13
+ # - JSON request and response handling
14
+ # - Automatic error raising for failed responses
15
+ # - Optional logging
16
+ # - SSL certificate validation
17
+ # - Request timeouts
18
+ #
19
+ # @api private
20
+ #
5
21
  module Connection
6
22
  private
7
23
 
24
+ #
25
+ # Returns HTTP headers to be included in requests.
26
+ #
27
+ # This method can be overridden in including classes to provide
28
+ # custom headers (e.g., authentication headers).
29
+ #
30
+ # @api private
31
+ # @return [Hash] HTTP headers hash
32
+ #
8
33
  def headers
9
34
  {}
10
35
  end
11
36
 
37
+ #
38
+ # Establishes and returns a Faraday HTTP connection.
39
+ #
40
+ # Creates a memoized Faraday connection configured with:
41
+ # - Base endpoint URL
42
+ # - Custom headers including Accept and User-Agent
43
+ # - Proxy settings if configured
44
+ # - SSL certificate paths
45
+ # - Request timeouts
46
+ # - Middleware stack for multipart, URL encoding, error handling, and JSON parsing
47
+ #
48
+ # @api private
49
+ # @return [Faraday::Connection] Configured Faraday connection instance
50
+ #
12
51
  def connection
13
52
  @connection ||= begin
14
53
  options = {
@@ -27,9 +66,14 @@ module Strava
27
66
  ::Faraday::Connection.new(endpoint, options) do |connection|
28
67
  connection.request :multipart
29
68
  connection.request :url_encoded
30
- connection.use Strava::Web::RaiseResponseError
69
+ connection.use Strava::Web::RaiseResponseError, filter_credentials: filter_credentials
31
70
  connection.response :json
32
- connection.response :logger, logger if logger
71
+ if logger
72
+ logger_options = log_formatter ? { formatter: log_formatter } : {}
73
+ connection.response(:logger, logger, **logger_options) do |formatter|
74
+ Strava::Web::Filter.logger(formatter) if filter_credentials
75
+ end
76
+ end
33
77
  connection.adapter ::Faraday.default_adapter
34
78
  end
35
79
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strava
4
+ module Web
5
+ #
6
+ # Filters credentials, such as client secrets and tokens, out of request
7
+ # data that is logged or included in errors.
8
+ #
9
+ module Filter
10
+ extend self
11
+
12
+ # @return [String] Replacement for filtered values
13
+ FILTERED = 'FILTERED'
14
+
15
+ # @return [Array<String>] Names of parameters that contain credentials
16
+ PARAMS = %w[client_secret access_token refresh_token code].freeze
17
+
18
+ # @return [Regexp] Matches credential parameters in URLs, query strings and form bodies
19
+ PARAMS_PATTERN = /(\b(?:#{PARAMS.join('|')})=)[^&\s"]+/
20
+
21
+ # @return [Regexp] Matches an Authorization header value in logs
22
+ AUTHORIZATION_PATTERN = /(Authorization: "?(?:Bearer|Basic) )[^"\s]+/i
23
+
24
+ #
25
+ # Configures a Faraday logging formatter to filter credentials.
26
+ #
27
+ # @param formatter [Faraday::Logging::Formatter]
28
+ # @return [void]
29
+ #
30
+ def logger(formatter)
31
+ formatter.filter(PARAMS_PATTERN, "\\1#{FILTERED}")
32
+ formatter.filter(AUTHORIZATION_PATTERN, "\\1#{FILTERED}")
33
+ end
34
+
35
+ #
36
+ # @param value [String, URI, nil] URL, query string or form body
37
+ # @return [String, nil] value with credential parameters filtered
38
+ #
39
+ def string(value)
40
+ value&.to_s&.gsub(PARAMS_PATTERN, "\\1#{FILTERED}")
41
+ end
42
+
43
+ #
44
+ # @param params [Hash, nil] request parameters
45
+ # @return [Hash, nil] params with credential values filtered
46
+ #
47
+ def params(params)
48
+ params&.to_h { |key, value| [key, PARAMS.include?(key.to_s) ? FILTERED : value] }
49
+ end
50
+
51
+ #
52
+ # @param headers [Hash, nil] request headers
53
+ # @return [Hash, nil] headers with the Authorization value filtered
54
+ #
55
+ def headers(headers)
56
+ headers&.to_h { |key, value| [key, key.to_s.casecmp?('Authorization') ? FILTERED : value] }
57
+ end
58
+
59
+ #
60
+ # @param body [String, Hash, Object, nil] request body
61
+ # @return [String, Hash, Object, nil] body with credential values filtered
62
+ #
63
+ def body(body)
64
+ case body
65
+ when String then string(body)
66
+ when Hash then params(body)
67
+ else body
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday/logging/formatter'
4
+
5
+ module Strava
6
+ module Web
7
+ #
8
+ # Formats request and response logs, adding a blank line after headers
9
+ # to separate them from the next log entry.
10
+ #
11
+ class LogFormatter < ::Faraday::Logging::Formatter
12
+ private
13
+
14
+ def dump_headers(headers)
15
+ dumped = super
16
+ "#{dumped}\n" if dumped
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,10 +2,41 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # Faraday middleware that raises exceptions for HTTP error responses.
7
+ #
8
+ # This middleware intercepts HTTP responses and raises appropriate exceptions
9
+ # based on the status code. It handles common HTTP error statuses and maps them
10
+ # to specific Strava error classes, including special handling for rate limiting
11
+ # (429) and resource not found (404) responses.
12
+ #
13
+ # @see Faraday::Middleware
14
+ # @see Strava::Errors::Fault
15
+ # @see Strava::Errors::RatelimitError
16
+ #
5
17
  class RaiseResponseError < ::Faraday::Middleware
18
+ # @return [Hash] Default options inherited from Faraday's RaiseError middleware
6
19
  DEFAULT_OPTIONS = Faraday::Response::RaiseError::DEFAULT_OPTIONS
20
+
21
+ # @return [Range] HTTP status codes that are considered client errors (400-599)
7
22
  CLIENT_ERROR_STATUSES = (400...600)
8
23
 
24
+ #
25
+ # Callback invoked when an HTTP response is complete.
26
+ #
27
+ # Examines the HTTP status code and raises appropriate exceptions:
28
+ # - 404: Faraday::ResourceNotFound
29
+ # - 407: Faraday::ConnectionFailed (proxy authentication required)
30
+ # - 429: Strava::Errors::RatelimitError (rate limit exceeded)
31
+ # - 400-599: Strava::Errors::Fault (general client/server errors)
32
+ #
33
+ # @param env [Faraday::Env] The Faraday request/response environment
34
+ # @raise [Faraday::ResourceNotFound] When resource is not found (404)
35
+ # @raise [Faraday::ConnectionFailed] When proxy authentication fails (407)
36
+ # @raise [Strava::Errors::RatelimitError] When rate limit is exceeded (429)
37
+ # @raise [Strava::Errors::Fault] For other client/server errors (400-599)
38
+ # @return [void]
39
+ #
9
40
  def on_complete(env)
10
41
  case env[:status]
11
42
  when 404
@@ -20,6 +51,16 @@ module Strava
20
51
  end
21
52
  end
22
53
 
54
+ #
55
+ # Extracts response values from the Faraday environment.
56
+ #
57
+ # Builds a hash containing response information (status, headers, body)
58
+ # and optionally includes request details if the middleware is configured
59
+ # with `include_request: true`.
60
+ #
61
+ # @param env [Faraday::Env] The Faraday request/response environment
62
+ # @return [Hash] Response values including status, headers, body, and optionally request details
63
+ #
23
64
  def response_values(env)
24
65
  response = {
25
66
  status: env.status,
@@ -31,18 +72,41 @@ module Strava
31
72
  # configured to _not_ include request data, then omit it.
32
73
  return response unless options[:include_request]
33
74
 
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
- }
75
+ response.merge(request: request_values(env))
76
+ end
77
+
78
+ #
79
+ # Extracts request values from the Faraday environment, filtering
80
+ # credentials unless the middleware is configured with `filter_credentials: false`.
81
+ #
82
+ # @param env [Faraday::Env] The Faraday request/response environment
83
+ # @return [Hash] Request method, URL, path, params, headers and body
84
+ #
85
+ def request_values(env)
86
+ request = {
87
+ method: env.method,
88
+ url: env.url,
89
+ url_path: env.url.path,
90
+ params: query_params(env),
91
+ headers: env.request_headers,
92
+ body: env.request_body
93
+ }
94
+ return request unless options.fetch(:filter_credentials, true)
95
+
96
+ request.merge(
97
+ url: URI(Strava::Web::Filter.string(env.url)),
98
+ params: Strava::Web::Filter.params(request[:params]),
99
+ headers: Strava::Web::Filter.headers(request[:headers]),
100
+ body: Strava::Web::Filter.body(request[:body])
43
101
  )
44
102
  end
45
103
 
104
+ #
105
+ # Extracts and decodes query parameters from the request URL.
106
+ #
107
+ # @param env [Faraday::Env] The Faraday request/response environment
108
+ # @return [Hash] Decoded query parameters
109
+ #
46
110
  def query_params(env)
47
111
  env.request.params_encoder ||= Faraday::Utils.default_params_encoder
48
112
  env.params_encoder.decode(env.url.query)
@@ -2,25 +2,81 @@
2
2
 
3
3
  module Strava
4
4
  module Web
5
+ #
6
+ # HTTP request methods for Strava web clients.
7
+ #
8
+ # This module provides GET, POST, PUT, and DELETE HTTP methods for making
9
+ # requests to Strava APIs. All methods return a wrapped response object
10
+ # that provides easy access to response data and metadata.
11
+ #
12
+ # @api private
13
+ #
5
14
  module Request
15
+ #
16
+ # Perform an HTTP GET request.
17
+ #
18
+ # @param path [String] The API path (relative to endpoint)
19
+ # @param options [Hash] Query parameters and options
20
+ #
21
+ # @return [Strava::Web::Response] Wrapped HTTP response
22
+ #
6
23
  def get(path, options = {})
7
24
  request(:get, path, options)
8
25
  end
9
26
 
27
+ #
28
+ # Perform an HTTP POST request.
29
+ #
30
+ # @param path [String] The API path (relative to endpoint)
31
+ # @param options [Hash] Request body parameters and options
32
+ #
33
+ # @return [Strava::Web::Response] Wrapped HTTP response
34
+ #
10
35
  def post(path, options = {})
11
36
  request(:post, path, options)
12
37
  end
13
38
 
39
+ #
40
+ # Perform an HTTP PUT request.
41
+ #
42
+ # @param path [String] The API path (relative to endpoint)
43
+ # @param options [Hash] Request body parameters and options
44
+ #
45
+ # @return [Strava::Web::Response] Wrapped HTTP response
46
+ #
14
47
  def put(path, options = {})
15
48
  request(:put, path, options)
16
49
  end
17
50
 
51
+ #
52
+ # Perform an HTTP DELETE request.
53
+ #
54
+ # @param path [String] The API path (relative to endpoint)
55
+ # @param options [Hash] Query parameters and options
56
+ #
57
+ # @return [Strava::Web::Response] Wrapped HTTP response
58
+ #
18
59
  def delete(path, options = {})
19
60
  request(:delete, path, options)
20
61
  end
21
62
 
22
63
  private
23
64
 
65
+ #
66
+ # Executes an HTTP request with the specified method.
67
+ #
68
+ # Constructs the full URL from the endpoint and path, sends the request
69
+ # using Faraday, and wraps the response in a Strava::Web::Response object.
70
+ #
71
+ # @api private
72
+ # @param method [Symbol] HTTP method (:get, :post, :put, :delete)
73
+ # @param path [String] The API path (relative to endpoint)
74
+ # @param options [Hash] Request parameters and options
75
+ # @option options [String] :endpoint Override the default endpoint URL
76
+ # @option options [Hash] :request Faraday request options (timeouts, etc.)
77
+ #
78
+ # @return [Strava::Web::Response] Wrapped HTTP response
79
+ #
24
80
  def request(method, path, options)
25
81
  options = options.dup if options.key?(:request) || options.key?(:endpoint)
26
82
  root = options.delete(:endpoint) || endpoint