Class: Smashrun::Client
- Inherits:
-
Object
- Object
- Smashrun::Client
- Defined in:
- lib/smashrun/client.rb
Constant Summary collapse
- OAUTH_URLS =
{ site: 'https://api.smashrun.com', authorize_url: 'https://secure.smashrun.com/oauth2/authenticate', token_url: 'https://secure.smashrun.com/oauth2/token' }.freeze
Instance Method Summary collapse
-
#activities(params = {}) ⇒ Object
Filter activities, valid options are: fromDateUTC, page and count.
-
#activity_detail(activity_id) ⇒ Object
To retrieve a detail of single activity.
-
#activity_geojson(activity_id) ⇒ Object
To retrieve a GeoJSON representation a run route.
-
#activity_polyline(activity_id) ⇒ Object
To retrieve a Google encoded polyline of a run route to easily draw a route map in Google maps.
-
#activity_splits(activity_id, unit) ⇒ Object
Retrive activity splits.
-
#activity_svg_polyline(activity_id) ⇒ Object
To retrieve an SVG polyline of a run route.
- #athlete ⇒ Object
-
#initialize(access_token) ⇒ Client
constructor
A new instance of Client.
-
#latest_activities_briefs ⇒ Object
Returns an array of json objects containing the runId, startTime, distance (in kilometers), and duration.
-
#latest_activities_ids ⇒ Object
Returns the first 100 smashrun run ids.
- #refresh_token(token) ⇒ Object
Constructor Details
#initialize(access_token) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/smashrun/client.rb', line 8 def initialize(access_token) client = OAuth2::Client.new(Smashrun.client_id, Smashrun.client_secret, OAUTH_URLS) @token = OAuth2::AccessToken.new(client, access_token) end |
Instance Method Details
#activities(params = {}) ⇒ Object
Filter activities, valid options are: fromDateUTC, page and count
20 21 22 23 |
# File 'lib/smashrun/client.rb', line 20 def activities(params={}) uri = params.present? ? "/v1/my/activities/search" : "/v1/my/activities" request uri, params end |
#activity_detail(activity_id) ⇒ Object
To retrieve a detail of single activity.
51 52 53 |
# File 'lib/smashrun/client.rb', line 51 def activity_detail(activity_id) request "/v1/my/activities/#{activity_id}" end |
#activity_geojson(activity_id) ⇒ Object
To retrieve a GeoJSON representation a run route.
46 47 48 |
# File 'lib/smashrun/client.rb', line 46 def activity_geojson(activity_id) request "/v1/my/activities/#{activity_id}/polyline/geojson" end |
#activity_polyline(activity_id) ⇒ Object
To retrieve a Google encoded polyline of a run route to easily draw a route map in Google maps.
36 37 38 |
# File 'lib/smashrun/client.rb', line 36 def activity_polyline(activity_id) request "/v1/my/activities/#{activity_id}/polyline" end |
#activity_splits(activity_id, unit) ⇒ Object
Retrive activity splits
56 57 58 59 60 61 62 |
# File 'lib/smashrun/client.rb', line 56 def activity_splits(activity_id, unit) unless ['km', 'mi'].include?(unit) raise ArgumentError.new("Invlaid distance unit for splits. Valid units are km or mi") end request "/v1/my/activities/#{activity_id}/splits/#{unit}" end |
#activity_svg_polyline(activity_id) ⇒ Object
To retrieve an SVG polyline of a run route.
41 42 43 |
# File 'lib/smashrun/client.rb', line 41 def activity_svg_polyline(activity_id) request "/v1/my/activities/#{activity_id}/polyline/svg" end |
#athlete ⇒ Object
64 65 66 |
# File 'lib/smashrun/client.rb', line 64 def athlete request "/v1/my/userinfo" end |
#latest_activities_briefs ⇒ Object
Returns an array of json objects containing the runId, startTime, distance (in kilometers), and duration
31 32 33 |
# File 'lib/smashrun/client.rb', line 31 def latest_activities_briefs request "/v1/my/activities/search/briefs" end |
#latest_activities_ids ⇒ Object
Returns the first 100 smashrun run ids.
26 27 28 |
# File 'lib/smashrun/client.rb', line 26 def latest_activities_ids request "/v1/my/activities/search/ids" end |
#refresh_token(token) ⇒ Object
14 15 16 17 |
# File 'lib/smashrun/client.rb', line 14 def refresh_token(token) @token.refresh_token = token @token.refresh!.to_hash end |