Class: Strava::Api::Client

Inherits:
Web::Client
  • Object
show all
Includes:
Endpoints::Activities, Endpoints::Athletes, Endpoints::Clubs, Endpoints::Gears, Endpoints::OAuth, Endpoints::Routes, Endpoints::SegmentEfforts, Endpoints::Segments, Endpoints::Streams, Endpoints::Uploads
Defined in:
lib/strava/api/client.rb

Overview

Main API client for interacting with the Strava API v3.

This class provides a complete Ruby interface to the Strava API, including support for:

  • Activities (create, read, update, list)
  • Athletes (profile, stats, zones)
  • Clubs (details, members, activities)
  • Gear (equipment details)
  • Routes (details, GPX/TCX export)
  • Segments and Segment Efforts
  • Streams (activity, route, segment data)
  • Uploads (activity file uploads)
  • OAuth (token refresh, deauthorization)

Examples:

Create a client with an access token

client = Strava::Api::Client.new(access_token: "your_access_token")
athlete = client.athlete
activities = client.athlete_activities(per_page: 10)

Configure globally

Strava::Api::Client.configure do |config|
  config.access_token = "your_access_token"
end
client = Strava::Api::Client.new

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Endpoints::OAuth

#deauthorize, #revoke

Methods included from Endpoints::Uploads

#create_upload, #upload

Methods included from Endpoints::Streams

#activity_streams, #segment_effort_streams, #segment_streams

Methods included from Endpoints::Segments

#explore_segments, #segment, #star_segment, #starred_segments

Methods included from Endpoints::SegmentEfforts

#segment_effort, #segment_efforts

Methods included from Endpoints::Routes

#athlete_routes, #export_route_gpx, #export_route_tcx, #route

Methods included from Endpoints::Gears

#gear

Methods included from Endpoints::Clubs

#athlete_clubs, #club, #club_events

Methods included from Endpoints::Athletes

#athlete, #athlete_stats, #athlete_zones, #update_athlete

Methods included from Endpoints::Activities

#activity, #activity_comments, #activity_kudos, #activity_laps, #activity_photos, #activity_zones, #athlete_activities, #create_activity, #update_activity

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize a new API client.

Examples:

client = Strava::Api::Client.new(
  access_token: "your_access_token",
  user_agent: "My Strava App/1.0"
)

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options for the client

Options Hash (options):

  • :access_token (String)

    OAuth access token for API authentication (required)

  • :endpoint (String)

    API endpoint URL (defaults to https://www.strava.com/api/v3)

  • :user_agent (String)

    User agent string for HTTP requests

  • :logger (Logger)

    Logger instance for request/response logging

  • :timeout (Integer)

    HTTP request timeout in seconds

  • :open_timeout (Integer)

    HTTP connection timeout in seconds

  • :proxy (String)

    HTTP proxy URL

  • :ca_path (String)

    Path to SSL CA certificates

  • :ca_file (String)

    Path to SSL CA certificate file



66
67
68
69
70
71
# File 'lib/strava/api/client.rb', line 66

def initialize(options = {})
  Config::ATTRIBUTES.each do |key|
    send("#{key}=", options[key] || Strava::Api.config.send(key))
  end
  super
end

Class Method Details

.configStrava::Api::Config

Returns the configuration object.

Returns:



104
105
106
# File 'lib/strava/api/client.rb', line 104

def config
  Config
end

.configure {|Config| ... } ⇒ Strava::Api::Config

Configure the API client globally.

Examples:

Strava::Api::Client.configure do |config|
  config.access_token = "your_access_token"
end

Yields:

  • (Config)

    Configuration object

Returns:



95
96
97
# File 'lib/strava/api/client.rb', line 95

def configure
  block_given? ? yield(Config) : Config
end

Instance Method Details

#headersHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns HTTP headers for API requests.

Returns:

  • (Hash)

    Headers including OAuth bearer token authorization



79
80
81
# File 'lib/strava/api/client.rb', line 79

def headers
  { 'Authorization' => "Bearer #{access_token}" }
end