Skip to content

Latest commit

 

History

History
958 lines (678 loc) · 32.2 KB

USAGE.md

File metadata and controls

958 lines (678 loc) · 32.2 KB

Strava Ruby Client Usage

This is the complete reference for strava-ruby-client. See the README to install the gem, get a token and configure the clients.

Table of Contents

Activities

Create an Activity

Creates a manual activity for an athlete.

activity = client.create_activity(
  name: 'Afternoon Run',
  sport_type: 'Run',
  start_date_local: Time.now,
  elapsed_time: 1234, # in seconds
  description: 'Test run.',
  distance: 1000 # in meters
)

activity.name # => 'Afternoon Run'
activity.strava_url # => 'https://www.strava.com/activities/1982980795'

See Strava::Models::DetailedActivity for all available properties.

Get Activity

Returns the given activity that is owned by the authenticated athlete.

activity = client.activity(1982980795)

activity.name # => 'Afternoon Run'
activity.strava_url # => 'https://www.strava.com/activities/1982980795'

See Strava::Models::DetailedActivity for all available properties.

Use map.summary_polyline and combine with polylines to parse the activity map and to construct a Google maps URL with start and end markers.

require 'cgi'
require 'polylines'

map = activity.map # => Strava::Models::Map

decoded_summary_polyline = Polylines::Decoder.decode_polyline(map.summary_polyline)
start_latlng = decoded_summary_polyline[0]
end_latlng = decoded_summary_polyline[-1]

# Google Maps Static API
google_maps_api_key = ENV['GOOGLE_STATIC_MAPS_API_KEY']
google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{CGI.escape(map.summary_polyline)}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}&key=#{google_maps_api_key}"

