smashrun-ruby 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9933ab7a4d03fabdde1506b9e11b0c6373db9550
4
- data.tar.gz: c4fd2cd6ea33c40da6b1b70b4fc98d2165439213
3
+ metadata.gz: 5381c533903a6cf6ed9e2feeaf75e21945061bd6
4
+ data.tar.gz: 62c5c9e78d90d8caac12b912f0294480aa8fad82
5
5
  SHA512:
6
- metadata.gz: 84bc5dbfb0c45811687fc4f73e51ee9ff6a7dc6b834760d588ea6342afea8f77297d737a701f08611d6e6da12c09607ef035374bfb8b428bdd40307088fefadd
7
- data.tar.gz: 1ad401357bd282d2f7773d6cf1d9e8b53a71d9b7c8bc5bdfe1e40266cc7cdde02391f018e43b530b4e7215e5532ba55b1b66f0caf785ddef45cbcdadb11306cc
6
+ metadata.gz: 0e3f77f0350dec2fdb39eda9fdf8279713e4af0ea99903046f626d8c91f4b57218fd6ca13c003b48533faa0df70e23538b61aa73084cdf1d5438a9155a352638
7
+ data.tar.gz: bc1d3caa4cc43e8b74377ca62f8edf78fe832f45a22bcf26a173d4fd6da4801b689db30301796d8c1559e6258df5b1fe89d2f5b386134a6321bc2d43058d78b7
@@ -0,0 +1,72 @@
1
+ # smashrun
2
+
3
+ Ruby gem for [Smashrun api](https://api.smashrun.com/v1/documentation)
4
+
5
+ Register your application for getting client id and secret: https://api.smashrun.com/register
6
+
7
+ ## Usage
8
+
9
+ ### Authentication
10
+
11
+ ```ruby
12
+ Smashrun.configure do |config|
13
+ config.client_id = 'your app client id'
14
+ config.client_secret = 'your app client secret'
15
+ end
16
+
17
+ client = Smashrun::Client.new(user_access_token)
18
+ ```
19
+
20
+ ### Refresh user's access token
21
+ Smashrun tokens are valid for 12 weeks, you can refresh access tokens using user's refresh token.
22
+
23
+ ```ruby
24
+ client.refresh_token(refresh_token)
25
+ ```
26
+ You better save new access token and refresh token.
27
+
28
+
29
+ ### Fetching activities
30
+
31
+ ```ruby
32
+ client.activities # => list of recent activities
33
+ ```
34
+ You can also use **fromDateUTC**, **page** or **count** for filtering and paginating activities list
35
+
36
+ ```ruby
37
+ client.activities page: 1, count: 100
38
+
39
+ client.activities fromDateUTC: 2.days.ago.to_i, page: 2
40
+ ```
41
+
42
+ If you want to minimize download size or need to quickly check for new activities, use following api methods instead.
43
+ ```ruby
44
+ client.latest_activities_briefs # retrive activities with minimal info( id, startTime, distance and duration)
45
+
46
+ client.latest_activities_ids # or just ids
47
+ ````
48
+
49
+
50
+ ### Fetching single activity detail
51
+
52
+ ```ruby
53
+ client.activity_detail activity_id # full activity detail
54
+ client.activity_svg_polyline activity_id # retrive SVG polyline for route of activity
55
+ client.activity_geojson activity_id # retrive activity route in GeoJSON format
56
+ client.activity_splits activity_id, 'distance_unit' # retrive splits of an activity in specified unit ( mi for mile and km for kilometer)
57
+ ````
58
+
59
+ ### Fetching user detail
60
+ ```ruby
61
+ client.athlete
62
+ ```
63
+
64
+ ### Posting new activities
65
+
66
+ Pending...
67
+
68
+
69
+ ## Copyright
70
+
71
+ Copyright (c) 20117 Naveed Ahmad. See LICENSE.txt for further details.
72
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -3,7 +3,7 @@ module Smashrun
3
3
  OAUTH_URLS = { site: 'https://api.smashrun.com',
4
4
  authorize_url: 'https://secure.smashrun.com/oauth2/authenticate',
5
5
  token_url: 'https://secure.smashrun.com/oauth2/token'
6
- }
6
+ }.freeze
7
7
 
8
8
  def initialize(access_token)
9
9
  client = OAuth2::Client.new(Smashrun.client_id, Smashrun.client_secret, OAUTH_URLS)
@@ -11,62 +11,63 @@ module Smashrun
11
11
  @token = OAuth2::AccessToken.new(client, access_token)
12
12
  end
13
13
 
14
- def get_refresh_token(token)
14
+ def refresh_token(token)
15
15
  @token.refresh_token = token
