Skip to content

niborg/strava-api-v3

 
 

Repository files navigation

strava-api-v3

Build Status Code Climate

This gem provides a wrapper around the Strava API V3 - http://strava.github.io/api/

Install

gem install 'strava-api-v3'

Create a client

At this point you will need to have the user authorise your application using OAuth2.

require 'strava/api/v3'

@client = Strava::Api::V3::Client.new(:access_token => "MY_ACCESS_TOKEN")

Call API methods

Activity

Each method returns a JSON object - see http://strava.github.io/api/v3/activities/ for more info

@client.retrieve_an_activity(:some_id)

@client.list_athlete_activities

@client.list_friends_activities

@client.list_activity_zones(:some_id)

@client.list_activity_laps(:some_id)

Activity extras

Each method returns a JSON object of respective type - see http://strava.github.io/api/v3/comments/, http://strava.github.io/api/v3/kudos/ and http://strava.github.io/api/v3/photos/ for more info

@client.list_activity_comments(:activity_id)

@client.list_activity_kudos(:activity_id)

@client.list_activity_photos(:activity_id) # only if you created the activity...

Athlete

Each method returns a JSON object - see http://strava.github.io/api/v3/athlete/ for more info

@client.retrieve_current_athlete # fetch the authenticated athlete

@client.retrieve_another_athlete(:some_id) # fetch another athlete by id

@client.list_athlete_segment_efforts(:some_id) # fetch K/QOMs/CRs for another athlete by id

@client.list_athlete_friends # fetch friends list

@client.list_specific_athlete_friends(:some_id) # fetch friends list another athlete by id

@client.totals_and_stats(:some_id) # fetch athlete totals and stats

Club

Each method returns a JSON object - see http://strava.github.io/api/v3/clubs/ for more info

@client.retrieve_a_club(:some_id)

@client.list_athlete_clubs

@client.list_club_members(:some_id)

@client.list_club_activities(:some_id)

Gear

Each method returns a JSON object - see http://strava.github.io/api/v3/gear/ for more info

@client.retrieve_gear(:some_id)

Route

Each method returns a JSON object - see http://strava.github.io/api/v3/routes/ for more info

@client.retrieve_a_route(:some_id)

@client.list_athlete_route

Segment

Each method returns a JSON object - see http://strava.github.io/api/v3/segments/ for more info

@client.retrieve_a_segment(:some_id)

@client.list_starred_segment

@client.segment_leaderboards(:some_id)

@client.segment_explorer

Segment Effort

Each method returns a JSON object - see http://strava.github.io/api/v3/efforts/ for more info

@client.retrieve_a_segment_effort(:some_id)

Stream

Each method returns a JSON object - see http://strava.github.io/api/v3/streams/ for more info

@client.retrieve_activity_streams(:some_id)

@client.retrieve_effort_streams(:some_id)

@client.retrieve_route_streams(:some_id)

@client.retrieve_segment_streams(:some_id)

Upload

Support for uploading activity files (FIT, TCX and GPX file types are supported by Strava. See https://strava.github.io/api/v3/uploads/ for more info

# Prepare options for upload
options = {}
options[:activity_type] = 'ride'
options[:data_type] = 'tcx'

# Open the file from the file systems
options[:file] = File.new('myfile.tcx')

# Submit upload and get upload ID
status = @client.upload_an_activity(options)
upload_id = status['id']

# Re-poll for status
status = @client.retrieve_upload_status(upload_id)

Authentication

Retrieve user token and information (athlete). See http://strava.github.io/api/v3/oauth for more info

access_information = Strava::Api::V3::Auth.retrieve_access('client_id', 'client_secret', 'code')
access_token = access_information['access_token']
athlete_information = access_information['athlete']

Contributors

  • Jared Holdcroft
  • James Chevalier

Packages

No packages published

Languages

  • Ruby 49.6%
  • CSS 44.4%
  • HTML 5.9%
  • JavaScript 0.1%