22
33module Strava
44 module Api
5+ #
6+ # Main API client for interacting with the Strava API v3.
7+ #
8+ # This class provides a complete Ruby interface to the Strava API, including support for:
9+ # * Activities (create, read, update, list)
10+ # * Athletes (profile, stats, zones)
11+ # * Clubs (details, members, activities)
12+ # * Gear (equipment details)
13+ # * Routes (details, GPX/TCX export)
14+ # * Segments and Segment Efforts
15+ # * Streams (activity, route, segment data)
16+ # * Uploads (activity file uploads)
17+ # * OAuth (token refresh, deauthorization)
18+ #
19+ # @example Create a client with an access token
20+ # client = Strava::Api::Client.new(access_token: "your_access_token")
21+ # athlete = client.athlete
22+ # activities = client.athlete_activities(per_page: 10)
23+ #
24+ # @example Configure globally
25+ # Strava::Api::Client.configure do |config|
26+ # config.access_token = "your_access_token"
27+ # end
28+ # client = Strava::Api::Client.new
29+ #
30+ # @see https://developers.strava.com/docs/reference/ Strava API Documentation
31+ #
532 class Client < Strava ::Web ::Client
633 include Endpoints ::Activities
734 include Endpoints ::Athletes
@@ -16,22 +43,64 @@ class Client < Strava::Web::Client
1643
1744 attr_accessor ( *Config ::ATTRIBUTES )
1845
46+ #
47+ # Initialize a new API client.
48+ #
49+ # @param [Hash] options Configuration options for the client
50+ # @option options [String] :access_token OAuth access token for API authentication (required)
51+ # @option options [String] :endpoint API endpoint URL (defaults to https://www.strava.com/api/v3)
52+ # @option options [String] :user_agent User agent string for HTTP requests
53+ # @option options [Logger] :logger Logger instance for request/response logging
54+ # @option options [Integer] :timeout HTTP request timeout in seconds
55+ # @option options [Integer] :open_timeout HTTP connection timeout in seconds
56+ # @option options [String] :proxy HTTP proxy URL
57+ # @option options [String] :ca_path Path to SSL CA certificates
58+ # @option options [String] :ca_file Path to SSL CA certificate file
59+ #
60+ # @example
61+ # client = Strava::Api::Client.new(
62+ # access_token: "your_access_token",
63+ # user_agent: "My Strava App/1.0"
64+ # )
65+ #
1966 def initialize ( options = { } )
2067 Config ::ATTRIBUTES . each do |key |
2168 send ( "#{ key } =" , options [ key ] || Strava ::Api . config . send ( key ) )
2269 end
2370 super
2471 end
2572
73+ #
74+ # Returns HTTP headers for API requests.
75+ #
76+ # @return [Hash] Headers including OAuth bearer token authorization
77+ # @api private
78+ #
2679 def headers
2780 { 'Authorization' => "Bearer #{ access_token } " }
2881 end
2982
3083 class << self
84+ #
85+ # Configure the API client globally.
86+ #
87+ # @yield [Config] Configuration object
88+ # @return [Strava::Api::Config] Configuration object
89+ #
90+ # @example
91+ # Strava::Api::Client.configure do |config|
92+ # config.access_token = "your_access_token"
93+ # end
94+ #
3195 def configure
3296 block_given? ? yield ( Config ) : Config
3397 end
3498
99+ #
100+ # Returns the configuration object.
101+ #
102+ # @return [Strava::Api::Config] Configuration object
103+ #
35104 def config
36105 Config
37106 end
0 commit comments