16
16
  @token.refresh!.to_hash
17
17
  end
18
18
 
19
- # Retrieve latest activities
20
- def get_activities()
21
- Oj.load(@token.get("/v1/my/activities").body)
22
- end
23
-
24
19
  # Filter activities, valid options are: *fromDateUTC*, *page* and *count*
25
- def search_activities(params={})
26
- Oj.load(@token.get("/v1/my/activities/search", params).body)
20
+ def activities(params={})
21
+ uri = params.present? ? "/v1/my/activities/search" : "/v1/my/activities"
22
+ request uri, params
27
23
  end
28
24
 
29
25
  # Returns the first 100 smashrun run ids.
30
26
  def latest_activities_ids
31
- Oj.load(@token.get("/v1/my/activities/search/ids").body)
27
+ request "/v1/my/activities/search/ids"
32
28
  end
33
29
 
34
30
  # Returns an array of json objects containing the runId, startTime, distance (in kilometers), and duration
35
31
  def latest_activities_briefs
36
- Oj.load(@token.get("/v1/my/activities/search/briefs").body)
32
+ request "/v1/my/activities/search/briefs"
37
33
  end
38
34
 
39
35
  # To retrieve a Google encoded polyline of a run route to easily draw a route map in Google maps.
40
36
  def activity_polyline(activity_id)
41
- Oj.load(@token.get("/v1/my/activities/#{activity_id}/polyline").body)
37
+ request "/v1/my/activities/#{activity_id}/polyline"
42
38
  end
43
-
39
+
44
40
  # To retrieve an SVG polyline of a run route.
45
41
  def activity_svg_polyline(activity_id)
46
- Oj.load(@token.get("/v1/my/activities/#{activity_id}/polyline/svg").body)
42
+ request "/v1/my/activities/#{activity_id}/polyline/svg"
47
43
  end
48
44
 
49
45
  # To retrieve a GeoJSON representation a run route.
50
46
  def activity_geojson(activity_id)
51
- Oj.load(@token.get("/v1/my/activities/#{activity_id}/polyline/geojson").body)
47
+ request "/v1/my/activities/#{activity_id}/polyline/geojson"
52
48
  end
53
-
49
+
54
50
  # To retrieve a detail of single activity.
55
51
  def activity_detail(activity_id)
56
- Oj.load(@token.get("/v1/my/activities/#{activity_id}").body)
52
+ request "/v1/my/activities/#{activity_id}"
57
53
  end
58
-
54
+
59
55
  # Retrive activity splits
60
56
  def activity_splits(activity_id, unit)
61
57
  unless ['km', 'mi'].include?(unit)
62
58
  raise ArgumentError.new("Invlaid distance unit for splits. Valid units are km or mi")
63
59
  end
64
-
65
- Oj.load(@token.get("/v1/my/activities/#{activity_id}/splits/#{unit}").body)
60
+
61
+ request "/v1/my/activities/#{activity_id}/splits/#{unit}"
62
+ end
63
+
64
+ def athlete
65
+ request "/v1/my/userinfo"
66
66
  end
67
67
 
68
- def profile_info
69
- Oj.load(@token.get("/v1/my/userinfo").body)
68
+ protected
69
+ def request(uri, params={})
70
+ Oj.load @token.get(uri, params).body
70
71
  end
71
72
  end
72
73
  end
@@ -2,28 +2,28 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: smashrun-ruby 0.1.2 ruby lib
5
+ # stub: smashrun-ruby 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "smashrun-ruby"
9
- s.version = "0.1.2"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Naveed Ahmad"]
14
- s.date = "2017-10-02"
14
+ s.date = "2017-10-03"
15
15
  s.description = "Ruby gem for Smashrun api"
16
16
  s.email = "naveedahmada036@gmail.com"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
23
  "Gemfile",
24
24
  "Gemfile.lock",
25
25
  "LICENSE.txt",
26
- "README.rdoc",
26
+ "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "lib/smashrun.rb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smashrun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naveed Ahmad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -100,13 +100,13 @@ executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files:
102
102
  - LICENSE.txt
103
- - README.rdoc
103
+ - README.md
104
104
  files:
105
105
  - ".document"
106
106
  - Gemfile
107
107
  - Gemfile.lock
108
108
  - LICENSE.txt
109
- - README.rdoc
109
+ - README.md
110
110
  - Rakefile
111
111
  - VERSION
112
112
  - lib/smashrun.rb
@@ -1,19 +0,0 @@
1
- = smashrun
2
-
3
- Description goes here.
4
-
5
- == Contributing to smashrun
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2017 Naveed Ahmad. See LICENSE.txt for
18
- further details.
19
-