Skip to content

Commit 01ea20c

Browse files
authored
closes #72 (#74)
next step towards v2.x 🎉
1 parent 22a3500 commit 01ea20c

File tree

5 files changed

+101
-3
lines changed

5 files changed

+101
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [#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).
44
* [#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).
55
* [#69](https://github.com/dblock/strava-ruby-client/pull/69): Raises `Strava::Api::RatelimitError`, when API ratelimit exceeded - [@simonneutert](https://github.com/simonneutert).
6+
* [#74](https://github.com/dblock/strava-ruby-client/pull/74): Fixes serialization causing `stack level too deep` - [@simonneutert](https://github.com/simonneutert).
67
* Your contribution here.
78

89
### 1.0.0 (2022/12/29)

lib/strava/models/mixins/http_response.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ module HttpResponse
77
extend ActiveSupport::Concern
88

99
included do
10-
property 'http_response', transform_with: ->(v) { Strava::Web::ApiResponse.new(v) }
10+
attr_reader :input
11+
12+
def initialize(obj)
13+
@input = obj
14+
super
15+
end
16+
17+
def http_response
18+
@http_response ||= Strava::Web::ApiResponse.new(input['http_response'])
19+
end
1120
end
1221
end
1322
end

lib/strava/models/upload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def validate!
2525
end
2626

2727
def raise_when_background_job_failed!
28-
response = self['http_response'].response
28+
response = http_response.response
2929
return unless response_contains_error_message?(response)
3030

3131
raise Strava::Errors::UploadError, response_values(response)

lib/strava/web/api_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ApiResponse
1010
#
1111
def initialize(http_response)
1212
@response = http_response
13-
@ratelimit = Strava::Api::Ratelimit.new(@response)
13+
@ratelimit = Strava::Api::Ratelimit.new(http_response)
1414
end
1515
end
1616
end

spec/strava/api/client/endpoints/activities/activity_spec.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,99 @@
278278

279279
expect(activity.available_zones).to eq %w[heartrate pace]
280280
end
281+
281282
it 'returns activity by id' do
282283
activity = client.activity(1_946_417_534)
283284
expect(activity).to be_a Strava::Models::Activity
284285
expect(activity.id).to eq 1_946_417_534
285286
end
287+
288+
context 'when serialized to JSON' do
289+
it 'is serialized without errors' do
290+
activity = client.activity(1_946_417_534)
291+
expect(activity.to_json).to be_present
292+
end
293+
294+
it 'contains all properties' do
295+
activity = client.activity(1_946_417_534)
296+
activity_json = JSON.parse(activity.to_json)
297+
expect(activity_json.keys).to match_array(
298+
%w[moving_time
299+
elapsed_time
300+
average_speed
301+
distance
302+
total_elevation_gain
303+
start_date_local
304+
id
305+
resource_state
306+
athlete
307+
name
308+
description
309+
sport_type
310+
workout_type
311+
external_id
312+
upload_id
313+
start_date
314+
timezone
315+
utc_offset
316+
start_latlng
317+
end_latlng
318+
location_city
319+
location_state
320+
location_country
321+
start_latitude
322+
start_longitude
323+
achievement_count
324+
kudos_count
325+
comment_count
326+
athlete_count
327+
photo_count
328+
map
329+
trainer
330+
commute
331+
manual
332+
private
333+
visibility
334+
flagged
335+
gear_id
336+
from_accepted_tag
337+
max_speed
338+
has_heartrate
339+
average_heartrate
340+
max_heartrate
341+
heartrate_opt_out
342+
display_hide_heartrate_option
343+
elev_high
344+
elev_low
345+
pr_count
346+
total_photo_count
347+
has_kudoed
348+
suffer_score
349+
calories
350+
segment_efforts
351+
best_efforts
352+
photos
353+
similar_activities
354+
embed_token
355+
available_zones
356+
splits_metric
357+
splits_standard
358+
laps
359+
gear
360+
device_name
361+
average_cadence
362+
average_temp
363+
average_watts
364+
weighted_average_watts
365+
kilojoules
366+
device_watts
367+
max_watts
368+
highlighted_kudosers
369+
segment_leaderboard_opt_out
370+
leaderboard_opt_out]
371+
)
372+
end
373+
end
286374
end
287375

288376
# uses the cassette: 'client/activity' but with status changed to 429 and ratelimit exceeded

0 commit comments

Comments
 (0)