A complete Ruby client for the Strava API v3.
It supports OAuth with refresh tokens, webhooks, pagination and rate limits, provides rich Strava models with distance, time and elevation helpers, and is tested with actual Strava data.
Add to Gemfile.
gem 'strava-ruby-client'
Run bundle install.
Strava API calls require an OAuth access token. The token shown on My API Application can't read your activities, so use strava-oauth-token to obtain one with more scopes, or implement the OAuth workflow in your application.
STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-tokenSave the refresh_token in a secure location and use strava-refresh-token to get a new access token when it expires.
client = Strava::Api::Client.new(access_token: ENV['STRAVA_ACCESS_TOKEN'])
athlete = client.athlete # => Strava::Models::DetailedAthlete
athlete.firstname # => 'Daniel'
activity = client.activity(1946417534) # => Strava::Models::DetailedActivity
activity.name # => 'TCS NYC Marathon 2018'
activity.distance_in_miles_s # => '26.26mi'
activity.strava_url # => 'https://www.strava.com/activities/1946417534'List APIs return one page by default. Pass per_page to retrieve all pages, limit to stop after a number of items, or a block to process items as pages arrive.
client.athlete_activities(per_page: 30, limit: 50) do |activity|
activity # => Strava::Models::SummaryActivity
endHTTP errors raise Strava::Errors::Fault, and exceeding rate limits raises Strava::Errors::RatelimitError. Every response exposes rate limits.
begin
athlete = client.athlete
athlete.http_response.ratelimit.fifteen_minutes_remaining # => 590
rescue Strava::Errors::Fault => e
e.message # => 'Authorization Error'
endSee docs/USAGE.md for all APIs, including activities, athletes, clubs, gear, routes, segments, streams, uploads, OAuth, webhooks, pagination, rate limits and errors.
You can configure web client options used in the OAuth and API clients, globally.
Strava::Web::Client.configure do |config|
config.user_agent = 'Strava Ruby Client/3.0'
endThe following settings are supported.
| setting | description |
|---|---|
| user_agent | User-agent, defaults to Strava Ruby Client/version. |
| proxy | Optional HTTP proxy. |
| ca_path | Optional SSL certificates path. |
| ca_file | Optional SSL certificates file. |
| logger | Optional Logger instance that logs HTTP requests. |
| timeout | Optional open/read timeout in seconds. |
| open_timeout | Optional connection open timeout in seconds. |
| log_formatter | Optional Faraday::Logging::Formatter class, e.g. Strava::Web::LogFormatter. |
| filter_credentials | Filter client secrets, tokens and codes from logs and errors, defaults to true. |
The API client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance.
Strava::API.configure do |config|
config.access_token = "..." # Strava access token
endclient = Strava::API::Client.new(
access_token: "...",
user_agent: "..."
)The following settings are supported.
| setting | description |
|---|---|
| access_token | Access token to pass in the Authorization header. |
| endpoint | Defaults to https://www.strava.com/api/v3. |
The OAuth client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance.
Strava::OAuth.configure do |config|
config.client_id = "..." # Strava client ID
config.client_secret = "..." # Strava client secret
endclient = Strava::OAuth::Client.new(
client_id: "...",
client_secret: "...",
user_agent: "..."
)The following settings are supported.
| setting | description |
|---|---|
| client_id | Application client ID. |
| client_secret | Application client secret. |
| endpoint | Defaults to https://www.strava.com/oauth. |
The Webhooks client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance.
Strava::Webhooks.configure do |config|
config.client_id = "..." # Strava client ID
config.client_secret = "..." # Strava client secret
endclient = Strava::Webhooks::Client.new(
client_id: "...",
client_secret: "...",
user_agent: "..."
)The following settings are supported.
| setting | description |
|---|---|
| client_id | Application client ID. |
| client_secret | Application client secret. |
| endpoint | Defaults to https://www.strava.com/api/v3. |
For a complete set of command-line tools, check out strava-ruby-cli built on top of this gem.
Use strava-oauth-token to obtain a token from the command-line. This will open a new browser window, navigate to Strava, request the appropriate permissions, then handle OAuth in a local redirect. The token type, refresh token, access token and token expiration will be displayed in the browser.
STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-tokenUse strava-refresh-token to obtain a token from the command-line using an existing refresh token.
STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... STRAVA_API_REFRESH_TOKEN=... strava-refresh-token- Slava: Strava integration with Slack, source.
- Strada: Strava integration with Discord, source.
- Jekyll Blog at run.dblock.org, source
- Secret Strava, source
- Strava API Documentation
- Writing a New Strava API Ruby Client
- Dealing with Strava API OAuth Token Migration
- Auto-Publishing Strava Runs to Github Pages
- Strava Command-Line Client
See CONTRIBUTING, CHANGELOG, UPGRADING and RELEASING.
Copyright (c) 2018-2025, Daniel Doubrovkine and Contributors.
This project is licensed under the MIT License.