strava-ruby-client 0.3.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: 9a1b298638723dd74bcfe279fcaacb537f5026db4ecb2e92e990381b5dafded1
4
- data.tar.gz: 7186ed4468c5d027cac4a3dec6874f27e5d19ff0067b5a84cbd004d069d22127
3
+ metadata.gz: f045573621bd73cc02f898a0490f82e9dd23bb16c3bb19b59d8a221769f82b05
4
+ data.tar.gz: bad5418a5021c71875676cdcad683d436f2e3d657a1bf5dd0f235140d625c7fa
5
5
  SHA512:
6
- metadata.gz: 5355242600a38d9d72156a11b80f7e86b4c08d59696ace79db384d99819ca4358fc562e658f15f14e2bbd4c3a4ed42776fd828569972fef8da90ff396e74819e
7
- data.tar.gz: 485676cac51d01d18071132be42ff798dc12dfa127c8b4552baa7eb2f1189dd637869320b039057d1e6295ec2c81c71b6e45b101068d6dd691943c5bf13f12d0
6
+ metadata.gz: e7df01bd670072327b685ecfdeee70f9e2eb04be470a950baa6c7fb577236c263d8938c128ee9aad08c9290f8976883094a54f14fb621a8ebe8d5992a49e7741
7
+ data.tar.gz: 2044195773cb4676fd417d73746c4f0287f986f15a8fa997c703ae9aa3c857dabe65dc4533f102ca5ee077531d6d6a82ab1978f2d236892592fadc4b511ca155
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ### 0.4.1 (2021/07/11)
2
+
3
+ * [#37](https://github.com/dblock/strava-ruby-client/pull/38): Added `Club#club_events` - [@simonneutert](https://github.com/simonneutert).
4
+ * [#34](https://github.com/dblock/strava-ruby-client/pull/34): Added `Athlete#ftp` - [@virae](https://github.com/virae).
5
+
6
+ ### 0.4.0 (2020/05/09)
7
+
8
+ * [#29](https://github.com/dblock/strava-ruby-client/pull/29): Cache `Faraday::Connection` for persistent adapters - [@dblock](https://github.com/dblock).
9
+ * [#30](https://github.com/dblock/strava-ruby-client/pull/30): Require Faraday >= 1.0 - [@dblock](https://github.com/dblock).
10
+
11
+ ### 0.3.2 (2020/03/28)
12
+
13
+ * [#26](https://github.com/dblock/strava-ruby-client/pull/26): Corrected `Strava::Webhooks.config.endpoint` - [@dblock](https://github.com/dblock).
14
+ * Automatically convert `before` and `after` arguments of `Strava::Api::Client#athlete_activities` from `Time` to `Integer` - [@dblock](https://github.com/dblock).
15
+ * [#18](https://github.com/dblock/strava-ruby-client/pull/18): Testing against Ruby 2.5.3 and 2.6.0 - [@lucianosousa](https://github.com/lucianosousa).
16
+ * [#18](https://github.com/dblock/strava-ruby-client/pull/18): Upgraded Rubocop to 0.61.1 - [@lucianosousa](https://github.com/lucianosousa).
17
+ * [#21](https://github.com/dblock/strava-ruby-client/pull/21): Include headers in error response - [@jameschevalier](https://github.com/jameschevalier).
18
+
19
+ ### 0.3.1 (2018/12/05)
20
+
21
+ * Added `Strava::Api::Client#activity_photos` - [@dblock](https://github.com/dblock).
22
+ * [#2](https://github.com/dblock/strava-ruby-client/issues/2): Added `Strava::Api::Client#deauthorize` - [@dblock](https://github.com/dblock).
23
+ * [#15](https://github.com/dblock/strava-ruby-client/issues/15): Added `strava-oauth-token` and `strava-webhooks` to gem executables - [@dblock](https://github.com/dblock).
24
+ * Fix: `Strava::Models::Activity#total_elevation_gain` no returns blank for negative and zero elevation differences - [@dblock](https://github.com/dblock).
25
+ * Fix: `Strava::Models::Split#distance` and `total_elevation_gain` incorrect for `Strava::Models::Activity#splits_standard` - [@dblock](https://github.com/dblock).
26
+
1
27
  ### 0.3.0 (2018/12/03)
2
28
 
3
29
  * Added webhooks support - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -15,6 +15,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
15
15
  - [Activities](#activities)
16
16
  - [Create an Activity](#create-an-activity)
17
17
  - [Get Activity](#get-activity)
18
+ - [List Activity Photos](#list-activity-photos)
18
19
  - [List Activity Comments](#list-activity-comments)
19
20
  - [List Activity Kudoers](#list-activity-kudoers)
20
21
  - [List Activity Laps](#list-activity-laps)
@@ -60,6 +61,9 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
60
61
  - [Get Upload](#get-upload)
61
62
  - [Pagination](#pagination)
62
63
  - [OAuth](#oauth)
64
+ - [OAuth Workflow](#oauth-workflow)
65
+ - [Deauthorize](#deauthorize)
66
+ - [Command Line OAuth Workflow](#command-line-oauth-workflow)
63
67
  - [Webhooks](#webhooks)
64
68
  - [Configuration](#configuration)
65
69
  - [Web Client Options](#web-client-options)
@@ -69,6 +73,9 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
69
73
  - [Errors](#errors)
70
74
  - [Tools](#tools)
71
75
  - [Strava OAuth Token](#strava-oauth-token)
76
+ - [Users](#users)
77
+ - [Resources](#resources)
78
+ - [Upgrading](#upgrading)
72
79
  - [Contributing](#contributing)
73
80
  - [Copyright and License](#copyright-and-license)
74
81
 
@@ -143,6 +150,29 @@ google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadm
143
150
 
144
151
  See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.
145
152
 
153
+ #### List Activity Photos
154
+
155
+ Returns the photos on the given activity. This API is undocumented.
156
+
157
+ ```ruby
158
+ photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
159
+
160
+ photo = photos.first # => Strava::Models::Photo
161
+
162
+ photo.id # => nil
163
+ photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
164
+ photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
165
+ photo.athlete_id # => 26_462_176
166
+ photo.activity_id # => 1_946_417_534
167
+ photo.activity_name # => 'TCS NYC Marathon 2018'
168
+ photo.created_at # => Time
169
+ photo.uploaded_at # => Time
170
+ photo.sizes # => { '0' => [29, 64] }
171
+ photo.default_photo # => false
172
+ ```
173
+
174
+ See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.
175
+
146
176
  #### List Activity Comments
147
177
 
148
178
  Returns the comments on the given activity.
@@ -327,6 +357,20 @@ activity.name # => 'Afternoon Run'
327
357
 
328
358
  See [Strava::Models::Activity](lib/strava/models/activity.rb) for all available properties. Note that Strava does not return activity or athlete ID via this API.
329
359
 
360
+ #### List Club Events
361
+
362
+ Retrieve recent Events from a specific club.
363
+
364
+ ```ruby
365
+ events = client.club_events(108605) # => Array[Strava::Models::ClubEvent]
366
+
367
+ event = events.first # => Strava::Models::ClubEvent
368
+
369
+ event.title # => 'First Group Event Ever! Yippieh!'
370
+ ```
371
+
372
+ See [Strava::Models::ClubEvent](lib/strava/models/club_event.rb) for all available properties.
373
+
330
374
  #### List Club Administrators
331
375
 
332
376
  Returns a list of the administrators of a given club.
@@ -760,7 +804,9 @@ end
760
804
 
761
805
  ### OAuth
762
806
 
763
- Obtain a redirect URL.
807
+ #### OAuth Workflow
808
+
809
+ Obtain a redirect URL using an instance of `Strava::OAuth::Client`.
764
810
 
765
811
  ```ruby
766
812
  client = Strava::OAuth::Client.new(
@@ -800,16 +846,32 @@ response = client.oauth_token(
800
846
  grant_type: 'refresh_token'
801
847
  )
802
848
 
803
- response.access_token # new access token
804
- response.refresh_token # new refresh token
805
- response.expires_at # new timestamp when the access token expires
849
+ response.access_token # => String, new access token
850
+ response.refresh_token # => String, new refresh token
851
+ response.expires_at # => Time, new timestamp when the access token expires
852
+ ```
853
+
854
+ #### Deauthorize
855
+
856
+ Revoke access to an athlete's data using an instance of `Strava::API::Client`.
857
+
858
+ ```ruby
859
+ authorization = client.deauthorize
860
+
861
+ authorization.access_token # => String, access token being revoked
806
862
  ```
807
863
 
864
+ #### Command Line OAuth Workflow
865
+
866
+ 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.
867
+
868
+ See [strava-oauth-token](/bin/strava-oauth-token) or [strava-ruby-cli](https://github.com/dblock/strava-ruby-cli) for an example.
869
+
808
870
  ### Webhooks
809
871
 
810
- Strava provides a [Webhook Event API](https://developers.strava.com/docs/webhooks/) that requires special access obtained by emailing [developers@strava.com](mailto:developers@strava.com).
872
+ Strava provides a [Webhook Event API](https://developers.strava.com/docs/webhooks/).
811
873
 
812
- A complete example that handles subscription creation, deletion and handling can be found in [strava-webhooks.rb](bin/strava-webhooks.rb). 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.
874
+ A complete example that handles subscription creation, deletion and handling can be found in [strava-webhooks](bin/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.
813
875
 
814
876
  Before creating a webhook subscription you must implement and run an HTTP server that will handle a `GET` challenge at the subscription URL.
815
877
 
@@ -978,11 +1040,11 @@ setting | description
978
1040
  --------------------|------------
979
1041
  client_id | Application client ID.
980
1042
  client_secret | Application client secret.
981
- endpoint | Defaults to `https://api.strava.com/api/v3`.
1043
+ endpoint | Defaults to `https://www.strava.com/api/v3`.
982
1044
 
983
1045
  ## Errors
984
1046
 
985
- All errors that return HTTP codes 400-600 result in either `Faraday::Error::ResourceNotFound`, `Faraday::Error::ConnectionFailed` or [Strava::Errors::Fault](lib/strava/errors/fault.rb) exceptions.
1047
+ All errors that return HTTP codes 400-600 result in either `Faraday::ResourceNotFound`, `Faraday::ConnectionFailed` or [Strava::Errors::Fault](lib/strava/errors/fault.rb) exceptions.
986
1048
 
987
1049
  ```ruby
988
1050
  begin
@@ -990,19 +1052,40 @@ begin
990
1052
  rescue Strava::Errors::Fault => e
991
1053
  e.message # => Bad Request
992
1054
  e.errors # => [{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }]
1055
+ e.headers # => { "status" => "403 Bad Request", "x-ratelimit-limit" => "600,30000", "x-ratelimit-usage" => "314,27536" }
993
1056
  end
994
1057
  ```
995
1058
 
996
1059
  ## Tools
997
1060
 
1061
+ For a complete set of command-line tools, check out [strava-ruby-cli](https://github.com/dblock/strava-ruby-cli) built on top of this gem.
1062
+
998
1063
  ### Strava OAuth Token
999
1064
 
1000
- Use [strava-oauth-token](bin/strava-outh-token.rb) 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.
1065
+ Use [strava-oauth-token](bin/strava-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.
1001
1066
 
1002
1067
  ```bash
1003
1068
  $ STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-token
1004
1069
  ```
1005
1070
 
1071
+ ## Users
1072
+
1073
+ * [Slava: Strava integration with Slack](https://slava.playplay.io), [source](https://github.com/dblock/slack-strava).
1074
+ * [Jekyll Blog at run.dblock.org](https://run.dblock.org), [source](https://github.com/dblock/run.dblock.org)
1075
+ * [Secret Strava](https://steele.blue/secret-strava/), [source](https://github.com/mattdsteele/secret-strava)
1076
+
1077
+ ## Resources
1078
+
1079
+ * [Strava API Documentation](https://developers.strava.com)
1080
+ * [Writing a New Strava API Ruby Client](https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html)
1081
+ * [Dealing with Strava API OAuth Token Migration](https://code.dblock.org/2018/11/17/dealing-with-strava-api-token-migration.html)
1082
+ * [Auto-Publishing Strava Runs to Github Pages](https://code.dblock.org/2018/02/17/auto-publishing-strava-runs-to-github-pages.html)
1083
+ * [Strava Command-Line Client](https://github.com/dblock/strava-ruby-cli)
1084
+
1085
+ ## Upgrading
1086
+
1087
+ See [UPGRADING](UPGRADING.md).
1088
+
1006
1089
  ## Contributing
1007
1090
 
1008
1091
  See [CONTRIBUTING](CONTRIBUTING.md).
File without changes
File without changes
@@ -25,6 +25,7 @@ require_relative 'strava/models/map'
25
25
  require_relative 'strava/models/activity'
26
26
  require_relative 'strava/models/club'
27
27
  require_relative 'strava/models/club_admin'
28
+ require_relative 'strava/models/club_event'
28
29
  require_relative 'strava/models/club_member'
29
30
  require_relative 'strava/models/segment_effort'
30
31
  require_relative 'strava/models/photos'
@@ -55,6 +56,7 @@ require_relative 'strava/models/explorer_segment'
55
56
  require_relative 'strava/models/stream_set'
56
57
  require_relative 'strava/models/stream'
57
58
  require_relative 'strava/models/upload'
59
+ require_relative 'strava/models/authorization'
58
60
 
59
61
  require_relative 'strava/web/raise_error'
60
62
  require_relative 'strava/web/connection'
@@ -84,5 +86,6 @@ require_relative 'strava/api/endpoints/segment_efforts'
84
86
  require_relative 'strava/api/endpoints/segments'
85
87
  require_relative 'strava/api/endpoints/streams'
86
88
  require_relative 'strava/api/endpoints/uploads'
89
+ require_relative 'strava/api/endpoints/oauth'
87
90
 
88
91
  require_relative 'strava/api/client'
@@ -11,6 +11,7 @@ module Strava
11
11
  include Endpoints::Segments
12
12
  include Endpoints::Streams
13
13
  include Endpoints::Uploads
14
+ include Endpoints::OAuth
14
15
 
15
16
  attr_accessor(*Config::ATTRIBUTES)
16
17
 
@@ -35,6 +35,21 @@ module Strava
35
35
  paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
36
36
  end
37
37
 
38
+ #
39
+ # List activity photos.
40
+ #
41
+ # @option options [String] :id
42
+ # Activity id.
43
+ # @option options [Integer] :page
44
+ # Page number.
45
+ # @option options [Integer] :per_page
46
+ # Number of items per page. Defaults to 30.
47
+ #
48
+ def activity_photos(id_or_options, options = {}, &block)
49
+ id, options = parse_args(id_or_options, options)
50
+ paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
51
+ end
52
+
38
53
  #
39
54
  # List activity kudoers.
40
55
  #
@@ -76,6 +91,9 @@ module Strava
76
91
  # Number of items per page. Defaults to 30.
77
92
  #
78
93
  def athlete_activities(options = {}, &block)
94
+ options = options.dup if options.key?(:after) || options.key?(:before)
95
+ options[:after] = options[:after].to_i if options[:after]
96
+ options[:before] = options[:before].to_i if options[:before]
79
97
  paginate 'athlete/activities', options, Strava::Models::Activity, &block
80
98
  end
81
99
 
@@ -17,6 +17,21 @@ module Strava
17
17
  paginate "clubs/#{id}/activities", options, Strava::Models::Activity, &block
18
18
  end
19
19
 
20
+ #
21
+ # List club / group events.
22
+ #
23
+ # @option options [String] :id
24
+ # Club id.
25
+ # @option options [Integer] :page
26
+ # Page number.
27
+ # @option options [Integer] :per_page
28
+ # Number of items per page. Defaults to 30.
29
+ #
30
+ def club_events(id_or_options, options = {}, &block)
31
+ id, options = parse_args(id_or_options, options)
32
+ paginate "clubs/#{id}/group_events", options, Strava::Models::ClubEvent, &block
33
+ end
34
+
20
35
  #
21
36
  # List club administrators.
22
37
  #
@@ -0,0 +1,14 @@
1
+ module Strava
2
+ module Api
3
+ module Endpoints
4
+ module OAuth
5
+ #
6
+ # Revoke access to an athlete's data.
7
+ #
8
+ def deauthorize(options = {})
9
+ Strava::Models::Authorization.new(post('deauthorize', { endpoint: Strava::OAuth.config.endpoint }.merge(options)))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -5,6 +5,10 @@ module Strava
5
5
  response[:body]['message'] || super
6
6
  end
7
7
 
8
+ def headers
9
+ response[:headers]
10
+ end
11
+
8
12
  def errors
9
13
  response[:body]['errors']
10
14
  end
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class Activity < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
  include Mixins::Time
6
6
  include Mixins::Elevation
7
7
 
@@ -60,8 +60,8 @@ module Strava
60
60
  property 'similar_activities', transform_with: ->(v) { Strava::Models::SimilarActivities.new(v) }
61
61
  property 'embed_token'
62
62
  property 'available_zones'
63
- property 'splits_metric', transform_with: ->(v) { v.map { |r| Strava::Models::Split::Metric.new(r) } }
64
- property 'splits_standard', transform_with: ->(v) { v.map { |r| Strava::Models::Split::Standard.new(r) } }
63
+ property 'splits_metric', transform_with: ->(v) { v.map { |r| Strava::Models::Split.new(r) } }
64
+ property 'splits_standard', transform_with: ->(v) { v.map { |r| Strava::Models::Split.new(r) } }
65
65
  property 'laps', transform_with: ->(v) { v.map { |r| Strava::Models::Lap.new(r) } }
66
66
  property 'gear', transform_with: ->(v) { Strava::Models::Gear.new(v) }
67
67
  property 'device_name'
@@ -78,30 +78,18 @@ module Strava
78
78
 
79
79
  def distance_s
80
80
  if type == 'Swim'
81
- case units
82
- when :metric then distance_in_meters_s
83
- when :imperial then distance_in_yards_s
84
- end
81
+ distance_in_meters_s
85
82
  else
86
- case units
87
- when :metric then distance_in_kilometers_s
88
- when :imperial then distance_in_miles_s
89
- end
83
+ distance_in_kilometers_s
90
84
  end
91
85
  end
92
86
 
93
87
  def pace_s
94
88
  case type
95
89
  when 'Swim'
96
- case units
97
- when :metric then pace_per_100_meters_s
98
- when :imperial then pace_per_100_yards_s
99
- end
90
+ pace_per_100_meters_s
100
91
  else
101
- case units
102
- when :metric then pace_per_kilometer_s
103
- when :imperial then pace_per_mile_s
104
- end
92
+ pace_per_kilometer_s
105
93
  end
106
94
  end
107
95
 
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class ActivityTotal < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
  include Mixins::Time
6
6
  include Mixins::Elevation
7
7
 
@@ -27,6 +27,7 @@ module Strava
27
27
  property 'date_preference'
28
28
  property 'measurement_preference'
29
29
  property 'clubs', transform_with: ->(v) { v.map { |r| Strava::Models::Club.new(r) } }
30
+ property 'ftp'
30
31
  property 'weight'
31
32
  property 'bikes', transform_with: ->(v) { v.map { |r| Strava::Models::Gear.new(r) } }
32
33
  property 'shoes', transform_with: ->(v) { v.map { |r| Strava::Models::Gear.new(r) } }
@@ -0,0 +1,7 @@
1
+ module Strava
2
+ module Models
3
+ class Authorization < Model
4
+ property 'access_token'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module Strava
2
+ module Models
3
+ class ClubEvent < Model
4
+ property 'id'
5
+ property 'resource_state'
6
+ property 'title'
7
+ property 'club_id'
8
+ property 'club', transform_with: ->(c) { Strava::Models::Club.new(c) }
9
+ property 'organizing_athlete', transform_with: ->(oa) { Strava::Models::Athlete.new(oa) }
10
+ property 'activity_type'
11
+ property 'created_at', transform_with: ->(v) { Time.parse(v) }
12
+ property 'route_id'
13
+ property 'route', transform_with: ->(r) { Strava::Models::Route.new(r) }
14
+ property 'women_only'
15
+ property 'private'
16
+ property 'skill_levels'
17
+ property 'terrain'
18
+ property 'upcoming_occurrences', transform_with: ->(upcoming) { upcoming.map { |o| Time.parse(o) } }
19
+ property 'zone'
20
+ property 'address'
21
+ property 'start_latlng'
22
+
23
+ def strava_url
24
+ "https://www.strava.com/clubs/#{club_id}/group_events/#{id}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class ExplorerSegment < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
 
6
6
  property 'id'
7
7
  property 'resource_state'
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class Gear < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
 
6
6
  property 'id'
7
7
  property 'resource_state'
@@ -9,24 +9,15 @@ module Strava
9
9
  end
10
10
 
11
11
  def distance_in_meters
12
- case units
13
- when :metric then distance
14
- when :imperial then distance / 3.28084
15
- end
12
+ distance
16
13
  end
17
14
 
18
15
  def distance_in_feet
19
- case units
20
- when :metric then distance * 3.28084
21
- when :imperial then distance
22
- end
16
+ distance * 3.28084
23
17
  end
24
18
 
25
19
  def distance_in_miles
26
- case units
27
- when :metric then distance_in_meters * 0.00062137
28
- when :imperial then distance_in_feet / 5280
29
- end
20
+ distance_in_meters * 0.00062137
30
21
  end
31
22
 
32
23
  def distance_in_miles_s
@@ -62,28 +53,7 @@ module Strava
62
53
  end
63
54
 
64
55
  def distance_s
65
- case units
66
- when :metric then distance_in_kilometers_s
67
- when :imperial then distance_in_miles_s
68
- end
69
- end
70
- end
71
-
72
- module MetricDistance
73
- extend ActiveSupport::Concern
74
- include Strava::Models::Mixins::Distance
75
-
76
- def units
77
- :metric
78
- end
79
- end
80
-
81
- module ImperialDistance
82
- extend ActiveSupport::Concern
83
- include Strava::Models::Mixins::Distance
84
-
85
- def units
86
- :imperial
56
+ distance_in_kilometers_s
87
57
  end
88
58
  end
89
59
  end
@@ -9,36 +9,27 @@ module Strava
9
9
  end
10
10
 
11
11
  def total_elevation_gain_in_feet
12
- case units
13
- when :metric then total_elevation_gain * 3.28084
14
- when :imperial then total_elevation_gain
15
- end
12
+ total_elevation_gain * 3.28084
16
13
  end
17
14
 
18
15
  def total_elevation_gain_in_meters
19
- case units
20
- when :metric then total_elevation_gain
21
- when :imperial then total_elevation_gain / 3.28084
22
- end
16
+ total_elevation_gain
23
17
  end
24
18
 
25
19
  def total_elevation_gain_in_meters_s
26
- return unless total_elevation_gain && total_elevation_gain.positive?
20
+ return if total_elevation_gain.nil?
27
21
 
28
22
  format('%gm', format('%.1f', total_elevation_gain_in_meters))
29
23
  end
30
24
 
31
25
  def total_elevation_gain_in_feet_s
32
- return unless total_elevation_gain && total_elevation_gain.positive?
26
+ return if total_elevation_gain.nil?
33
27
 
34
28
  format('%gft', format('%.1f', total_elevation_gain_in_feet))
35
29
  end
36
30
 
37
31
  def total_elevation_gain_s
38
- case units
39
- when :metric then total_elevation_gain_in_meters_s
40
- when :imperial then total_elevation_gain_in_feet_s
41
- end
32
+ total_elevation_gain_in_meters_s
42
33
  end
43
34
  end
44
35
  end
@@ -52,10 +52,7 @@ module Strava
52
52
  end
53
53
 
54
54
  def speed_s
55
- case units
56
- when :metric then kilometer_per_hour_s
57
- when :imperial then miles_per_hour_s
58
- end
55
+ kilometer_per_hour_s
59
56
  end
60
57
 
61
58
  private
@@ -5,6 +5,16 @@ module Strava
5
5
  property 'unique_id'
6
6
  property 'urls'
7
7
  property 'source'
8
+ property 'athlete_id'
9
+ property 'activity_id'
10
+ property 'activity_name'
11
+ property 'resource_state'
12
+ property 'caption'
13
+ property 'created_at', transform_with: ->(v) { Time.parse(v) }
14
+ property 'created_at_local', transform_with: ->(v) { Time.parse(v) }
15
+ property 'uploaded_at', transform_with: ->(v) { Time.parse(v) }
16
+ property 'sizes'
17
+ property 'default_photo'
8
18
  end
9
19
  end
10
20
  end
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class Route < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
  include Mixins::Elevation
6
6
  include Mixins::Time
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class RunningRace < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
 
6
6
  property 'id'
7
7
  property 'resource_state'
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class Segment < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
  include Mixins::Elevation
6
6
  include Mixins::Time
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Strava
2
2
  module Models
3
3
  class SegmentEffort < Model
4
- include Mixins::MetricDistance
4
+ include Mixins::Distance
5
5
  include Mixins::Time
6
6
 
7
7
  property 'id'
@@ -10,20 +10,6 @@ module Strava
10
10
  property 'split'
11
11
  property 'average_heartrate'
12
12
  property 'pace_zone'
13
-
14
- class Standard < Split
15
- private
16
-
17
- def units
18
- :imperial
19
- end
20
- end
21
-
22
- class Metric < Split
23
- def units
24
- :metric
25
- end
26
- end
27
13
  end
28
14
  end
29
15
  end
@@ -1,3 +1,3 @@
1
1
  module Strava
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -8,26 +8,28 @@ module Strava
8
8
  end
9
9
 
10
10
  def connection
11
- options = {
12
- headers: headers.merge('Accept' => 'application/json; charset=utf-8')
13
- }
11
+ @connection ||= begin
12
+ options = {
13
+ headers: headers.merge('Accept' => 'application/json; charset=utf-8')
14
+ }
14
15
 
15
- options[:headers]['User-Agent'] = user_agent if user_agent
16
- options[:proxy] = proxy if proxy
17
- options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
16
+ options[:headers]['User-Agent'] = user_agent if user_agent
17
+ options[:proxy] = proxy if proxy
18
+ options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
18
19
 
19
- request_options = {}
20
- request_options[:timeout] = timeout if timeout
21
- request_options[:open_timeout] = open_timeout if open_timeout
22
- options[:request] = request_options if request_options.any?
20
+ request_options = {}
21
+ request_options[:timeout] = timeout if timeout
22
+ request_options[:open_timeout] = open_timeout if open_timeout
23
+ options[:request] = request_options if request_options.any?
23
24
 
24
- ::Faraday::Connection.new(endpoint, options) do |connection|
25
- connection.use ::Faraday::Request::Multipart
26
- connection.use ::Faraday::Request::UrlEncoded
27
- connection.use ::Strava::Web::Response::RaiseError
28
- connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
29
- connection.response :logger, logger if logger
30
- connection.adapter ::Faraday.default_adapter
25
+ ::Faraday::Connection.new(endpoint, options) do |connection|
26
+ connection.use ::Faraday::Request::Multipart
27
+ connection.use ::Faraday::Request::UrlEncoded
28
+ connection.use ::Strava::Web::Response::RaiseError
29
+ connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
30
+ connection.response :logger, logger if logger
31
+ connection.adapter ::Faraday.default_adapter
32
+ end
31
33
  end
32
34
  end
33
35
  end
@@ -7,10 +7,10 @@ module Strava
7
7
  def on_complete(env)
8
8
  case env[:status]
9
9
  when 404
10
- raise Faraday::Error::ResourceNotFound, response_values(env)
10
+ raise Faraday::ResourceNotFound, response_values(env)
11
11
  when 407
12
12
  # mimic the behavior that we get with proxy requests with HTTPS
13
- raise Faraday::Error::ConnectionFailed, %(407 "Proxy Authentication Required ")
13
+ raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
14
14
  when ClientErrorStatuses
15
15
  raise Strava::Errors::Fault, response_values(env)
16
16
  end
@@ -20,7 +20,9 @@ module Strava
20
20
  private
21
21
 
22
22
  def request(method, path, options)
23
- path = [endpoint, path].join('/')
23
+ options = options.dup if options.key?(:request) || options.key?(:endpoint)
24
+ root = options.delete(:endpoint) || endpoint
25
+ path = [root, path].join('/')
24
26
  response = connection.send(method) do |request|
25
27
  case method
26
28
  when :get, :delete
@@ -12,7 +12,7 @@ module Strava
12
12
  attr_accessor(*Config::ATTRIBUTES)
13
13
 
14
14
  def reset
15
- self.endpoint = 'https://api.strava.com/api/v3'
15
+ self.endpoint = 'https://www.strava.com/api/v3'
16
16
  self.client_id = nil
17
17
  self.client_secret = nil
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strava-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2021-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.9'
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.9'
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday_middleware
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,17 +66,19 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
69
+ description:
70
70
  email: dblock@dblock.org
71
- executables: []
71
+ executables:
72
+ - strava-oauth-token
73
+ - strava-webhooks
72
74
  extensions: []
73
75
  extra_rdoc_files: []
74
76
  files:
75
77
  - CHANGELOG.md
76
78
  - LICENSE.md
77
79
  - README.md
78
- - bin/strava-oauth-token.rb
79
- - bin/strava-webhooks.rb
80
+ - bin/strava-oauth-token
81
+ - bin/strava-webhooks
80
82
  - lib/strava-ruby-client.rb
81
83
  - lib/strava/api/client.rb
82
84
  - lib/strava/api/config.rb
@@ -85,6 +87,7 @@ files:
85
87
  - lib/strava/api/endpoints/athletes.rb
86
88
  - lib/strava/api/endpoints/clubs.rb
87
89
  - lib/strava/api/endpoints/gears.rb
90
+ - lib/strava/api/endpoints/oauth.rb
88
91
  - lib/strava/api/endpoints/routes.rb
89
92
  - lib/strava/api/endpoints/running_races.rb
90
93
  - lib/strava/api/endpoints/segment_efforts.rb
@@ -99,8 +102,10 @@ files:
99
102
  - lib/strava/models/activity_total.rb
100
103
  - lib/strava/models/activity_zone.rb
101
104
  - lib/strava/models/athlete.rb
105
+ - lib/strava/models/authorization.rb
102
106
  - lib/strava/models/club.rb
103
107
  - lib/strava/models/club_admin.rb
108
+ - lib/strava/models/club_event.rb
104
109
  - lib/strava/models/club_member.rb
105
110
  - lib/strava/models/comment.rb
106
111
  - lib/strava/models/explorer_segment.rb
@@ -150,7 +155,7 @@ homepage: http://github.com/dblock/strava-ruby-client
150
155
  licenses:
151
156
  - MIT
152
157
  metadata: {}
153
- post_install_message:
158
+ post_install_message:
154
159
  rdoc_options: []
155
160
  require_paths:
156
161
  - lib
@@ -165,9 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
170
  - !ruby/object:Gem::Version
166
171
  version: 1.3.6
167
172
  requirements: []
168
- rubyforge_project:
169
- rubygems_version: 2.7.6
170
- signing_key:
173
+ rubygems_version: 3.0.6
174
+ signing_key:
171
175
  specification_version: 4
172
176
  summary: Strava API Ruby client.
173
177
  test_files: []