strava-ruby-client 1.1.0 β†’ 2.0.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
  SHA256:
3
- metadata.gz: 2583980553406730410bd2207010190c47b7a36d4fea785390138eb3a27da767
4
- data.tar.gz: 544a48791a8fcb1b6bb7b8b80c6b745720013bec3e8d15788c0fff5a42366d96
3
+ metadata.gz: dce678ec9f5b6b9bfca53c7c40f11557a4f779949ccf1bcc08b0aab2c5dff911
4
+ data.tar.gz: 656ed8118cd0983e7f259f509d756e80bcc8fe40da7396e2b8be443cd794191b
5
5
  SHA512:
6
- metadata.gz: 98c300765eb5c6dc38734ed419db35b7816008397dc3d61b7d3d301675a417e4ea06b71907f11ec8196172c312f54c0961fdfbd99e4ceae35a75cdcd71a872e3
7
- data.tar.gz: 32c57b79aa21e42d081f9b88184e65043dce242602efec84b115460f71ab22d3b6e764405f7f9eeb5c81305e08478fa4486c276bc00654a6164d2c5715362315
6
+ metadata.gz: 1674b1059b314e60baa3b404df1f37d9c968e340985b00385b4ee33a66730b55f55ca096263498e438101deaefe218e7146ab3ac83b1931c48c59619064375f7
7
+ data.tar.gz: 5292d8c10f1a41128dc746df559fb8d3ec2fc62920710acea8b402a8160b701441e36a51b3bfb81471ddf06489d4437016ab7ff30382fb8952cdd4d9518cabe5
data/CHANGELOG.md CHANGED
@@ -1,10 +1,11 @@
1
- ### 1.1.0 (2023/06/09)
2
-
3
- * [#78](https://github.com/dblock/strava-ruby-client/pull/78): Drops unsupported endpoint/method `activity_photos` - [@simonneutert](https://github.com/simonneutert).
4
-
5
- ### 1.0.1 (2023/02/11)
6
-
7
- * [#73](https://github.com/dblock/strava-ruby-client/pull/73): Fixes serialization causing `stack level too deep` - [@simonneutert](https://github.com/simonneutert).
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).
8
9
 
9
10
  ### 1.0.0 (2022/12/29)
10
11
 
data/README.md CHANGED
@@ -63,6 +63,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
63
63
  - [Command Line OAuth Workflow](#command-line-oauth-workflow)
64
64
  - [Webhooks](#webhooks)
65
65
  - [Ratelimit](#ratelimit)
66
+ - [Exceeded Ratelimit](#exceeded-ratelimit)
66
67
  - [Configuration](#configuration)
67
68
  - [Web Client Options](#web-client-options)
68
69
  - [API Client Options](#api-client-options)
@@ -202,7 +203,6 @@ activity = activities.first # => Strava::Models::Activity
202
203
 
203
204
  activity.name # => 'NYC TCS Marathon 2018'
204
205
  activity.strava_url # => 'https://www.strava.com/activities/1477353766'
205
- activity.type_emoji # => 'πŸƒ'
206
206
  activity.sport_type_emoji # => 'πŸƒ'
207
207
  activity.distance_s # => '42.2km'
208
208
  activity.moving_time_in_hours_s # => '3h38m5s'
@@ -687,7 +687,7 @@ See [Strava::Models::StreamSet](lib/strava/models/stream_set.rb) and [Strava::Mo
687
687
 
688
688
  #### Upload Activity
689
689
 
690
- 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).
691
691
 
692
692
  ```ruby
693
693
  upload = client.create_upload(
@@ -709,9 +709,10 @@ See [Strava::Models::Upload](lib/strava/models/upload.rb) for all available prop
709
709
 
710
710
  #### Get Upload
711
711
 
712
- 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.
713
713
 
714
714
  ```ruby
715
+ # happy path
715
716
  upload = client.upload(2136460097) # => Strava::Models::Upload
716
717
 
717
718
  upload.id # => 2_136_460_097
@@ -721,7 +722,29 @@ upload.status # => 'Your activity is ready.'
721
722
  upload.activity_id # => 1_998_557_443
722
723
  ```
723
724
 
724
- See [Strava::Models::Upload](lib/strava/models/upload.rb) for all available properties.
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.
725
748
 
726
749
  ### Pagination
727
750
 
@@ -923,6 +946,16 @@ You can access the Hash containing all limits by calling `to_h`.
923
946
  }
924
947
  ```
925
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
+
926
959
  ## Configuration
927
960
 
928
961
  ### Web Client Options
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'dotenv/load'
5
- require 'strava-ruby-client'
6
5
  require 'webrick'
6
+ require 'strava-ruby-client'
7
7
 
8
8
  server = WEBrick::HTTPServer.new(Port: 4242)
9
9
 
data/bin/strava-webhooks CHANGED
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'dotenv/load'
5
- require 'strava-ruby-client'
6
5
  require 'webrick'
6
+ require 'strava-ruby-client'
7
7
 
8
8
  logger = ::Logger.new($stdout)
9
9
  logger.level = Logger::INFO
@@ -110,7 +110,7 @@ module Strava
110
110
  # The description of the activity.
111
111
  # @option options [String] :name
112
112
  # The name of the activity.
113
- # @option options [String] :type
113
+ # @option options [String] :sport_type
114
114
  # Activity type.
115
115
  # @option options [String] :gear_id
116
116
  # Identifier for the gear associated with the activity. Specifying "none" clears gear from activity.
@@ -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 type == 'Swim'
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 type
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strava
4
- VERSION = '1.1.0'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -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
@@ -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/http_response'
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/time'
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: 1.1.0
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-06-09 00:00:00.000000000 Z
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