Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork23
A complete Ruby client for the Strava API v3.
License
dblock/strava-ruby-client
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A complete Ruby client for theStrava API v3.
Unlike other clients, includingstrava-api-v3, provides complete OAuth refresh token flow support, webhooks support, a richer first class interface to Strava models, conversion helpers for distance, time and elevation, natively supports pagination, implements more consistent error handling and is built with thorough test coverage using actual Strava data.
- Installation
- Usage
- Configuration
- Errors
- Tools
- Users
- Resources
- Upgrading
- Contributing
- Copyright and License
Add to Gemfile.
gem 'strava-ruby-client'
Runbundle install
.
Use an access token obtained fromMy API Application in the Strava UI, thestrava-oauth-token tool or theOAuth Workflow in your application.
client=Strava::Api::Client.new(access_token:"12345678987654321")client.athlete# => Strava::Models::Athlete
Note that the token from the Strava website does not have enough permissions to retrieve your own activities. Use thestrava-oauth-token tool to obtain a short lived with more access scopes.
export STRAVA_CLIENT_ID=...export STRAVA_CLIENT_SECRET=...bundleexec ruby bin/strava-oauth-token
Note theaccess_token
from the browser window.
export STRAVA_ACCESS_TOKEN=...bundleexec ruby bin/strava-activities.rb
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 secondsdescription:'Test run.',distance:1000# in meters)activity.name# => 'Afternoon Run'activity.strava_url# => 'https://www.strava.com/activities/1982980795'
SeeStrava::Models::Activity for all available properties.
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'
SeeStrava::Models::Activity for all available properties.
Usemap.summary_polyline
and combine withpolylines 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::Mapdecoded_summary_polyline=Polylines::Decoder.decode_polyline(map.summary_polyline)start_latlng=decoded_summary_polyline[0]end_latlng=decoded_summary_polyline[-1]# Google Maps Static APIgoogle_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 APImapbox_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}"
SeeStrava::Models::Map for all available properties.
Returns the photos on the given activity. This API is undocumented in Strava's docs. But there is a discussion in thestrava community hub.
photos=client.activity_photos(1982980795)# => Array[Strava::Models::Photo]# 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::Photo]photo=photos.first# => Strava::Models::Photophoto.id# => nilphoto.unique_id# => '65889142-538D-4EE5-96F5-3DC3B773B1E3'photo.urls# => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }photo.athlete_id# => 26_462_176photo.activity_id# => 1_946_417_534photo.activity_name# => 'TCS NYC Marathon 2018'photo.created_at# => Timephoto.uploaded_at# => Timephoto.sizes# => { '0' => [29, 64] }photo.default_photo# => false
SeeStrava::Models::Photo for all available properties.
Returns the comments on the given activity.
comments=client.activity_comments(1982980795)# => Array[Strava::Models::Comment]comment=comments.first# => Strava::Models::Commentcomment.text# => 'Молодчина!'comment.athlete.username# => 'zolotov'
SeeStrava::Models::Comment for all available properties.
Returns the athletes who kudoed an activity identified by an identifier.
kudoers=client.activity_kudos(1982980795)# => Array[Strava::Models::Athlete]kodoer=kudoers.first# => Strava::Models::Athletekudoer.username# => 'zolotov'
SeeStrava::Models::Athlete for all available properties.
Returns the laps of an activity identified by an identifier.
laps=client.activity_laps(1982980795)# => Array[Strava::Models::Lap]lap=laps.first# => Strava::Models::Laplap.name# => 'Lap 1'
SeeStrava::Models::Lap for all available properties.
Returns the currently logged-in athlete's activities.
activities=client.athlete_activities# => Array[Strava::Models::Activity]activity=activities.first# => Strava::Models::Activityactivity.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.speed_s# => '11.4km/h'activity.miles_per_hour_s# => '7.1mph'activity.total_elevation_gain_s# => '270.9m'activity.total_elevation_gain_in_feet_s# => '888.8ft'
SeeStrava::Models::Activity,Strava::Models::Mixins::Distance,Strava::Models::Mixins::Elevation andStrava::Models::Mixins::Time for all available properties.
Returns the zones of a given activity.
zones=client.activity_zones(1982980795)# => Array[Strava::Models::ActivityZone]zone=zones.first# => Strava::Models::ActivityZonezones.type# => 'heartrate'distribution_buckets=activity_zone.distribution_buckets# => Array[Strava::Models::TimedZoneRange]distribution_bucket=distribution_buckets.first# => Strava::Models::TimedZoneRangedistribution_bucket.min# => 0distribution_bucket.max# => 123distribution_bucket.time# => 20
SeeStrava::Models::ActivityZone andStrava::Models::TimedZoneRange for all available properties.
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'
Returns the currently authenticated athlete.
client.athlete# => Strava::Models::Athlete
SeeStrava::Models::Athlete for all available properties.
Returns the the authenticated athlete's heart rate and power zones.
athlete_zones=client.athlete_zones# => Strava::Models::Zonesheart_rate=athlete_zones.heart_rate# => Strava::Models::HeartRateZoneRangesheart_rate.custom_zone# => falsezone=heart_rate.zones.first# => Strava::Models::ZoneRangezone.min# => 0zone.max# => 123
SeeStrava::Models::Zones,Strava::Models::HeartRateZoneRanges,Strava::Models::PowerZoneRanges andStrava::Models::ZoneRange for all available properties.
Returns the activity stats of an athlete.
athlete_stats=client.athlete_stats(26462176)# => Strava::Models::ActivityStatsrecent_run_totals=athlete_stats.recent_ride_totals# => Strava::Models::ActivityTotalrecent_run_totals.count# => 7recent_run_totals.distance# => 78049.90087890625recent_run_totals.distance_s# => '78.05km'recent_run_totals.moving_time# => 25647recent_run_totals.moving_time_in_hours_s# => '7h7m27s'recent_run_totals.elapsed_time# => 26952recent_run_totals.elapsed_time_in_hours_s# => '7h29m12s'recent_run_totals.elevation_gain# => 595.4644241333008recent_run_totals.total_elevation_gain_s# => '595.5m'recent_run_totals.achievement_count# => 19
SeeStrava::Models::ActivityStats andStrava::Models::ActivityTotal for all available properties.
Update the currently authenticated athlete.
athlete=client.update_athlete(weight:90.1)# => Strava::Models::Athlete
SeeStrava::Models::Athlete for all available returned properties.
Retrieve recent activities from members of a specific club.
activities=client.club_activities(108605)# => Array[Strava::Models::Activity]activity=activities.first# => Strava::Models::Activityactivity.name# => 'Afternoon Run'
SeeStrava::Models::Activity for all available properties. Note that Strava does not return activity or athlete ID via this API.
Retrieve recent Events from a specific club.
events=client.club_events(108605)# => Array[Strava::Models::ClubEvent]event=events.first# => Strava::Models::ClubEventevent.title# => 'First Group Event Ever! Yippieh!'
SeeStrava::Models::ClubEvent for all available properties.
Returns a list of the administrators of a given club.
admins=client.club_admins(108605)# => Array[Strava::Models::ClubAdmin]admin=admins.first# => Strava::Models::ClubAdminadmin.name# => 'Peter Ciaccia'
SeeStrava::Models::ClubAdmin for all available properties.
Returns a given club using its identifier.
club=client.club(108605)# => Strava::Models::Clubclub.name# => 'NYRR'
SeeStrava::Models::Club for all available properties.
Returns a list of the members of a given club.
members=client.club_members(108605)# => Array[Strava::Models::ClubMember]member=members.first# => Strava::Models::ClubMembermember.name# => 'Peter Ciaccia'
SeeStrava::Models::ClubMember for all available properties.
Returns a list of the clubs whose membership includes the authenticated athlete.
clubs=client.athlete_clubs# => Array[Strava::Models::Club]club=clubs.first# => Strava::Models::Clubactivity.name# => 'NYRR'activity.strava_url# => 'https://www.strava.com/clubs/nyrr'
SeeStrava::Models::Club for all available properties.
Returns an equipment using its identifier.
gear=client.gear(id:'b2338517')# => Strava::Models::Geargear.id# => 'b2338517'gear.name# => 'Trek'gear.distance# => 380939.0gear.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'
SeeStrava::Models::Gear for all available properties.
ReturnsGPS Exchange Format (GPX) data of the route. Combine withmulti_xml orgpx to parse it.
data=client.export_route_gpx(16341573)# => Stringrequire'multi_xml'xml=MultiXml.parse(data)# => parsed GPXrequire'gpx'gpx=GPX::GPXFile.new(gpx_data:data)# => GPX::GPXFilegpx.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]
Returns aTraining Center XML (TCX) data of the route. Combine withmulti_xml to parse it.
data=client.export_route_tcx(16341573)# => Stringrequire'multi_xml'xml=MultiXml.parse(data)# => parsed TCX
Returns a route using its identifier.
route=client.route(16341573)# => Strava::Models::Routeroute.name# => 'Lower Manhattan Loop'route.description# => 'My usual long run when I am too lazy to go to Central Park.'
SeeStrava::Models::Route for all available properties.
Returns a list of the routes by athlete ID.
routes=client.athlete_routes(26462176)# => Array[Strava::Models::Route]route=routes.first# => Strava::Models::Routeroute.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'
SeeStrava::Models::Route for all available properties.
Returns a running race for a given identifier.
running_race=client.running_race(1577)# => Strava::Models::RunningRacerunning_race.name# => 'Walt Disney World Marathon 10k'running_race.distance# => 10_000.0running_race.distance_s# => '10km'running_race.city# => 'Orlando'running_race.state# => 'FL'running_race.country# => 'United States'running_race.strava_url# => 'https://www.strava.com/running-races/2018-walt-disney-world-marathon-10k'running_race.website_url# => 'https://www.rundisney.com/disneyworld-marathon/'
SeeStrava::Models::RunningRace for all available properties.
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::SegmentEffortsegment_effort.name# => 'E 14th St Climb'segment_effort.activity# => Strava::Models::Activitysegment_effort.athlete# => Strava::Models::Athletesegment_effort.elapsed_time# => 116segment_effort.distance# => 398.6segment_effort.distance_s# => '0.4km'segment_effort.average_heartrate# => 152.2segment_effort.max_heartrate# => 158.0segment_effort.achievements# => Enumerableachievement=segment_effort.achievements.first# => Strava::Models::Achievementachievement.rank# => 1achievement.type# => 'pr'achievement.type_id# => 3
SeeStrava::Models::SegmentEffort andStrava::Models::Achievement for all available properties.
Returns a segment effort from an activity that is owned by the authenticated athlete.
segment_effort=client.segment_effort(41494197089)# => Strava::Models::SegmentEffortsegment_effort.name# => 'E 14th St Climb'segment_effort.activity# => Strava::Models::Activitysegment_effort.elapsed_time# => 116segment_stats=segment_effort.athlete_segment_stats# => Strava::Models::SegmentStatssegment_stats.pr_elapsed_time# => 116segment_stats.elapsed_time_in_hours_s# => '1m56s'segment_stats.pr_date# => Datesegment_stats.effort_count# => 3
SeeStrava::Models::SegmentEffort andStrava::Models::SegmentStats for all available properties.
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::ExplorerSegmentsegment.name# => 'Compton Gardens hill'segment.avg_grade# => 4.6segment.start_latlng# => [36.377702, -94.207242]segment.end_latlng# => [36.375948, -94.207689]segment.elev_difference# => 9.6
SeeStrava::Models::ExplorerSegment for all available properties.
List of the authenticated athlete's starred segments.
segments=client.starred_segmentssegment=segments.first# => Strava::Models::Segmentsegment.pr_time# => 256segment.elapsed_time_in_hours_s# => '4m16s'segment.starred_date# => Timesegment.athlete_pr_effort# => Strava::Models::SegmentEffort
SeeStrava::Models::Segment andStrava::Models::SegmentEffort for all available properties.
Returns the specified segment.
segment=client.segment(1109718)# => Strava::Models::Segmentsegment.name# => 'E 14th St Climb'segment.city# => 'New York'segment.state# => 'NY'segment.country# => 'United States'segment.map# => Strava::Models::Mapsegment.effort_count# => 750segment.athlete_count# => 206segment.star_count# => 1segment.athlete_segment_stats# => Strava::Models::SegmentStats
SeeStrava::Models::Segment for all available properties.
Stars/unstars the given segment for the authenticated athlete.
segment=client.star_segment(50272077110,starred:true)# => Strava::Models::Segmentsegment.name# => 'E 14th St Climb'segment.starred# => true
SeeStrava::Models::Segment for all available properties.
Stream APIs can return various streams by key(s).
streams=client.segment_streams(1109718,keys:%w[distancelatlngaltitude])# => Strava::Models::StrewamSetstreams.distance# => Strava::Models::Streamstreams.latlng# => Strava::Models::Streamstreams.altitude# => Strava::Models::Stream
Returns the given activity's streams.
streams=client.activity_streams(1946417534)# => Strava::Models::StreamSetdistance=streams.distance# => Strava::Models::Streamdistance.original_size# => 13_129distance.resolution# => 'high'distance.series_type# => 'distance'distance.data# => Array[Float]
SeeStrava::Models::StreamSet andStrava::Models::Stream for all available properties.
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::Streamdistance.original_size# => 117distance.resolution# => 'high'distance.series_type# => 'distance'distance.data# => Array[Float]
SeeStrava::Models::StreamSet andStrava::Models::Stream for all available properties.
Returns the given segment's streams.
streams=client.segment_streams(1109718)# => Strava::Models::StreamSetdistance=streams.distance# => Strava::Models::Streamdistance.original_size# => 32distance.resolution# => 'high'distance.series_type# => 'distance'distance.data# => Array[Float]
SeeStrava::Models::StreamSet andStrava::Models::Stream for all available properties.
Uploads a new data file to create an activity from. To check the processing status of the uploaded file, seeGet 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::Uploadupload.id# => 2136460097upload.external_id# => 'strava-ruby-client-upload-1.tcx'upload.error# => nilupload.status# => 'Your activity is still being processed.'upload.activity_id# => nil
SeeStrava::Models::Upload for all available properties.
Returns an upload for a given identifier. RaisesStrava::Errors::UploadError
if the upload was faulty and did not result in a created activity.Strava::Errors::UploadError#upload
containsStrava::Models::Upload
for further inspection.
# happy pathupload=client.upload(2136460097)# => Strava::Models::Uploadupload.id# => 2_136_460_097upload.external_id# => 'strava-ruby-client-upload-1.tcx'upload.error# => nilupload.status# => 'Your activity is ready.'upload.activity_id# => 1_998_557_443
# with error after uploadupload=client.upload(2136460097)beginwhileupload.processing?sleep1upload=client.upload(2136460097)endrescueStrava::Errors::UploadError=>upload_errorupload_error.status# => 200upload_error.error_status# => 'There was an error processing your activity.'upload_error.message# => '17611540601.tcx duplicate of activity 8309312818'upload_error.upload.external_id# => nilupload_error.upload.activity_id# => nilupload_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::UploadFailedend
SeeStrava::Models::Upload for all available properties.
SeeStrava::Errors::UploadError for all available properties.
Some Strava APIs, includingathlete-activities support pagination when supplying an optionalpage
andper_page
parameter. By default the client retrieves one page of data, which Strava currently defaults to 30 items. You can paginate through more data by supplying a block and an optionalper_page
parameter. The underlying implementation makes page-sized calls and increments thepage
argument.
client.athlete_activities(per_page:30)do |activity|activity# => Strava::Models::Activityend
Obtain a redirect URL using an instance ofStrava::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::Tokenresponse.access_token# access tokenresponse.refresh_token# refresh tokenresponse.expires_at# timestamp when the access token expiresresponse.athlete# => Strava::Models::Athlete
SeeStrava authentication documentation,Strava::Models::Token andStrava::Models::Athlete 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 tokenresponse.refresh_token# => String, new refresh tokenresponse.expires_at# => Time, new timestamp when the access token expires
Revoke access to an athlete's data using an instance ofStrava::API::Client
.
authorization=client.deauthorizeauthorization.access_token# => String, access token being revoked
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.
Seestrava-oauth-token orstrava-ruby-cli for an example.
Strava provides aWebhook Event API.
A complete example that handles subscription creation, deletion and handling can be found instrava-webhooks. Runstrava-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 andstrava-webhooks delete [id]
to delete it.
Before creating a webhook subscription you must implement and run an HTTP server that will handle aGET
challenge at the subscription URL.
challenge=Strava::Webhooks::Models::Challenge.new(request.query)raise'Bad Request'unlesschallenge.verify_token =='token'response.content_type='application/json'response.body=challenge.response.to_json
SeeStrava::Webhooks::Models::Challenge for details.
An existing subscription must be handled in the same HTTP server'sPOST
request to the subscription URL.
event=Strava::Webhooks::Models::Event.new(JSON.parse(request.body))event# => Strava::Webhooks::Models::Eventevent.object_type# => 'activity'event.object_id# => 1991813808event.aspect_type# => 'update'event.updates# => { 'sport_type' => 'Walk' }event.owner_id# => 29323238event.subscription_id# => 131302event.event_time# => DateTime
SeeStrava::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::Subscriptionsubscription.id# => 131300subscription.callback_url# => 'http://example.com/strava'
SeeStrava::Webhooks::Models::Subscription for details.
List an existing subscription. Strava seems to only allow one.
subscriptions=client.push_subscriptionssubscription=subscriptions.first# => Strava::Webhooks::Models::Subscriptionsubscription.id# => 131300subscription.callback_url# => 'http://example.com/strava'
Delete an existing subscription.
client.delete_push_subscription(131300)# => nil
Every API call's HTTP Reponse 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 aStrava::Web::ApiResponse
class. Ratelimits are accessed via this class usingStrava::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::Athleteathlete.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 callingto_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}
Strava answers with HTTP status code 429, when ratelimits are exceeded. This will in return raiseStrava::Errors::RatelimitError
.
error.is_a?(Strava::Errors::RatelimitError)#=> trueerror.ratelimit.is_a?(Strava::Api::Ratelimit)#=> true# see Strava::Api::Ratelimit
You can configure web client options used in the OAuth and API clients, globally.
Strava::Web::Client.configuredo |config|config.user_agent='Strava Ruby Client/1.0'end
The following settings are supported.
setting | description |
---|---|
user_agent | User-agent, defaults toStrava Ruby Client/version. |
proxy | Optional HTTP proxy. |
ca_path | Optional SSL certificates path. |
ca_file | Optional SSL certificates file. |
logger | OptionalLogger instance that logs HTTP requests. |
timeout | Optional open/read timeout in seconds. |
open_timeout | Optional connection open timeout in seconds. |
The API client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance.
Strava::API.configuredo |config|config.access_token="..."# Strava access tokenend
client=Strava::API::Client.new(access_token:"...",user_agent:"...")
The following settings are supported.
setting | description |
---|---|
access_token | Access token to pass in theAuthorization header. |
endpoint | Defaults tohttps://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.configuredo |config|config.client_id="..."# Strava client IDconfig.client_secret="..."# Strava client secretend
client=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 tohttps://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.configuredo |config|config.client_id="..."# Strava client IDconfig.client_secret="..."# Strava client secretend
client=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 tohttps://www.strava.com/api/v3 . |
All errors that return HTTP codes 400-600 result in eitherFaraday::ResourceNotFound
,Faraday::ConnectionFailed
orStrava::Errors::Fault exceptions.
beginclient.oauth_token(code:'invalid')rescueStrava::Errors::Fault=>ee.message# => Bad Requeste.errors# => [{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }]e.headers# => { "status" => "403 Bad Request", "x-ratelimit-limit" => "600,30000", "x-ratelimit-usage" => "314,27536" }end
For a complete set of command-line tools, check outstrava-ruby-cli built on top of this gem.
Usestrava-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-token
- Slava: Strava integration with Slack,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
SeeUPGRADING.
SeeCONTRIBUTING.
Copyright (c) 2018,Daniel Doubrovkine andContributors.
This project is licensed under theMIT License.
About
A complete Ruby client for the Strava API v3.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors13
Uh oh!
There was an error while loading.Please reload this page.