strava-ruby-client 0.4.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/README.md +90 -88
  4. data/bin/strava-oauth-token +2 -2
  5. data/bin/strava-webhooks +2 -2
  6. data/lib/strava/api/client.rb +21 -2
  7. data/lib/strava/api/endpoints/routes.rb +2 -2
  8. data/lib/strava/api/endpoints/running_races.rb +0 -12
  9. data/lib/strava/api/endpoints/segments.rb +0 -46
  10. data/lib/strava/api/pagination.rb +60 -0
  11. data/lib/strava/api/ratelimit.rb +159 -0
  12. data/lib/strava/deep_copyable.rb +16 -0
  13. data/lib/strava/models/achievement.rb +1 -1
  14. data/lib/strava/models/activity.rb +48 -2
  15. data/lib/strava/models/activity_stats.rb +1 -1
  16. data/lib/strava/models/activity_total.rb +1 -1
  17. data/lib/strava/models/activity_zone.rb +1 -1
  18. data/lib/strava/models/athlete.rb +1 -2
  19. data/lib/strava/models/authorization.rb +1 -1
  20. data/lib/strava/models/club.rb +1 -1
  21. data/lib/strava/models/club_admin.rb +1 -1
  22. data/lib/strava/models/club_event.rb +1 -1
  23. data/lib/strava/models/club_member.rb +1 -1
  24. data/lib/strava/models/comment.rb +1 -1
  25. data/lib/strava/models/explorer_segment.rb +1 -1
  26. data/lib/strava/models/gear.rb +1 -1
  27. data/lib/strava/models/heart_rate_zone_ranges.rb +1 -1
  28. data/lib/strava/models/kudoser.rb +1 -1
  29. data/lib/strava/models/lap.rb +1 -1
  30. data/lib/strava/models/map.rb +1 -1
  31. data/lib/strava/models/mixins/http_response.rb +15 -0
  32. data/lib/strava/models/photo.rb +1 -1
  33. data/lib/strava/models/photos.rb +1 -1
  34. data/lib/strava/models/power_zone_ranges.rb +1 -1
  35. data/lib/strava/models/response.rb +9 -0
  36. data/lib/strava/models/route.rb +1 -1
  37. data/lib/strava/models/running_race.rb +1 -1
  38. data/lib/strava/models/segment.rb +1 -1
  39. data/lib/strava/models/segment_effort.rb +1 -1
  40. data/lib/strava/models/segment_stats.rb +1 -1
  41. data/lib/strava/models/similar_activities.rb +1 -1
  42. data/lib/strava/models/split.rb +1 -1
  43. data/lib/strava/models/stream.rb +1 -1
  44. data/lib/strava/models/stream_set.rb +1 -1
  45. data/lib/strava/models/timed_zone_range.rb +1 -1
  46. data/lib/strava/models/token.rb +1 -1
  47. data/lib/strava/models/trend.rb +1 -1
  48. data/lib/strava/models/upload.rb +1 -1
  49. data/lib/strava/models/zone_range.rb +1 -1
  50. data/lib/strava/models/zones.rb +1 -1
  51. data/lib/strava/version.rb +1 -1
  52. data/lib/strava/web/api_response.rb +17 -0
  53. data/lib/strava/web/client.rb +2 -2
  54. data/lib/strava/web/connection.rb +4 -4
  55. data/lib/strava/web/raise_response_error.rb +29 -0
  56. data/lib/strava/web/request.rb +3 -2
  57. data/lib/strava/web/response.rb +92 -0
  58. data/lib/strava/webhooks/models/subscription.rb +1 -1
  59. data/lib/strava-ruby-client.rb +9 -4
  60. metadata +17 -12
  61. data/lib/strava/models/segment_leaderboard.rb +0 -12
  62. data/lib/strava/models/segment_leaderboard_entry.rb +0 -14
  63. data/lib/strava/web/raise_error.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1fd53d322d249bebc5d46c0edaaf9fd6d8831ba2c23134c0450203e078965d6
