strava-ruby-client 0.3.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +60 -10
- data/lib/strava/api/endpoints/activities.rb +3 -0
- data/lib/strava/api/endpoints/clubs.rb +15 -0
- data/lib/strava/errors/fault.rb +4 -0
- data/lib/strava/models/athlete.rb +1 -0
- data/lib/strava/models/club_event.rb +28 -0
- data/lib/strava/models/gear.rb +3 -0
- data/lib/strava/version.rb +1 -1
- data/lib/strava/web/connection.rb +19 -17
- data/lib/strava/web/raise_error.rb +2 -2
- data/lib/strava/webhooks/config.rb +1 -1
- data/lib/strava-ruby-client.rb +1 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c405363163b2332c696362fcaecc55b27ebcc9cc36dc78bfff54059d4433a580
|
4
|
+
data.tar.gz: a555beb0bf2072cf7cfe40a8178e72d0d4bc846963446704a642e344d46f780e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca090cb5fc5553cbf275f36e797e90cbede14cbe8c400520b79a4ddd061719878e3f1b38e13efbf948bab884f5ab62f8d5b5e49812cc154af155e78bd3601dfc
|
7
|
+
data.tar.gz: 662f42daf772d75c032a2f228f4d0a2f268c8de68a9ea91b95cae9840d0a185c3a159df5023b182026fd47deaa5909494b06d3b03e91cd85ac74bed66a249239
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
### 0.4.2 (2021/10/03)
|
2
|
+
|
3
|
+
* [#45](https://github.com/dblock/strava-ruby-client/pull/45): Added `Gear#frame_type` `#retired` `#weight` - [@deuber](https://github.com/deuber).
|
4
|
+
|
5
|
+
### 0.4.1 (2021/07/11)
|
6
|
+
|
7
|
+
* [#37](https://github.com/dblock/strava-ruby-client/pull/38): Added `Club#club_events` - [@simonneutert](https://github.com/simonneutert).
|
8
|
+
* [#34](https://github.com/dblock/strava-ruby-client/pull/34): Added `Athlete#ftp` - [@virae](https://github.com/virae).
|
9
|
+
|
10
|
+
### 0.4.0 (2020/05/09)
|
11
|
+
|
12
|
+
* [#29](https://github.com/dblock/strava-ruby-client/pull/29): Cache `Faraday::Connection` for persistent adapters - [@dblock](https://github.com/dblock).
|
13
|
+
* [#30](https://github.com/dblock/strava-ruby-client/pull/30): Require Faraday >= 1.0 - [@dblock](https://github.com/dblock).
|
14
|
+
|
15
|
+
### 0.3.2 (2020/03/28)
|
16
|
+
|
17
|
+
* [#26](https://github.com/dblock/strava-ruby-client/pull/26): Corrected `Strava::Webhooks.config.endpoint` - [@dblock](https://github.com/dblock).
|
18
|
+
* Automatically convert `before` and `after` arguments of `Strava::Api::Client#athlete_activities` from `Time` to `Integer` - [@dblock](https://github.com/dblock).
|
19
|
+
* [#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).
|
20
|
+
* [#18](https://github.com/dblock/strava-ruby-client/pull/18): Upgraded Rubocop to 0.61.1 - [@lucianosousa](https://github.com/lucianosousa).
|
21
|
+
* [#21](https://github.com/dblock/strava-ruby-client/pull/21): Include headers in error response - [@jameschevalier](https://github.com/jameschevalier).
|
22
|
+
|
1
23
|
### 0.3.1 (2018/12/05)
|
2
24
|
|
3
25
|
* Added `Strava::Api::Client#activity_photos` - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
29
29
|
- [Update Athlete](#update-athlete)
|
30
30
|
- [Clubs](#clubs)
|
31
31
|
- [List Club Activities](#list-club-activities)
|
32
|
+
- [List Club Events](#list-club-events)
|
32
33
|
- [List Club Administrators](#list-club-administrators)
|
33
34
|
- [Get Club](#get-club)
|
34
35
|
- [List Club Members](#list-club-members)
|
@@ -63,6 +64,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
63
64
|
- [OAuth](#oauth)
|
64
65
|
- [OAuth Workflow](#oauth-workflow)
|
65
66
|
- [Deauthorize](#deauthorize)
|
67
|
+
- [Command Line OAuth Workflow](#command-line-oauth-workflow)
|
66
68
|
- [Webhooks](#webhooks)
|
67
69
|
- [Configuration](#configuration)
|
68
70
|
- [Web Client Options](#web-client-options)
|
@@ -72,6 +74,9 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
72
74
|
- [Errors](#errors)
|
73
75
|
- [Tools](#tools)
|
74
76
|
- [Strava OAuth Token](#strava-oauth-token)
|
77
|
+
- [Users](#users)
|
78
|
+
- [Resources](#resources)
|
79
|
+
- [Upgrading](#upgrading)
|
75
80
|
- [Contributing](#contributing)
|
76
81
|
- [Copyright and License](#copyright-and-license)
|
77
82
|
|
@@ -353,6 +358,20 @@ activity.name # => 'Afternoon Run'
|
|
353
358
|
|
354
359
|
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.
|
355
360
|
|
361
|
+
#### List Club Events
|
362
|
+
|
363
|
+
Retrieve recent Events from a specific club.
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
events = client.club_events(108605) # => Array[Strava::Models::ClubEvent]
|
367
|
+
|
368
|
+
event = events.first # => Strava::Models::ClubEvent
|
369
|
+
|
370
|
+
event.title # => 'First Group Event Ever! Yippieh!'
|
371
|
+
```
|
372
|
+
|
373
|
+
See [Strava::Models::ClubEvent](lib/strava/models/club_event.rb) for all available properties.
|
374
|
+
|
356
375
|
#### List Club Administrators
|
357
376
|
|
358
377
|
Returns a list of the administrators of a given club.
|
@@ -413,15 +432,19 @@ See [Strava::Models::Club](lib/strava/models/club.rb) for all available properti
|
|
413
432
|
Returns an equipment using its identifier.
|
414
433
|
|
415
434
|
```ruby
|
416
|
-
gear = client.gear('
|
435
|
+
gear = client.gear(id: 'b2338517') # => Strava::Models::Gear
|
417
436
|
|
418
|
-
gear.id # => '
|
419
|
-
gear.name # => '
|
437
|
+
gear.id # => 'b2338517'
|
438
|
+
gear.name # => 'Trek'
|
420
439
|
gear.distance # => 380939.0
|
421
440
|
gear.distance_s # => '380.94km'
|
422
|
-
gear.brand_name # => '
|
423
|
-
gear.model_name # => '
|
424
|
-
gear.description # => '
|
441
|
+
gear.brand_name # => 'Trek'
|
442
|
+
gear.model_name # => 'Madone'
|
443
|
+
gear.description # => 'white'
|
444
|
+
gear.primary # => 'false'
|
445
|
+
gear.frame_type # => '3'
|
446
|
+
gear.weight # => '9'
|
447
|
+
gear.retired # => 'false'
|
425
448
|
```
|
426
449
|
|
427
450
|
See [Strava::Models::Gear](lib/strava/models/gear.rb) for all available properties.
|
@@ -843,9 +866,15 @@ authorization = client.deauthorize
|
|
843
866
|
authorization.access_token # => String, access token being revoked
|
844
867
|
```
|
845
868
|
|
869
|
+
#### Command Line OAuth Workflow
|
870
|
+
|
871
|
+
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.
|
872
|
+
|
873
|
+
See [strava-oauth-token](/bin/strava-oauth-token) or [strava-ruby-cli](https://github.com/dblock/strava-ruby-cli) for an example.
|
874
|
+
|
846
875
|
### Webhooks
|
847
876
|
|
848
|
-
Strava provides a [Webhook Event API](https://developers.strava.com/docs/webhooks/)
|
877
|
+
Strava provides a [Webhook Event API](https://developers.strava.com/docs/webhooks/).
|
849
878
|
|
850
879
|
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.
|
851
880
|
|
@@ -1016,11 +1045,11 @@ setting | description
|
|
1016
1045
|
--------------------|------------
|
1017
1046
|
client_id | Application client ID.
|
1018
1047
|
client_secret | Application client secret.
|
1019
|
-
endpoint | Defaults to `https://
|
1048
|
+
endpoint | Defaults to `https://www.strava.com/api/v3`.
|
1020
1049
|
|
1021
1050
|
## Errors
|
1022
1051
|
|
1023
|
-
All errors that return HTTP codes 400-600 result in either `Faraday::
|
1052
|
+
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.
|
1024
1053
|
|
1025
1054
|
```ruby
|
1026
1055
|
begin
|
@@ -1028,19 +1057,40 @@ begin
|
|
1028
1057
|
rescue Strava::Errors::Fault => e
|
1029
1058
|
e.message # => Bad Request
|
1030
1059
|
e.errors # => [{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }]
|
1060
|
+
e.headers # => { "status" => "403 Bad Request", "x-ratelimit-limit" => "600,30000", "x-ratelimit-usage" => "314,27536" }
|
1031
1061
|
end
|
1032
1062
|
```
|
1033
1063
|
|
1034
1064
|
## Tools
|
1035
1065
|
|
1066
|
+
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.
|
1067
|
+
|
1036
1068
|
### Strava OAuth Token
|
1037
1069
|
|
1038
|
-
Use [strava-oauth-token](bin/strava-
|
1070
|
+
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.
|
1039
1071
|
|
1040
1072
|
```bash
|
1041
1073
|
$ STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-token
|
1042
1074
|
```
|
1043
1075
|
|
1076
|
+
## Users
|
1077
|
+
|
1078
|
+
* [Slava: Strava integration with Slack](https://slava.playplay.io), [source](https://github.com/dblock/slack-strava).
|
1079
|
+
* [Jekyll Blog at run.dblock.org](https://run.dblock.org), [source](https://github.com/dblock/run.dblock.org)
|
1080
|
+
* [Secret Strava](https://steele.blue/secret-strava/), [source](https://github.com/mattdsteele/secret-strava)
|
1081
|
+
|
1082
|
+
## Resources
|
1083
|
+
|
1084
|
+
* [Strava API Documentation](https://developers.strava.com)
|
1085
|
+
* [Writing a New Strava API Ruby Client](https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html)
|
1086
|
+
* [Dealing with Strava API OAuth Token Migration](https://code.dblock.org/2018/11/17/dealing-with-strava-api-token-migration.html)
|
1087
|
+
* [Auto-Publishing Strava Runs to Github Pages](https://code.dblock.org/2018/02/17/auto-publishing-strava-runs-to-github-pages.html)
|
1088
|
+
* [Strava Command-Line Client](https://github.com/dblock/strava-ruby-cli)
|
1089
|
+
|
1090
|
+
## Upgrading
|
1091
|
+
|
1092
|
+
See [UPGRADING](UPGRADING.md).
|
1093
|
+
|
1044
1094
|
## Contributing
|
1045
1095
|
|
1046
1096
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
@@ -91,6 +91,9 @@ module Strava
|
|
91
91
|
# Number of items per page. Defaults to 30.
|
92
92
|
#
|
93
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]
|
94
97
|
paginate 'athlete/activities', options, Strava::Models::Activity, &block
|
95
98
|
end
|
96
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
|
#
|
data/lib/strava/errors/fault.rb
CHANGED
@@ -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,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
|
data/lib/strava/models/gear.rb
CHANGED
data/lib/strava/version.rb
CHANGED
@@ -8,26 +8,28 @@ module Strava
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def connection
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
@connection ||= begin
|
12
|
+
options = {
|
13
|
+
headers: headers.merge('Accept' => 'application/json; charset=utf-8')
|
14
|
+
}
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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::
|
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::
|
13
|
+
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
14
14
|
when ClientErrorStatuses
|
15
15
|
raise Strava::Errors::Fault, response_values(env)
|
16
16
|
end
|
data/lib/strava-ruby-client.rb
CHANGED
@@ -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'
|
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.
|
4
|
+
version: 0.4.2
|
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:
|
11
|
+
date: 2021-10-03 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:
|
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:
|
40
|
+
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday_middleware
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email: dblock@dblock.org
|
71
71
|
executables:
|
72
72
|
- strava-oauth-token
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/strava/models/authorization.rb
|
106
106
|
- lib/strava/models/club.rb
|
107
107
|
- lib/strava/models/club_admin.rb
|
108
|
+
- lib/strava/models/club_event.rb
|
108
109
|
- lib/strava/models/club_member.rb
|
109
110
|
- lib/strava/models/comment.rb
|
110
111
|
- lib/strava/models/explorer_segment.rb
|
@@ -154,7 +155,7 @@ homepage: http://github.com/dblock/strava-ruby-client
|
|
154
155
|
licenses:
|
155
156
|
- MIT
|
156
157
|
metadata: {}
|
157
|
-
post_install_message:
|
158
|
+
post_install_message:
|
158
159
|
rdoc_options: []
|
159
160
|
require_paths:
|
160
161
|
- lib
|
@@ -169,9 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: 1.3.6
|
171
172
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.1.3
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Strava API Ruby client.
|
177
177
|
test_files: []
|