# MapBox Static API
mapbox_access_token = ENV['MAPBOX_ACCESS_TOKEN']
mapbox_image_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-5+787af2-1.0(#{CGI.escape(map.summary_polyline)}),pin-s-s+e5b22e(#{start_latlng[1]},#{start_latlng[0]}),pin-s-f+89ae00(#{end_latlng[1]},#{end_latlng[0]})/auto/800x800?access_token=#{mapbox_access_token}"

See Strava::Models::Map for all available properties.

List Activity Photos

Returns the photos on the given activity. This API is undocumented in Strava's docs. But there is a discussion in the strava community hub.

photos = client.activity_photos(1982980795) # => Array[Strava::Models::DetailedPhoto]
# in order to request a certain size (by default it will return the biggest size possible):
# photos = client.activity_photos(1982980795, {size: 1920}) # => Array[Strava::Models::DetailedPhoto]

photo = photos.first # => Strava::Models::DetailedPhoto

photo.id # => nil
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
photo.athlete_id # => 26_462_176
photo.activity_id # => 1_946_417_534
photo.activity_name # => 'TCS NYC Marathon 2018'
photo.created_at # => Time
photo.uploaded_at # => Time
photo.sizes # => { '0' => [29, 64] }
photo.default_photo # => false

See Strava::Models::DetailedPhoto for all available properties.

List Activity Comments

Returns the comments on the given activity.

comments = client.activity_comments(1982980795) # => Array[Strava::Models::Comment]

comment = comments.first # => Strava::Models::Comment

comment.text # => 'Молодчина!'
comment.athlete.username # => 'zolotov'

See Strava::Models::Comment for all available properties.

List Activity Kudoers

Returns the athletes who kudoed an activity identified by an identifier.

kudoers = client.activity_kudos(1982980795) # => Array[Strava::Models::SummaryAthlete]

kodoer = kudoers.first # => Strava::Models::SummaryAthlete

kudoer.username # => 'zolotov'

See Strava::Models::SummaryAthlete for all available properties.

List Activity Laps

Returns the laps of an activity identified by an identifier.

laps = client.activity_laps(1982980795) # => Array[Strava::Models::Lap]

lap = laps.first # => Strava::Models::Lap

lap.name # => 'Lap 1'

See Strava::Models::Lap for all available properties.

List Athlete Activities

Returns the currently logged-in athlete's activities.

activities = client.athlete_activities # => Array[Strava::Models::SummaryActivity]

activity = activities.first # => Strava::Models::SummaryActivity

activity.name # => 'NYC TCS Marathon 2018'
activity.strava_url # => 'https://www.strava.com/activities/1477353766'
activity.sport_type_emoji # => '🏃'
activity.distance_s # => '42.2km'
activity.moving_time_in_hours_s # => '3h38m5s'
activity.elapsed_time_in_hours_s # => '3h42m13s'
activity.pace_s # => '5m15s/km'
activity.pace_per_mile_s # => '8m28s/mi'
activity.average_speed_s # => '11.4km/h'
activity.average_speed_miles_per_hour_s # => '7.1mph'
activity.total_elevation_gain_s # => '270.9m'
activity.total_elevation_gain_in_feet_s # => '888.8ft'

See Strava::Models::SummaryActivity, Strava::Models::Mixins::Distance, Strava::Models::Mixins::TotalElevationGain, Strava::Models::Mixins::ElapsedTime and Strava::Models::Mixins::MovingTime for all available properties.

Get Activity Zones

Returns the zones of a given activity.

zones = client.activity_zones(1982980795) # => Array[Strava::Models::ActivityZone]

zone = zones.first # => Strava::Models::ActivityZone
zones.type # => 'heartrate'

distribution_buckets = activity_zone.distribution_buckets # => Array[Strava::Models::TimedZoneRange]

distribution_bucket = distribution_buckets.first # => Strava::Models::TimedZoneRange

distribution_bucket.min # => 0
distribution_bucket.max # => 123
distribution_bucket.time # => 20

See Strava::Models::ActivityZone and Strava::Models::TimedZoneRange for all available properties.

Update Activity

Update an activity.

activity = client.update_activity(
  id: 1982980795,
  name: 'Afternoon Run (Updated)',
  sport_type: 'Run',
  description: 'It was cold.'
)

activity.name # => 'Afternoon Run (Updated)'
activity.strava_url # => 'https://www.strava.com/activities/1982980795'

Athletes

Get Authenticated Athlete

Returns the currently authenticated athlete.

client.athlete # => Strava::Models::DetailedAthlete

See Strava::Models::DetailedAthlete for all available properties.

Get Zones

Returns the the authenticated athlete's heart rate and power zones.

athlete_zones = client.athlete_zones # => Strava::Models::Zones

heart_rate = athlete_zones.heart_rate # => Strava::Models::HeartRateZoneRanges
heart_rate.custom_zone # => false

zone = heart_rate.zones.first # => Strava::Models::ZoneRange
zone.min # => 0
zone.max # => 123

See Strava::Models::Zones, Strava::Models::HeartRateZoneRanges, Strava::Models::PowerZoneRanges and Strava::Models::ZoneRange for all available properties.

Get Athlete Stats

Returns the activity stats of an athlete.

athlete_stats = client.athlete_stats(26462176) # => Strava::Models::ActivityStats

recent_run_totals = athlete_stats.recent_ride_totals # => Strava::Models::ActivityTotal

recent_run_totals.count # => 7
recent_run_totals.distance # => 78049.90087890625
recent_run_totals.distance_s # => '78.05km'
recent_run_totals.moving_time # => 25647
recent_run_totals.moving_time_in_hours_s # => '7h7m27s'
recent_run_totals.elapsed_time # => 26952
recent_run_totals.elapsed_time_in_hours_s # => '7h29m12s'
recent_run_totals.elevation_gain # => 595.4644241333008
recent_run_totals.total_elevation_gain_s # => '595.5m'
recent_run_totals.achievement_count # => 19

See Strava::Models::ActivityStats and Strava::Models::ActivityTotal for all available properties.

Update Athlete

Update the currently authenticated athlete.

athlete = client.update_athlete(weight: 90.1) # => Strava::Models::Athlete

See Strava::Models::DetailedAthlete for all available returned properties.

Clubs

Strava removed the Club Activities, Club Members, and Club Admins endpoints on September 1, 2026 (see the Strava API changelog). The corresponding club_activities, club_members, and club_admins methods have been removed from this gem.

List Athlete Clubs

Returns a list of the clubs whose membership includes the authenticated athlete.

clubs = client.athlete_clubs # => Array[Strava::Models::SummaryClub]

club = clubs.first # => Strava::Models::SummaryClub

activity.name # => 'NYRR'
activity.strava_url # => 'https://www.strava.com/clubs/nyrr'

See Strava::Models::SummaryClub for all available properties.

Get Club

Returns a given club using its identifier.

club = client.club(108605) # => Strava::Models::DetailedClub

club.name # => 'NYRR'

See Strava::Models::DetailedClub for all available properties.

List Club Events

Retrieve recent Events from a specific club.

events = client.club_events(108605) # => Array[Strava::Models::ClubEvent]

event = events.first # => Strava::Models::ClubEvent

event.title # => 'First Group Event Ever! Yippieh!'

See Strava::Models::ClubEvent for all available properties.

Gears

Get Equipment

Returns an equipment using its identifier.

gear = client.gear(id: 'b2338517') # => Strava::Models::DetailedGear

gear.id # => 'b2338517'
gear.name # => 'Trek'
gear.distance # => 380939.0
gear.distance_s # => '380.94km'
gear.brand_name # => 'Trek'
gear.model_name # => 'Madone'
gear.description # => 'white'
gear.primary # => 'false'
gear.frame_type # => '3'
gear.weight # => '9'
gear.retired # => 'false'

See Strava::Models::DetailedGear for all available properties.

Routes

Export Route GPX

Returns GPS Exchange Format (GPX) data of the route. Combine with multi_xml or gpx to parse it.

data = client.export_route_gpx(16341573) # => String

require 'multi_xml'
xml = MultiXml.parse(data) # => parsed GPX

require 'gpx'
gpx = GPX::GPXFile.new(gpx_data: data) # => GPX::GPXFile

gpx.name # => 'Lower Manhattan Loop'
gpx.description # => 'My usual long run when I am too lazy to go to Central Park.'
gpx.tracks # => Array[GPX::Track]

Export Route TCX

Returns a Training Center XML (TCX) data of the route. Combine with multi_xml or tcx to parse it.

data = client.export_route_tcx(16341573) # => String

require 'multi_xml'
xml = MultiXml.parse(data) # => parsed TCX

require 'tcx'
tcx = Tcx.load(data) # => Tcx::Database

tcx.courses.first.name # => 'Lower Manhattan'

Get Route

Returns a route using its identifier.

route = client.route(16341573) # => Strava::Models::Route

route.name # => 'Lower Manhattan Loop'
route.description # => 'My usual long run when I am too lazy to go to Central Park.'

See Strava::Models::Route for all available properties.

List Athlete Routes

Returns a list of the routes by athlete ID.

routes = client.athlete_routes(26462176) # => Array[Strava::Models::Route]

route = routes.first # => Strava::Models::Route

route.name # => 'Lower Manhattan Loop'
route.description # => 'My usual long run when I am too lazy to go to Central Park.'
route.moving_time_in_hours_s # => '1h21m5s'

See Strava::Models::Route for all available properties.

Segment Efforts

List Segment Efforts

Returns a set of the authenticated athlete's segment efforts for a given segment.

segment_efforts = client.segment_efforts(1109718)

segment_effort = segment_efforts.first # => Strava::Models::DetailedSegmentEffort

segment_effort.name # => 'E 14th St Climb'
segment_effort.activity # => Strava::Models::Activity
segment_effort.athlete # => Strava::Models::Athlete
segment_effort.elapsed_time # => 116
segment_effort.distance # => 398.6
segment_effort.distance_s # => '0.4km'
segment_effort.average_heartrate # => 152.2
segment_effort.max_heartrate # => 158.0

segment_effort.achievements # => Enumerable

achievement = segment_effort.achievements.first # => Strava::Models::Achievement
achievement.rank # => 1
achievement.type # => 'pr'
achievement.type_id # => 3

See Strava::Models::DetailedSegmentEffort and Strava::Models::Achievement for all available properties.

Get Segment Effort

Returns a segment effort from an activity that is owned by the authenticated athlete.

segment_effort = client.segment_effort(41494197089) # => Strava::Models::DetailedSegmentEffort

segment_effort.name # => 'E 14th St Climb'
segment_effort.activity # => Strava::Models::Activity
segment_effort.elapsed_time # => 116

segment_stats = segment_effort.athlete_segment_stats # => Strava::Models::SummaryPRSegmentEffort
segment_stats.pr_elapsed_time # => 116
segment_stats.elapsed_time_in_hours_s # => '1m56s'
segment_stats.pr_date # => Date
segment_stats.effort_count # => 3

See Strava::Models::DetailedSegmentEffort and Strava::Models::SummaryPRSegmentEffort for all available properties.

Segments

Explore Segments

Returns the top 10 segments matching a specified query.

segments = client.explore_segments(bounds: [36.372975, -94.220234, 36.415949, -94.183670], activity_type: 'running')

segment = segments.first # => Strava::Models::ExplorerSegment
segment.name # => 'Compton Gardens hill'
segment.avg_grade # => 4.6
segment.start_latlng # => [36.377702, -94.207242]
segment.end_latlng # => [36.375948, -94.207689]
segment.elev_difference # => 9.6

See Strava::Models::ExplorerSegment for all available properties.

List Starred Segments

List of the authenticated athlete's starred segments.

segments = client.starred_segments

segment = segments.first # => Strava::Models::SummarySegment

segment.pr_time # => 256
segment.elapsed_time_in_hours_s # => '4m16s'
segment.starred_date # => Time
segment.athlete_segment_stats # => Strava::Models::SummarySegmentEffort
segment.athlete_pr_effort # => Strava::Models::SummaryPRSegmentEffort

See Strava::Models::SummarySegment, Strava::Models::SummarySegmentEffort and Strava::Models::SummaryPRSegmentEffort for all available properties.

Get Segment

Returns the specified segment.

segment = client.segment(1109718) # => Strava::Models::DetailedSegment

segment.name # => 'E 14th St Climb'
segment.city # => 'New York'
segment.state # => 'NY'
segment.country # => 'United States'
segment.map # => Strava::Models::Map
segment.effort_count # => 750
segment.athlete_count # => 206
segment.star_count # => 1
segment.athlete_segment_stats # => Strava::Models::SummarySegmentEffort

See Strava::Models::DetailedSegment for all available properties.

Star Segment

Stars/unstars the given segment for the authenticated athlete.

segment = client.star_segment(50272077110, starred: true) # => Strava::Models::DetailedSegment

segment.name # => 'E 14th St Climb'
segment.starred # => true

See Strava::Models::DetailedSegment for all available properties.

Streams

Stream APIs can return various streams by key(s).

streams = client.segment_streams(1109718, keys: %w[distance latlng altitude]) # => Strava::Models::StrewamSet

streams.distance # => Strava::Models::Stream
streams.latlng # => Strava::Models::Stream
streams.altitude # => Strava::Models::Stream

The Strava API doesn't return a total elevation loss (descent) property for streams, but it can be computed from an altitude stream's data.

streams = client.activity_streams(1946417534, keys: %w[altitude]) # => Strava::Models::StreamSet

streams.altitude.total_elevation_gain # => 725.3
streams.altitude.total_elevation_loss # => 680.1
streams.altitude.total_elevation_gain_s # => "725.3m"
streams.altitude.total_elevation_loss_s # => "680.1m"

Get Activity Streams

Returns the given activity's streams.

streams = client.activity_streams(1946417534) # => Strava::Models::StreamSet

distance = streams.distance # => Strava::Models::Stream
distance.original_size # => 13_129
distance.resolution # => 'high'
distance.series_type # => 'distance'
distance.data # => Array[Float]

See Strava::Models::StreamSet and Strava::Models::Stream for all available properties.

Get Segment Effort Streams

Returns a set of streams for a segment effort completed by the authenticated athlete.

streams = client.segment_effort_streams(41494197089)

distance = streams.distance # => Strava::Models::Stream
distance.original_size # => 117
distance.resolution # => 'high'
distance.series_type # => 'distance'
distance.data # => Array[Float]

See Strava::Models::StreamSet and Strava::Models::Stream for all available properties.

Get Segment Streams

Returns the given segment's streams.

streams = client.segment_streams(1109718) # => Strava::Models::StreamSet

distance = streams.distance # => Strava::Models::Stream
distance.original_size # => 32
distance.resolution # => 'high'
distance.series_type # => 'distance'
distance.data # => Array[Float]

See Strava::Models::StreamSet and Strava::Models::Stream for all available properties.

Uploads

Upload Activity

Uploads a new data file to create an activity from. To check the processing status of the uploaded file, see Get Upload.

upload = client.create_upload(
  file: Faraday::UploadIO.new('17611540601.tcx', 'application/tcx+xml'),
  name: 'Uploaded Activity',
  description: 'Uploaded by strava-ruby-client.',
  data_type: 'tcx',
  external_id: 'strava-ruby-client-upload-1'
) # => Strava::Models::Upload

upload.id # => 2136460097
upload.external_id # => 'strava-ruby-client-upload-1.tcx'
upload.error # => nil
upload.status # => 'Your activity is still being processed.'
upload.activity_id # => nil

See Strava::Models::Upload for all available properties.

Get Upload

Returns an upload for a given identifier. Raises Strava::Errors::UploadError if the upload was faulty and did not result in a created activity. Strava::Errors::UploadError#upload contains Strava::Models::Upload for further inspection.

# happy path
upload = client.upload(2136460097) # => Strava::Models::Upload

upload.id # => 2_136_460_097
upload.external_id # => 'strava-ruby-client-upload-1.tcx'
upload.error # => nil
upload.status # => 'Your activity is ready.'
upload.activity_id # => 1_998_557_443
# with error after upload
upload = client.upload(2136460097) 
begin
  while upload.processing?
    sleep 1
    upload = client.upload(2136460097)
  end
rescue Strava::Errors::UploadError => upload_error
  upload_error.status # => 200
  upload_error.error_status # => 'There was an error processing your activity.'
  upload_error.message # => '17611540601.tcx duplicate of activity 8309312818'
  
  upload_error.upload.external_id # => nil
  upload_error.upload.activity_id # => nil
  upload_error.upload.status # => 'There was an error processing your activity.'
  upload_error.upload.error # => '17611540601.tcx duplicate of activity 8309312818'
  upload_error.upload.class # => Strava::Models::UploadFailed
end

See Strava::Models::Upload for all available properties.
See Strava::Errors::UploadError for all available properties.

Pagination

Some Strava APIs, including athlete-activities support pagination when supplying an optional page and per_page parameter. By default the client retrieves one page of data, which Strava currently defaults to 30 items. If you supply per_page, the client will retrieve all pages. You can paginate through items incrementally by supplying a block. Use limit to limit the number of items returned. The underlying implementation makes page-sized calls and increments the page argument.

client.athlete_activities(per_page: 30) do |activity|
  activity # => Strava::Models::Activity
end
client.athlete_activities(per_page: 30) # => [Strava::Models::Activity], all pages
client.athlete_activities(per_page: 30, limit: 50) # => [Strava::Models::Activity], all pages, stop at 50 items

Some Strava APIs, including activity-comments support cursor-based pagination when supplying optional after_cursor and page_size parameters. By default the client retrieves one page of data, which Strava currently defaults to 30 items. If you supply page_size, the client will retrieve all pages. You can paginate through items incrementally by supplying a block. Use limit to limit the number of items returned. The underlying implementation makes page-sized calls and uses the returned cursor as after_cursor.

client.activity_comments(id: 1982980795, page_size: 30) do |comment|
  comment # => Strava::Models::Comment
end
client.activity_comments(id: 1982980795, page_size: 30) # => [Strava::Models::Comment], all pages
client.activity_comments(id: 1982980795, page_size: 30, limit: 100) # => [Strava::Models::Comment], paginated, stop at 100 items

OAuth

OAuth Workflow

Obtain a redirect URL using an instance of Strava::OAuth::Client.

client = Strava::OAuth::Client.new(
  client_id: "12345",
  client_secret: "12345678987654321"
)

redirect_url = client.authorize_url(
  redirect_uri: 'https://example.com/oauth',
  approval_prompt: 'force',
  response_type: 'code',
  scope: 'activity:read_all',
  state: 'magic'
)

Once the user is redirected to your application, perform a token exchange to obtain a refresh and access token.

response = client.oauth_token(code: '1234556789901234567890')

response # => Strava::Models::Token

response.access_token # access token
response.refresh_token # refresh token
response.expires_at # timestamp when the access token expires
response.athlete # => Strava::Models::SummaryAthlete

See Strava authentication documentation, Strava::Models::Token and Strava::Models::SummaryAthlete for all available properties in the response.

If the access token is expired, refresh it before making any requests. You will get back all new tokens.

response = client.oauth_token(
  refresh_token: '...',
  grant_type: 'refresh_token'
)

response.access_token # => String, new access token
response.refresh_token # => String, new refresh token
response.expires_at # => Time, new timestamp when the access token expires

Revoke

Revoke access to an athlete's data using an instance of Strava::API::Client.

authorization = client.revoke

authorization.access_token # => String, access token being revoked

Deauthorize

Revoke access to an athlete's data using an instance of Strava::API::Client.

authorization = client.deauthorize

authorization.access_token # => String, access token being revoked

Deprecated: use revoke instead. The oauth/deauthorize endpoint will be retired on June 1, 2027 in favor of oauth/revoke.

Command Line OAuth Workflow

The OAuth process is web-based and you cannot obtain a token from a Strava client ID and secret without user intervention. You can, however, start a local web server to handle the OAuth redirect and open a browser from the command-line.

See strava-oauth-token or strava-ruby-cli for an example.

Webhooks

Strava provides a Webhook Event API.

A complete example that handles subscription creation, deletion and handling can be found in strava-webhooks. Run strava-webhooks to see current registrations, strava-webhooks handle to run an HTTP server that handles both challenges and event data, strava-webhooks create [url] to create a new subscription and strava-webhooks delete [id] to delete it.

Before creating a webhook subscription you must implement and run an HTTP server that will handle a GET challenge at the subscription URL.

challenge = Strava::Webhooks::Models::Challenge.new(request.query)
raise 'Bad Request' unless challenge.verify_token == 'token'
response.content_type = 'application/json'
response.body = challenge.response.to_json

See Strava::Webhooks::Models::Challenge for details.

An existing subscription must be handled in the same HTTP server's POST request to the subscription URL.

event = Strava::Webhooks::Models::Event.new(JSON.parse(request.body))

event # => Strava::Webhooks::Models::Event
event.object_type # => 'activity'
event.id # => 1991813808
event.id_str # => '1991813808'
event.aspect_type # => 'update'
event.updates # => { 'sport_type' => 'Walk' }
event.owner_id # => 29323238
event.owner_id_str # => '29323238'
event.subscription_id # => 131302
event.event_time # => DateTime

See Strava::Webhooks::Models::Event for details.

Subscriptions can be created, listed and deleted.

Create a client.

client = Strava::Webhooks::Client.new(
  client_id: "12345",
  client_secret: "12345678987654321"
)

Create a subscription.

subscription = client.create_push_subscription(callback_url: 'http://example.com/strava', verify_token: 'token')

subscription # => Strava::Webhooks::Models::Subscription
subscription.id # => 131300
subscription.callback_url # => 'http://example.com/strava'

See Strava::Webhooks::Models::Subscription for details.

List an existing subscription. Strava seems to only allow one.

subscriptions = client.push_subscriptions

subscription = subscriptions.first # => Strava::Webhooks::Models::Subscription
subscription.id # => 131300
subscription.callback_url # => 'http://example.com/strava'

Delete an existing subscription.

client.delete_push_subscription(131300) # => nil

Rate Limits

Every API call's HTTP Response Content, be it a single Model or a list (via pagination), can be accessed by using #http_response.

client.athlete #=> Strava::Models::Athlete#http_response

client.activity_comments(id: 1234567) #=> Array<Strava::Models::Comment>#http_response

http_response itself is a Strava::Web::ApiResponse class. Ratelimits are accessed via this class using Strava::Web::ApiResponse#ratelimit. See the examples given below:

comments = client.activity_comments(id: 123_456_789)

# comments == Array<Strava::Models::Comment>
comments.http_response.ratelimit.to_h
athlete = client.athlete # => Strava::Models::Athlete
athlete.http_response.ratelimit

The following properties are available on Strava::Api::Ratelimit.

  • limit
  • limit?
  • usage
  • fifteen_minutes
  • fifteen_minutes_usage
  • fifteen_minutes_remaining
  • total_day
  • total_day_usage
  • total_day_remaining
  • to_h
  • to_s

You can access the Hash containing all limits by calling to_h.

# athlete.http_response.ratelimit.to_h
{
  limit: limit,
  usage: usage,
  total_day: total_day,
  total_day_usage: total_day_usage,
  total_day_remaining: total_day_remaining,
  fifteen_minutes: fifteen_minutes,
  fifteen_minutes_usage: fifteen_minutes_usage,
  fifteen_minutes_remaining: fifteen_minutes_remaining
}

Exceeded Rate Limits

Strava answers with HTTP status code 429, when ratelimits are exceeded. This will in return raise Strava::Errors::RatelimitError.

error.is_a?(Strava::Errors::RatelimitError) #=> true
error.ratelimit.is_a?(Strava::Api::Ratelimit) #=> true
# see Strava::Api::Ratelimit

Errors

All errors that return HTTP codes 400-600 result in either Faraday::ResourceNotFound, Faraday::ConnectionFailed or Strava::Errors::Fault exceptions.

begin
  client.oauth_token(code: 'invalid')
rescue Strava::Errors::Fault => e
  e.message # => Bad Request
  e.errors # => [{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }]
  e.headers # => { "status" => "403 Bad Request", "x-ratelimit-limit" => "600,30000", "x-ratelimit-usage" => "314,27536" }
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.

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