4
- data.tar.gz: fa26523a8f6d1987700b414131bd0a754154f734cdf7f21be6988de2fd1a1271
3
+ metadata.gz: b80a0bbc9fed0fa22baa2beaa23d59492d26766295539f05eaf7e38c6b6abed3
4
+ data.tar.gz: f118e373ce17c7add5a1919b7e1b0936836e268a2bcc0c3349a548dccbf16fa7
5
5
  SHA512:
6
- metadata.gz: 65e071fafa80e86f019290774a902a53837bc9a6f4aa15f50306bdf0807fdd929a509638832109cfe2e4380dfa921a4e205623252b4651ab780d6109dfd1f3a7
7
- data.tar.gz: d0cada36caa3cd5beac43605a3efc55ea79f4603184fdfa1df614418a6b9a59e6b8cff7365b0e6f9bc59ddf036d288480d18d81e5165f35f69b2c912502759b7
6
+ metadata.gz: 3f6a9ed96fd697e3906afaea168495e2313dce12d9cb125e3ec63e72d007fbba42f424578482982606bcc0e94ae722fd4c22dd7a669ae0566838a8c08374ed3c
7
+ data.tar.gz: 8a7c832f863941ea132c0f3ef9d327b439038ac12334ebc87ac221ddf6a392371536eb59413cb6dfcac31ed1ecb6554085079d5c284059d0a51a5b74b3a3fd8c
data/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
+ ### 1.0.0 (2022/12/29)
2
+
3
+ * [#48](https://github.com/dblock/strava-ruby-client/pull/55): Removed `client.running_races` - [@simonneutert](https://github.com/simonneutert).
4
+ * [#56](https://github.com/dblock/strava-ruby-client/pull/56): Removed `client.segment_leaderboard` - [@simonneutert](https://github.com/simonneutert).
5
+ * [#58](https://github.com/dblock/strava-ruby-client/pull/58): Update Faraday to `>= 2.0` - [@schinery](https://github.com/schinery).
6
+ * [#58](https://github.com/dblock/strava-ruby-client/pull/58): Removed support for Ruby 2.5 and 2.6 - [@schinery](https://github.com/schinery).
7
+ * [#58](https://github.com/dblock/strava-ruby-client/pull/58): Upgraded Robocop to 1.3.0 - [@schinery](https://github.com/schinery).
8
+ * [#59](https://github.com/dblock/strava-ruby-client/pull/59): Removed deprecated `athlete.email` field - [@francordie](https://github.com/francordie).
9
+ * [#63](https://github.com/dblock/strava-ruby-client/pull/63): Added `activity.sport_type` for Strava API V3 specifications - [@simonneutert](https://github.com/simonneutert).
10
+ * [#61](https://github.com/dblock/strava-ruby-client/pull/61): Adds ratelimit as a property of model(s) - [@simonneutert](https://github.com/simonneutert), [@adamwolf](https://github.com/adamwolf).
11
+
1
12
  ### 0.4.3 (2022/03/21)
2
13
 
3
14
  * [#51](https://github.com/dblock/strava-ruby-client/pull/51): Ensure support for large Integer IDs - [@simonneutert](https://github.com/simonneutert).
4
15
  * [#53](https://github.com/dblock/strava-ruby-client/pull/53): Upgraded to RuboCop 1.26.0 - [@dblock](https://github.com/dblock).
5
- * [#46](https://github.com/dblock/strava-ruby-client/pull/46): Add missing `activity:read` scope from `strava-oauth-token` - [@xaviershay](https://github.com/xaviershay).
16
+ * [#46](https://github.com/dblock/strava-ruby-client/pull/46): Added missing `activity:read` scope from `strava-oauth-token` - [@xaviershay](https://github.com/xaviershay).
6
17
 
7
18
  ### 0.4.2 (2021/10/03)
8
19
 
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Strava Ruby Client
2
- ==================
1
+ # Strava Ruby Client
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/strava-ruby-client.svg)](https://badge.fury.io/rb/strava-ruby-client)
5
4
  [![Test](https://github.com/dblock/strava-ruby-client/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/dblock/strava-ruby-client/actions/workflows/test.yml)
@@ -43,13 +42,11 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
43
42
  - [List Athlete Routes](#list-athlete-routes)
44
43
  - [Running Races](#running-races)
45
44
  - [Get Running Race](#get-running-race)
46
- - [List Running Races](#list-running-races)
47
45
  - [Segment Efforts](#segment-efforts)
48
46
  - [List Segment Efforts](#list-segment-efforts)
49
47
  - [Get Segment Effort](#get-segment-effort)
50
48
  - [Segments](#segments)
51
49
  - [Explore Segments](#explore-segments)
52
- - [Get Segment Leaderboard](#get-segment-leaderboard)
53
50
  - [List Starred Segments](#list-starred-segments)
54
51
  - [Get Segment](#get-segment)
55
52
  - [Star Segment](#star-segment)
@@ -66,6 +63,7 @@ Unlike other clients, including [strava-api-v3](https://github.com/jaredholdcrof
66
63
  - [Deauthorize](#deauthorize)
67
64
  - [Command Line OAuth Workflow](#command-line-oauth-workflow)
68
65
  - [Webhooks](#webhooks)
66
+ - [Ratelimit](#ratelimit)
69
67
  - [Configuration](#configuration)
70
68
  - [Web Client Options](#web-client-options)
71
69
  - [API Client Options](#api-client-options)
@@ -109,7 +107,7 @@ Creates a manual activity for an athlete.
109
107
  ```ruby
110
108
  activity = client.create_activity(
111
109
  name: 'Afternoon Run',
112
- type: 'Run',
110
+ sport_type: 'Run',
113
111
  start_date_local: Time.now,
114
112
  elapsed_time: 1234, # in seconds
115
113
  description: 'Test run.',
@@ -217,7 +215,6 @@ lap.name # => 'Lap 1'
217
215
 
218
216
  See [Strava::Models::Lap](lib/strava/models/lap.rb) for all available properties.
219
217
 
220
-
221
218
  #### List Athlete Activities
222
219
 
223
220
  Returns the currently logged-in athlete's activities.
@@ -230,6 +227,7 @@ activity = activities.first # => Strava::Models::Activity
230
227
  activity.name # => 'NYC TCS Marathon 2018'
231
228
  activity.strava_url # => 'https://www.strava.com/activities/1477353766'
232
229
  activity.type_emoji # => '🏃'
230
+ activity.sport_type_emoji # => '🏃'
233
231
  activity.distance_s # => '42.2km'
234
232
  activity.moving_time_in_hours_s # => '3h38m5s'
235
233
  activity.elapsed_time_in_hours_s # => '3h42m13s'
@@ -272,7 +270,7 @@ Update an activity.
272
270
  activity = client.update_activity(
273
271
  id: 1982980795,
274
272
  name: 'Afternoon Run (Updated)',
275
- type: 'Run',
273
+ sport_type: 'Run',
276
274
  description: 'It was cold.'
277
275
  )
278
276
 
@@ -530,23 +528,6 @@ running_race.website_url # => 'https://www.rundisney.com/disneyworld-marathon/'
530
528
 
531
529
  See [Strava::Models::RunningRace](lib/strava/models/running_race.rb) for all available properties.
532
530
 
533
- #### List Running Races
534
-
535
- Returns a list running races based on a set of search criteria.
536
-
537
- ```ruby
538
- running_races = client.running_races
539
-
540
- running_race = running_races.first # => Strava::Models::RunningRace
541
-
542
- running_race.name # => 'Walt Disney World Half Marathon'
543
- running_race.distance # => 21_097.0
544
- running_race.measurement_preference # => 'feet'
545
- running_race.distance_s # => '13.11mi'
546
- ```
547
-
548
- See [Strava::Models::RunningRace](lib/strava/models/running_race.rb) for all available properties.
549
-
550
531
  ### Segment Efforts
551
532
 
552
533
  #### List Segment Efforts
@@ -616,37 +597,6 @@ segment.elev_difference # => 9.6
616
597
 
617
598
  See [Strava::Models::ExplorerSegment](lib/strava/models/explorer_segment.rb) for all available properties.
618
599
 
619
- #### Get Segment Leaderboard
620
-
621
- Returns the specified segment leaderboard.
622
-
623
- ```ruby
624
- segment_leaderboard = client.segment_leaderboard(1109718) # => Strava::Models::SegmentLeaderboard
625
-
626
- segment_leaderboard.effort_count # => 204
627
- segment_leaderboard.entry_count # => 204
628
- segment_leaderboard.kom_type # => 'kom'
629
- segment_leaderboard.entries # => Enumerable
630
-
631
- entry = segment_leaderboard.entries.first # => Strava::Models::SegmentLeaderboardEntry
632
- entry.athlete_name # => 'Etan B.'
633
- entry.moving_time_in_hours_s # => '1m32s'
634
- entry.start_date # => Time
635
- entry.start_date_local # => Time
636
- entry.rank # => 1
637
- ```
638
-
639
- This API supports pagination through the entire segment leaderboard but wraps entries into a [Strava::Models::SegmentLeaderboard](lib/strava/models/segment_leaderboard.rb) object.
640
-
641
- ```ruby
642
- client.segment_leaderboard(1109718) do |row|
643
- row # => Strava::Models::SegmentLeaderboard
644
- row.entries # => Array[Strava::Models::SegmentLeaderboardEntry]
645
- end
646
- ```
647
-
648
- See [Strava::Models::SegmentLeaderboard](lib/strava/models/segment_leaderboard.rb) and [Strava::Models::SegmentLeaderboardEntry](lib/strava/models/segment_leaderboard_entry.rb) for all available properties.
649
-
650
600
  #### List Starred Segments
651
601
 
652
602
  List of the authenticated athlete's starred segments.
@@ -898,7 +848,7 @@ event # => Strava::Webhooks::Models::Event
898
848
  event.object_type # => 'activity'
899
849
  event.object_id # => 1991813808
900
850
  event.aspect_type # => 'update'
901
- event.updates # => { 'type' => 'Walk' }
851
+ event.updates # => { 'sport_type' => 'Walk' }
902
852
  event.owner_id # => 29323238
903
853
  event.subscription_id # => 131302
904
854
  event.event_time # => DateTime
@@ -945,6 +895,58 @@ Delete an existing subscription.
945
895
  client.delete_push_subscription(131300) # => nil
946
896
  ```
947
897
 
898
+ ### Ratelimit
899
+
900
+ Every API call's HTTP Reponse Content, be it a single Model or a list (via pagination), can be accessed by using `#http_response`.
901
+
902
+ `client.athlete` #=> `Strava::Models::Athlete#http_response`
903
+
904
+ `client.activity_comments(id: 1234567)` #=> `Array<Strava::Models::Comment>#http_response`
905
+
906
+ `http_response` itself is a `Strava::Web::ApiResponse` class. Ratelimits are accessed via this class using `Strava::Web::ApiResponse#ratelimit`. See the examples given below:
907
+
908
+ ```ruby
909
+ comments = client.activity_comments(id: 123_456_789)
910
+
911
+ # comments == Array<Strava::Models::Comment>
912
+ comments.http_response.ratelimit.to_h
913
+ ```
914
+
915
+ ```ruby
916
+ athlete = client.athlete # => Strava::Models::Athlete
917
+ athlete.http_response.ratelimit
918
+ ```
919
+
920
+ The following properties are available on Strava::Api::Ratelimit.
921
+
922
+ - `limit`
923
+ - `limit?`
924
+ - `usage`
925
+ - `fifteen_minutes`
926
+ - `fifteen_minutes_usage`
927
+ - `fifteen_minutes_remaining`
928
+ - `total_day`
929
+ - `total_day_usage`
930
+ - `total_day_remaining`
931
+ - `to_h`
932
+ - `to_s`
933
+
934
+ You can access the Hash containing all limits by calling `to_h`.
935
+
936
+ ```ruby
937
+ # athlete.http_response.ratelimit.to_h
938
+ {
939
+ limit: limit,
940
+ usage: usage,
941
+ total_day: total_day,
942
+ total_day_usage: total_day_usage,
943
+ total_day_remaining: total_day_remaining,
944
+ fifteen_minutes: fifteen_minutes,
945
+ fifteen_minutes_usage: fifteen_minutes_usage,
946
+ fifteen_minutes_remaining: fifteen_minutes_remaining
947
+ }
948
+ ```
949
+
948
950
  ## Configuration
949
951
 
950
952
  ### Web Client Options
@@ -959,15 +961,15 @@ end
959
961
 
960
962
  The following settings are supported.
961
963
 
962
- setting | description
963
- --------------------|------------
964
- user_agent | User-agent, defaults to _Strava Ruby Client/version_.
965
- proxy | Optional HTTP proxy.
966
- ca_path | Optional SSL certificates path.
967
- ca_file | Optional SSL certificates file.
968
- logger | Optional `Logger` instance that logs HTTP requests.
969
- timeout | Optional open/read timeout in seconds.
970
- open_timeout | Optional connection open timeout in seconds.
964
+ | setting | description |
965
+ | ------------ | ----------------------------------------------------- |
966
+ | user_agent | User-agent, defaults to _Strava Ruby Client/version_. |
967
+ | proxy | Optional HTTP proxy. |
968
+ | ca_path | Optional SSL certificates path. |
969
+ | ca_file | Optional SSL certificates file. |
970
+ | logger | Optional `Logger` instance that logs HTTP requests. |
971
+ | timeout | Optional open/read timeout in seconds. |
972
+ | open_timeout | Optional connection open timeout in seconds. |
971
973
 
972
974
  ### API Client Options
973
975
 
@@ -988,10 +990,10 @@ client = Strava::API::Client.new(
988
990
 
989
991
  The following settings are supported.
990
992
 
991
- setting | description
992
- --------------------|------------
993
- access_token | Access token to pass in the `Authorization` header.
994
- endpoint | Defaults to `https://www.strava.com/api/v3`.
993
+ | setting | description |
994
+ | ------------ | --------------------------------------------------- |
995
+ | access_token | Access token to pass in the `Authorization` header. |
996
+ | endpoint | Defaults to `https://www.strava.com/api/v3`. |
995
997
 
996
998
  ### OAuth Client Options
997
999
 
@@ -1014,11 +1016,11 @@ client = Strava::OAuth::Client.new(
1014
1016
 
1015
1017
  The following settings are supported.
1016
1018
 
1017
- setting | description
1018
- --------------------|------------
1019
- client_id | Application client ID.
1020
- client_secret | Application client secret.
1021
- endpoint | Defaults to `https://www.strava.com/oauth`.
1019
+ | setting | description |
1020
+ | ------------- | ------------------------------------------- |
1021
+ | client_id | Application client ID. |
1022
+ | client_secret | Application client secret. |
1023
+ | endpoint | Defaults to `https://www.strava.com/oauth`. |
1022
1024
 
1023
1025
  ### Webhooks Client Options
1024
1026
 
@@ -1041,11 +1043,11 @@ client = Strava::Webhooks::Client.new(
1041
1043
 
1042
1044
  The following settings are supported.
1043
1045
 
1044
- setting | description
1045
- --------------------|------------
1046
- client_id | Application client ID.
1047
- client_secret | Application client secret.
1048
- endpoint | Defaults to `https://www.strava.com/api/v3`.
1046
+ | setting | description |
1047
+ | ------------- | -------------------------------------------- |
1048
+ | client_id | Application client ID. |
1049
+ | client_secret | Application client secret. |
1050
+ | endpoint | Defaults to `https://www.strava.com/api/v3`. |
1049
1051
 
1050
1052
  ## Errors
1051
1053
 
@@ -1070,22 +1072,22 @@ For a complete set of command-line tools, check out [strava-ruby-cli](https://gi
1070
1072
  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.
1071
1073
 
1072
1074
  ```bash
1073
- $ STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-token
1075
+ STRAVA_CLIENT_ID=... STRAVA_CLIENT_SECRET=... strava-oauth-token
1074
1076
  ```
1075
1077
 
1076
1078
  ## Users
1077
1079
 
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)
1080
+ - [Slava: Strava integration with Slack](https://slava.playplay.io), [source](https://github.com/dblock/slack-strava).
1081
+ - [Jekyll Blog at run.dblock.org](https://run.dblock.org), [source](https://github.com/dblock/run.dblock.org)
1082
+ - [Secret Strava](https://steele.blue/secret-strava/), [source](https://github.com/mattdsteele/secret-strava)
1081
1083
 
1082
1084
  ## Resources
1083
1085
 
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)
1086
+ - [Strava API Documentation](https://developers.strava.com)
1087
+ - [Writing a New Strava API Ruby Client](https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html)
1088
+ - [Dealing with Strava API OAuth Token Migration](https://code.dblock.org/2018/11/17/dealing-with-strava-api-token-migration.html)
1089
+ - [Auto-Publishing Strava Runs to Github Pages](https://code.dblock.org/2018/02/17/auto-publishing-strava-runs-to-github-pages.html)
1090
+ - [Strava Command-Line Client](https://github.com/dblock/strava-ruby-cli)
1089
1091
 
1090
1092
  ## Upgrading
1091
1093
 
@@ -12,8 +12,8 @@ trap 'INT' do
12
12
  end
13
13
 
14
14
  client = Strava::OAuth::Client.new(
15
- client_id: ENV['STRAVA_CLIENT_ID'],
16
- client_secret: ENV['STRAVA_CLIENT_SECRET']
15
+ client_id: ENV.fetch('STRAVA_CLIENT_ID', nil),
16
+ client_secret: ENV.fetch('STRAVA_CLIENT_SECRET', nil)
17
17
  )
18
18
 
19
19
  server.mount_proc '/' do |req, res|
data/bin/strava-webhooks CHANGED
@@ -9,8 +9,8 @@ logger = ::Logger.new($stdout)
9
9
  logger.level = Logger::INFO
10
10
 
11
11
  client = Strava::Webhooks::Client.new(
12
- client_id: ENV['STRAVA_CLIENT_ID'],
13
- client_secret: ENV['STRAVA_CLIENT_SECRET'],
12
+ client_id: ENV.fetch('STRAVA_CLIENT_ID', nil),
13
+ client_secret: ENV.fetch('STRAVA_CLIENT_SECRET', nil),
14
14
  logger: logger
15
15
  )
16
16
 
@@ -40,18 +40,37 @@ module Strava
40
40
 
41
41
  private
42
42
 
43
+ #
44
+ # paginates requests
45
+ #
46
+ # @param [String] path url for request
47
+ # @param [Hash] options hash containing settings
48
+ # @param [Class] model by Class
49
+ #
50
+ # @example
51
+ # paginate("athlete/activities", {per_page: 72}, Strava::Models::Activity)
52
+ #
53
+ # @return [Strava::Api::Pagination]
54
+ #
43
55
  def paginate(path, options, model)
56
+ collection = []
57
+ web_response = nil
44
58
  if block_given?
45
59
  Cursor.new(self, path, options).each do |page|
60
+ web_response = page # response of the last request made
46
61
  page.each do |row|
47
- yield model.new(row)
62
+ m = model.new(row)
63
+ yield m
64
+ collection << m
48
65
  end
49
66
  end
50
67
  else
51
- get(path, options).map do |row|
68
+ web_response = get(path, options)
69
+ collection = web_response.map do |row|
52
70
  model.new(row)
53
71
  end
54
72
  end
73
+ Pagination.new(collection, web_response)
55
74
  end
56
75
  end
57
76
  end
@@ -12,7 +12,7 @@ module Strava
12
12
  #
13
13
  def export_route_gpx(id_or_options, options = {})
14
14
  id, options = parse_args(id_or_options, options)
15
- get "routes/#{id}/export_gpx", options
15
+ get("routes/#{id}/export_gpx", options).response
16
16
  end
17
17
 
18
18
  #
@@ -23,7 +23,7 @@ module Strava
23
23
  #
24
24
  def export_route_tcx(id_or_options, options = {})
25
25
  id, options = parse_args(id_or_options, options)
26
- get "routes/#{id}/export_tcx", options
26
+ get("routes/#{id}/export_tcx", options).response
27
27
  end
28
28
 
29
29
  #
@@ -14,18 +14,6 @@ module Strava
14
14
  id, options = parse_args(id_or_options, options)
15
15
  Strava::Models::RunningRace.new(get("running_races/#{id}", options))
16
16
  end
17
-
18
- #
19
- # Returns a list running races based on a set of search criteria.
20
- #
21
- # @option options [Integer] :year
22
- # Filters the list by a given year.
23
- #
24
- def running_races(options = {})
25
- get('running_races', options).map do |row|
26
- Strava::Models::RunningRace.new(row)
27
- end
28
- end
29
17
  end
30
18
  end
31
19
  end
@@ -25,52 +25,6 @@ module Strava
25
25
  end
26
26
  end
27
27
 
28
- #
29
- # Returns the specified segment leaderboard.
30
- #
31
- # @option options [Integer] :id
32
- # The identifier of the segment leaderboard.
33
- # @option options [String] :gender
34
- # Filter by gender.
35
- # @option options [String] :age_group
36
- # Filter by age group.
37
- # @option options [String] :weight_class
38
- # Filter by weight class.
39
- # @option options [Boolean] :following
40
- # Filter by friends of the authenticated athlete.
41
- # @option options [Integer] :club_id
42
- # Filter by club.
43
- # @option options [String] :date_range
44
- # Filter by date range.
45
- # @option options [Integer] :context_entries
46
- # ?
47
- # @option options [Integer] :page
48
- # Page number.
49
- # @option options [Integer] :per_page
50
- # Number of items per page. Defaults to 30.
51
- #
52
- def segment_leaderboard(id_or_options, options = {})
53
- id, options = parse_args(id_or_options, options)
54
-
55
- if block_given?
56
- next_page = 1
57
- total_count = 0
58
- loop do
59
- query = options.merge(page: next_page)
60
- response = Strava::Models::SegmentLeaderboard.new(get("segments/#{id}/leaderboard", query))
61
- total_count += response.entries.count
62
- break unless response.entries.any?
63
-
64
- yield response
65
- break if total_count >= response.entry_count
66
-
67
- next_page += 1
68
- end
69
- else
70
- Strava::Models::SegmentLeaderboard.new(get("segments/#{id}/leaderboard", options))
71
- end
72
- end
73
-
74
28
  #
75
29
  # List of the authenticated athlete's starred segments.
76
30
  #
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strava
4
+ module Api
5
+ #
6
+ # Wrapper Class around pagination results which are an Array of Models.
7
+ #
8
+ # This class exists to provide a way to provide a high-level abstraction, like
9
+ # access to API request/response data (i.e. ratelimits) for paginated results.
10
+ #
11
+ class Pagination
12
+ include Enumerable
13
+ include Strava::DeepCopyable
14
+
15
+ attr_reader :collection
16
+
17
+ #
18
+ # @param [Array<Strava::Models::>] collection of Models
19
+ # @param [Strava::Web::Response] web_response
20
+ #
21
+ def initialize(collection, web_response)
22
+ @collection = collection
23
+ @web_response = web_response
24
+ end
25
+
26
+ #
27
+ # getter method that calculates on access
28
+ #
29
+ # @return [Strava::Web::ApiResponse]
30
+ #
31
+ def http_response
32
+ @http_response ||=
33
+ Strava::Web::ApiResponse.new(deep_copy(@web_response).http_response)
34
+ end
35
+
36
+ #
37
+ # delegates `size` to @collection
38
+ #
39
+ # @return [Integer]
40
+ #
41
+ def size
42
+ @collection.size
43
+ end
44
+
45
+ def each
46
+ @collection.each { |c| yield c if block_given? }
47
+ end
48
+
49
+ private
50
+
51
+ def method_missing(method_symbol, *args, &block)
52
+ @collection.send(method_symbol, *args, &block)
53
+ end
54
+
55
+ def respond_to_missing?(method_name, include_private = false)
56
+ super
57
+ end
58
+ end
59
+ end
60
+ end