strava-ruby-client 1.0.1 β 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -3
- data/README.md +37 -28
- data/bin/strava-oauth-token +1 -1
- data/bin/strava-webhooks +1 -1
- data/lib/strava/api/endpoints/activities.rb +1 -16
- data/lib/strava/api/ratelimit.rb +14 -0
- data/lib/strava/errors/ratelimit_error.rb +32 -0
- data/lib/strava/errors/upload_error.rb +33 -0
- data/lib/strava/models/activity.rb +2 -41
- data/lib/strava/models/upload.rb +34 -0
- data/lib/strava/version.rb +1 -1
- data/lib/strava/web/raise_response_error.rb +2 -0
- data/lib/strava-ruby-client.rb +4 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce678ec9f5b6b9bfca53c7c40f11557a4f779949ccf1bcc08b0aab2c5dff911
|
4
|
+
data.tar.gz: 656ed8118cd0983e7f259f509d756e80bcc8fe40da7396e2b8be443cd794191b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1674b1059b314e60baa3b404df1f37d9c968e340985b00385b4ee33a66730b55f55ca096263498e438101deaefe218e7146ab3ac83b1931c48c59619064375f7
|
7
|
+
data.tar.gz: 5292d8c10f1a41128dc746df559fb8d3ec2fc62920710acea8b402a8160b701441e36a51b3bfb81471ddf06489d4437016ab7ff30382fb8952cdd4d9518cabe5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
###
|
2
|
-
|
3
|
-
* [#
|
1
|
+
### 2.0.0 (2023/6/22)
|
2
|
+
|
3
|
+
* [#77](https://github.com/dblock/strava-ruby-client/pull/77): Drops unsupported endpoint/method `activity_photos` - [@simonneutert](https://github.com/simonneutert).
|
4
|
+
* [#62](https://github.com/dblock/strava-ruby-client/pull/68): Drops `Activity#type` attribute as it is being deprecated by Strava, dropping `Activity#type_emoji` with it - [@simonneutert](https://github.com/simonneutert).
|
5
|
+
* [#23](https://github.com/dblock/strava-ruby-client/pull/23): Failed uploads raise Strava::Errors::UploadError - [@ylecuyer](https://github.com/ylecuyer), [@simonneutert](https://github.com/simonneutert).
|
6
|
+
* [#69](https://github.com/dblock/strava-ruby-client/pull/69): Raises `Strava::Api::RatelimitError`, when API ratelimit exceeded - [@simonneutert](https://github.com/simonneutert).
|
7
|
+
* [#74](https://github.com/dblock/strava-ruby-client/pull/74): Fixes serialization causing `stack level too deep` - [@simonneutert](https://github.com/simonneutert).
|
8
|
+
* [#75](https://github.com/dblock/strava-ruby-client/pull/75): Fixes DangerBot deprecation warning for `check` of TOC - [@simonneutert](https://github.com/simonneutert).
|
4
9
|
|
5
10
|
### 1.0.0 (2022/12/29)
|
6
11
|
|
data/README.md
CHANGED
@@ -14,7 +14,6 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
14
14
|
- [Activities](#activities)
|
15
15
|
- [Create an Activity](#create-an-activity)
|
16
16
|
- [Get Activity](#get-activity)
|
17
|
-
- [List Activity Photos](#list-activity-photos)
|
18
17
|
- [List Activity Comments](#list-activity-comments)
|
19
18
|
- [List Activity Kudoers](#list-activity-kudoers)
|
20
19
|
- [List Activity Laps](#list-activity-laps)
|
@@ -64,6 +63,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
|
|
64
63
|
- [Command Line OAuth Workflow](#command-line-oauth-workflow)
|
65
64
|
- [Webhooks](#webhooks)
|
66
65
|
- [Ratelimit](#ratelimit)
|
66
|
+
- [Exceeded Ratelimit](#exceeded-ratelimit)
|
67
67
|
- [Configuration](#configuration)
|
68
68
|
- [Web Client Options](#web-client-options)
|
69
69
|
- [API Client Options](#api-client-options)
|
@@ -149,29 +149,6 @@ google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadm
|
|
149
149
|
|
150
150
|
See [Strava::Models::Map](lib/strava/models/map.rb) for all available properties.
|
151
151
|
|
152
|
-
#### List Activity Photos
|
153
|
-
|
154
|
-
Returns the photos on the given activity. This API is undocumented.
|
155
|
-
|
156
|
-
```ruby
|
157
|
-
photos = client.activity_photos(1982980795) # => Array[Strava::Models::Photo]
|
158
|
-
|
159
|
-
photo = photos.first # => Strava::Models::Photo
|
160
|
-
|
161
|
-
photo.id # => nil
|
162
|
-
photo.unique_id # => '65889142-538D-4EE5-96F5-3DC3B773B1E3'
|
163
|
-
photo.urls # => { '0' => 'https://dgtzuqphqg23d.cloudfront.net/eb4DMJ2hJW3k_g9URZEMfaJ8rZfHagrNlZRuEZz0osU-29x64.jpg' }
|
164
|
-
photo.athlete_id # => 26_462_176
|
165
|
-
photo.activity_id # => 1_946_417_534
|
166
|
-
photo.activity_name # => 'TCS NYC Marathon 2018'
|
167
|
-
photo.created_at # => Time
|
168
|
-
photo.uploaded_at # => Time
|
169
|
-
photo.sizes # => { '0' => [29, 64] }
|
170
|
-
photo.default_photo # => false
|
171
|
-
```
|
172
|
-
|
173
|
-
See [Strava::Models::Photo](lib/strava/models/photo.rb) for all available properties.
|
174
|
-
|
175
152
|
#### List Activity Comments
|
176
153
|
|
177
154
|
Returns the comments on the given activity.
|
@@ -226,7 +203,6 @@ activity = activities.first # => Strava::Models::Activity
|
|
226
203
|
|
227
204
|
activity.name # => 'NYC TCS Marathon 2018'
|
228
205
|
activity.strava_url # => 'https://www.strava.com/activities/1477353766'
|
229
|
-
activity.type_emoji # => 'π'
|
230
206
|
activity.sport_type_emoji # => 'π'
|
231
207
|
activity.distance_s # => '42.2km'
|
232
208
|
activity.moving_time_in_hours_s # => '3h38m5s'
|
@@ -711,7 +687,7 @@ See [Strava::Models::StreamSet](lib/strava/models/stream_set.rb) and [Strava::Mo
|
|
711
687
|
|
712
688
|
#### Upload Activity
|
713
689
|
|
714
|
-
Uploads a new data file to create an activity from.
|
690
|
+
Uploads a new data file to create an activity from. To check the processing status of the uploaded file, see [Get Upload](#get-upload).
|
715
691
|
|
716
692
|
```ruby
|
717
693
|
upload = client.create_upload(
|
@@ -733,9 +709,10 @@ See [Strava::Models::Upload](lib/strava/models/upload.rb) for all available prop
|
|
733
709
|
|
734
710
|
#### Get Upload
|
735
711
|
|
736
|
-
Returns an upload for a given identifier.
|
712
|
+
Returns an upload for a given identifier. Raises `Strava::Errors::UploadError` if the upload was faulty and did not result in a created activity. `Strava::Errors::UploadError#upload` contains `Strava::Models::Upload` for further inspection.
|
737
713
|
|
738
714
|
```ruby
|
715
|
+
# happy path
|
739
716
|
upload = client.upload(2136460097) # => Strava::Models::Upload
|
740
717
|
|
741
718
|
upload.id # => 2_136_460_097
|
@@ -745,7 +722,29 @@ upload.status # => 'Your activity is ready.'
|
|
745
722
|
upload.activity_id # => 1_998_557_443
|
746
723
|
```
|
747
724
|
|
748
|
-
|
725
|
+
```ruby
|
726
|
+
# with error after upload
|
727
|
+
upload = client.upload(2136460097)
|
728
|
+
begin
|
729
|
+
while upload.processing?
|
730
|
+
sleep 1
|
731
|
+
upload = client.upload(2136460097)
|
732
|
+
end
|
733
|
+
rescue Strava::Errors::UploadError => upload_error
|
734
|
+
upload_error.status # => 200
|
735
|
+
upload_error.error_status # => 'There was an error processing your activity.'
|
736
|
+
upload_error.message # => '17611540601.tcx duplicate of activity 8309312818'
|
737
|
+
|
738
|
+
upload_error.upload.external_id # => nil
|
739
|
+
upload_error.upload.activity_id # => nil
|
740
|
+
upload_error.upload.status # => 'There was an error processing your activity.'
|
741
|
+
upload_error.upload.error # => '17611540601.tcx duplicate of activity 8309312818'
|
742
|
+
upload_error.upload.class # => Strava::Models::UploadFailed
|
743
|
+
end
|
744
|
+
```
|
745
|
+
|
746
|
+
See [Strava::Models::Upload](lib/strava/models/upload.rb) for all available properties.
|
747
|
+
See [Strava::Errors::UploadError](lib/strava/errors/upload_failed_error.rb) for all available properties.
|
749
748
|
|
750
749
|
### Pagination
|
751
750
|
|
@@ -947,6 +946,16 @@ You can access the Hash containing all limits by calling `to_h`.
|
|
947
946
|
}
|
948
947
|
```
|
949
948
|
|
949
|
+
#### Exceeded Ratelimit
|
950
|
+
|
951
|
+
Strava answers with HTTP status code 429, when ratelimits are exceeded. This will in return raise `Strava::Errors::RatelimitError`.
|
952
|
+
|
953
|
+
```ruby
|
954
|
+
error.is_a?(Strava::Errors::RatelimitError) #=> true
|
955
|
+
error.ratelimit.is_a?(Strava::Api::Ratelimit) #=> true
|
956
|
+
# see Strava::Api::Ratelimit
|
957
|
+
```
|
958
|
+
|
950
959
|
## Configuration
|
951
960
|
|
952
961
|
### Web Client Options
|
data/bin/strava-oauth-token
CHANGED
data/bin/strava-webhooks
CHANGED
@@ -37,21 +37,6 @@ module Strava
|
|
37
37
|
paginate "activities/#{id}/comments", options, Strava::Models::Comment, &block
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
# List activity photos.
|
42
|
-
#
|
43
|
-
# @option options [String] :id
|
44
|
-
# Activity id.
|
45
|
-
# @option options [Integer] :page
|
46
|
-
# Page number.
|
47
|
-
# @option options [Integer] :per_page
|
48
|
-
# Number of items per page. Defaults to 30.
|
49
|
-
#
|
50
|
-
def activity_photos(id_or_options, options = {}, &block)
|
51
|
-
id, options = parse_args(id_or_options, options)
|
52
|
-
paginate "activities/#{id}/photos", options, Strava::Models::Photo, &block
|
53
|
-
end
|
54
|
-
|
55
40
|
#
|
56
41
|
# List activity kudoers.
|
57
42
|
#
|
@@ -125,7 +110,7 @@ module Strava
|
|
125
110
|
# The description of the activity.
|
126
111
|
# @option options [String] :name
|
127
112
|
# The name of the activity.
|
128
|
-
# @option options [String] :
|
113
|
+
# @option options [String] :sport_type
|
129
114
|
# Activity type.
|
130
115
|
# @option options [String] :gear_id
|
131
116
|
# Identifier for the gear associated with the activity. Specifying "none" clears gear from activity.
|
data/lib/strava/api/ratelimit.rb
CHANGED
@@ -9,6 +9,20 @@ module Strava
|
|
9
9
|
@body = response.body
|
10
10
|
end
|
11
11
|
|
12
|
+
def exceeded
|
13
|
+
return false unless limit?
|
14
|
+
|
15
|
+
@exceeded ||= if fifteen_minutes_remaining && fifteen_minutes_remaining <= 0
|
16
|
+
{ fifteen_minutes_remaining: fifteen_minutes_remaining }
|
17
|
+
elsif total_day_remaining && total_day_remaining <= 0
|
18
|
+
{ total_day_remaining: total_day_remaining }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def exceeded?
|
23
|
+
!!exceeded
|
24
|
+
end
|
25
|
+
|
12
26
|
def to_s
|
13
27
|
to_h.map do |k, v|
|
14
28
|
"#{k}: #{v}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Strava
|
4
|
+
module Errors
|
5
|
+
class RatelimitError < ::Faraday::ClientError
|
6
|
+
attr_reader :http_response, :ratelimit, :error_message
|
7
|
+
|
8
|
+
def initialize(http_response, error_message = nil)
|
9
|
+
@response = http_response.response
|
10
|
+
@ratelimit = Strava::Api::Ratelimit.new(@response)
|
11
|
+
@error_message = error_message || message
|
12
|
+
super({
|
13
|
+
status: http_response.status,
|
14
|
+
headers: http_response.response_headers,
|
15
|
+
body: http_response.body
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
response[:body]['message'] || super
|
21
|
+
end
|
22
|
+
|
23
|
+
def headers
|
24
|
+
response[:headers]
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
response[:body]['errors']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Strava
|
4
|
+
module Errors
|
5
|
+
class UploadError < ::Faraday::ClientError
|
6
|
+
def status
|
7
|
+
response[:status]
|
8
|
+
end
|
9
|
+
|
10
|
+
def headers
|
11
|
+
response[:headers]
|
12
|
+
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
body[:error] || super
|
16
|
+
end
|
17
|
+
|
18
|
+
def error_status
|
19
|
+
body[:status]
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload
|
23
|
+
@upload ||= Strava::Models::Upload.new(body)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def body
|
29
|
+
(response[:body] || {}).with_indifferent_access
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -13,7 +13,6 @@ module Strava
|
|
13
13
|
property 'athlete', transform_with: ->(v) { Strava::Models::Athlete.new(v) }
|
14
14
|
property 'name'
|
15
15
|
property 'description'
|
16
|
-
property 'type' # deprecated
|
17
16
|
property 'sport_type'
|
18
17
|
property 'workout_type'
|
19
18
|
property 'id'
|
@@ -80,7 +79,7 @@ module Strava
|
|
80
79
|
property 'leaderboard_opt_out'
|
81
80
|
|
82
81
|
def distance_s
|
83
|
-
if
|
82
|
+
if sport_type == 'Swim'
|
84
83
|
distance_in_meters_s
|
85
84
|
else
|
86
85
|
distance_in_kilometers_s
|
@@ -88,7 +87,7 @@ module Strava
|
|
88
87
|
end
|
89
88
|
|
90
89
|
def pace_s
|
91
|
-
case
|
90
|
+
case sport_type
|
92
91
|
when 'Swim'
|
93
92
|
pace_per_100_meters_s
|
94
93
|
else
|
@@ -139,44 +138,6 @@ module Strava
|
|
139
138
|
when 'Yoga' then 'π§'
|
140
139
|
end
|
141
140
|
end
|
142
|
-
|
143
|
-
#
|
144
|
-
# @deprecated Use {#sport_type_emoji} instead.
|
145
|
-
#
|
146
|
-
# @return [String] precisely an emoji
|
147
|
-
#
|
148
|
-
def type_emoji
|
149
|
-
case type
|
150
|
-
when 'Run', 'VirtualRun' then 'π'
|
151
|
-
when 'Ride', 'EBikeRide', 'VirtualRide' then 'π΄'
|
152
|
-
when 'Swim' then 'π'
|
153
|
-
when 'Walk' then 'πΆ'
|
154
|
-
when 'AlpineSki' then 'β·οΈ'
|
155
|
-
when 'BackcountrySki' then 'πΏοΈ'
|
156
|
-
# when 'Canoeing' then ''
|
157
|
-
# when 'Crossfit' then ''
|
158
|
-
# when 'Elliptical' then ''
|
159
|
-
# when 'Hike' then ''
|
160
|
-
when 'IceSkate' then 'βΈοΈ'
|
161
|
-
# when 'InlineSkate' then ''
|
162
|
-
# when 'Kayaking' then ''
|
163
|
-
# when 'Kitesurf' then ''
|
164
|
-
# when 'NordicSki' then ''
|
165
|
-
when 'RockClimbing' then 'π§'
|
166
|
-
when 'RollerSki' then ''
|
167
|
-
when 'Rowing' then 'π£'
|
168
|
-
when 'Snowboard' then 'π'
|
169
|
-
# when 'Snowshoe' then ''
|
170
|
-
# when 'StairStepper' then ''
|
171
|
-
# when 'StandUpPaddling' then ''
|
172
|
-
when 'Surfing' then 'π'
|
173
|
-
when 'WeightTraining' then 'ποΈ'
|
174
|
-
# when 'Windsurf' then ''
|
175
|
-
when 'Wheelchair' then 'βΏ'
|
176
|
-
# when 'Workout' then ''
|
177
|
-
# when 'Yoga'' then ''
|
178
|
-
end
|
179
|
-
end
|
180
141
|
end
|
181
142
|
end
|
182
143
|
end
|
data/lib/strava/models/upload.rb
CHANGED
@@ -8,6 +8,40 @@ module Strava
|
|
8
8
|
property 'error'
|
9
9
|
property 'status'
|
10
10
|
property 'activity_id'
|
11
|
+
|
12
|
+
def processing?
|
13
|
+
validate!
|
14
|
+
activity_id.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def processed?
|
18
|
+
!processing?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate!
|
24
|
+
raise_when_background_job_failed!
|
25
|
+
end
|
26
|
+
|
27
|
+
def raise_when_background_job_failed!
|
28
|
+
response = http_response.response
|
29
|
+
return unless response_contains_error_message?(response)
|
30
|
+
|
31
|
+
raise Strava::Errors::UploadError, response_values(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def response_contains_error_message?(response)
|
35
|
+
response.status == 200 && response.body['error'].present?
|
36
|
+
end
|
37
|
+
|
38
|
+
def response_values(response)
|
39
|
+
{
|
40
|
+
status: response.status,
|
41
|
+
headers: response.headers,
|
42
|
+
body: response.body
|
43
|
+
}
|
44
|
+
end
|
11
45
|
end
|
12
46
|
end
|
13
47
|
end
|
data/lib/strava/version.rb
CHANGED
@@ -12,6 +12,8 @@ module Strava
|
|
12
12
|
when 407
|
13
13
|
# mimic the behavior that we get with proxy requests with HTTPS
|
14
14
|
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
15
|
+
when 429
|
16
|
+
raise Strava::Errors::RatelimitError.new(env, 'Too Many Requests')
|
15
17
|
when CLIENT_ERROR_STATUSES
|
16
18
|
raise Strava::Errors::Fault, response_values(env)
|
17
19
|
end
|
data/lib/strava-ruby-client.rb
CHANGED
@@ -17,11 +17,13 @@ require_relative 'strava/logger'
|
|
17
17
|
require_relative 'strava/deep_copyable'
|
18
18
|
|
19
19
|
require_relative 'strava/errors/fault'
|
20
|
+
require_relative 'strava/errors/upload_error'
|
21
|
+
require_relative 'strava/errors/ratelimit_error'
|
20
22
|
|
21
|
-
require_relative 'strava/models/mixins/
|
23
|
+
require_relative 'strava/models/mixins/time'
|
22
24
|
require_relative 'strava/models/mixins/distance'
|
23
25
|
require_relative 'strava/models/mixins/elevation'
|
24
|
-
require_relative 'strava/models/mixins/
|
26
|
+
require_relative 'strava/models/mixins/http_response'
|
25
27
|
require_relative 'strava/models/mixins/start_date_local'
|
26
28
|
|
27
29
|
require_relative 'strava/models/model'
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -98,6 +98,8 @@ files:
|
|
98
98
|
- lib/strava/api/ratelimit.rb
|
99
99
|
- lib/strava/deep_copyable.rb
|
100
100
|
- lib/strava/errors/fault.rb
|
101
|
+
- lib/strava/errors/ratelimit_error.rb
|
102
|
+
- lib/strava/errors/upload_error.rb
|
101
103
|
- lib/strava/logger.rb
|
102
104
|
- lib/strava/models/achievement.rb
|
103
105
|
- lib/strava/models/activity.rb
|
@@ -177,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
179
|
- !ruby/object:Gem::Version
|
178
180
|
version: 1.3.6
|
179
181
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
182
|
+
rubygems_version: 3.4.12
|
181
183
|
signing_key:
|
182
184
|
specification_version: 4
|
183
185
|
summary: Strava API Ruby client.
|