strava-ruby-client 3.0.0 → 3.2.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 +29 -0
- data/README.md +44 -995
- data/bin/strava-webhooks +50 -38
- data/lib/strava/api/client.rb +69 -0
- data/lib/strava/api/config.rb +40 -0
- data/lib/strava/api/cursor.rb +32 -1
- data/lib/strava/api/endpoints/activities.rb +197 -57
- data/lib/strava/api/endpoints/athletes.rb +64 -8
- data/lib/strava/api/endpoints/clubs.rb +24 -59
- data/lib/strava/api/endpoints/gears.rb +11 -2
- data/lib/strava/api/endpoints/oauth.rb +45 -0
- data/lib/strava/api/endpoints/routes.rb +20 -13
- data/lib/strava/api/endpoints/segment_efforts.rb +15 -8
- data/lib/strava/api/endpoints/segments.rb +74 -21
- data/lib/strava/api/endpoints/streams.rb +22 -18
- data/lib/strava/api/endpoints/uploads.rb +12 -2
- data/lib/strava/api/pagination.rb +26 -2
- data/lib/strava/api/ratelimit.rb +34 -0
- data/lib/strava/deep_copyable.rb +20 -1
- data/lib/strava/errors/fault.rb +32 -0
- data/lib/strava/errors/ratelimit_error.rb +35 -0
- data/lib/strava/errors/upload_error.rb +55 -0
- data/lib/strava/logger.rb +27 -0
- data/lib/strava/models/achievement.rb +28 -1
- data/lib/strava/models/activity_stats.rb +47 -1
- data/lib/strava/models/activity_total.rb +32 -1
- data/lib/strava/models/activity_zone.rb +46 -2
- data/lib/strava/models/authorization.rb +13 -0
- data/lib/strava/models/base_stream.rb +22 -1
- data/lib/strava/models/club_event.rb +66 -3
- data/lib/strava/models/comment.rb +40 -2
- data/lib/strava/models/destination.rb +28 -1
- data/lib/strava/models/detailed_activity.rb +211 -3
- data/lib/strava/models/detailed_athlete.rb +106 -4
- data/lib/strava/models/detailed_club.rb +76 -2
- data/lib/strava/models/detailed_gear.rb +45 -2
- data/lib/strava/models/detailed_photo.rb +64 -4
- data/lib/strava/models/detailed_photos.rb +36 -1
- data/lib/strava/models/detailed_segment.rb +98 -4
- data/lib/strava/models/detailed_segment_effort.rb +93 -4
- data/lib/strava/models/explorer_segment.rb +55 -2
- data/lib/strava/models/heart_rate_zone_ranges.rb +29 -1
- data/lib/strava/models/kudoser.rb +29 -1
- data/lib/strava/models/lap.rb +63 -3
- data/lib/strava/models/lat_lng.rb +42 -4
- data/lib/strava/models/local_legend.rb +41 -1
- data/lib/strava/models/map.rb +31 -0
- data/lib/strava/models/meta_activity.rb +15 -2
- data/lib/strava/models/meta_athlete.rb +17 -2
- data/lib/strava/models/meta_club.rb +15 -1
- data/lib/strava/models/mixins/average_speed.rb +81 -3
- data/lib/strava/models/mixins/distance.rb +25 -0
- data/lib/strava/models/mixins/elapsed_time.rb +18 -0
- data/lib/strava/models/mixins/elevation_difference.rb +42 -0
- data/lib/strava/models/mixins/elevation_gain.rb +39 -0
- data/lib/strava/models/mixins/estimated_moving_time.rb +18 -0
- data/lib/strava/models/mixins/http_response.rb +36 -0
- data/lib/strava/models/mixins/moving_time.rb +18 -0
- data/lib/strava/models/mixins/sport_type.rb +39 -1
- data/lib/strava/models/mixins/start_date_local.rb +41 -25
- data/lib/strava/models/mixins/time_in_hours.rb +23 -0
- data/lib/strava/models/mixins/total_elevation_gain.rb +42 -0
- data/lib/strava/models/model.rb +29 -0
- data/lib/strava/models/photos_summary.rb +33 -2
- data/lib/strava/models/photos_summary_primary.rb +28 -2
- data/lib/strava/models/power_zone_ranges.rb +23 -1
- data/lib/strava/models/response.rb +18 -0
- data/lib/strava/models/route.rb +72 -4
- data/lib/strava/models/similar_activities.rb +57 -1
- data/lib/strava/models/split.rb +27 -2
- data/lib/strava/models/stats_visibility.rb +24 -1
- data/lib/strava/models/stream.rb +107 -0
- data/lib/strava/models/stream_set.rb +52 -1
- data/lib/strava/models/summary_activity.rb +153 -3
- data/lib/strava/models/summary_athlete.rb +56 -3
- data/lib/strava/models/summary_club.rb +61 -2
- data/lib/strava/models/summary_gear.rb +31 -2
- data/lib/strava/models/summary_pr_segment_effort.rb +32 -2
- data/lib/strava/models/summary_segment.rb +81 -3
- data/lib/strava/models/summary_segment_effort.rb +33 -2
- data/lib/strava/models/timed_zone_range.rb +38 -1
- data/lib/strava/models/token.rb +31 -0
- data/lib/strava/models/trend.rb +38 -1
- data/lib/strava/models/updatable_activity.rb +36 -1
- data/lib/strava/models/upload.rb +50 -1
- data/lib/strava/models/waypoint.rb +31 -1
- data/lib/strava/models/xoms.rb +35 -1
- data/lib/strava/models/zone_range.rb +34 -1
- data/lib/strava/models/zones.rb +32 -1
- data/lib/strava/oauth/client.rb +107 -19
- data/lib/strava/oauth/config.rb +41 -0
- data/lib/strava/version.rb +1 -1
- data/lib/strava/web/api_response.rb +28 -2
- data/lib/strava/web/client.rb +73 -3
- data/lib/strava/web/config.rb +44 -0
- data/lib/strava/web/connection.rb +46 -2
- data/lib/strava/web/filter.rb +72 -0
- data/lib/strava/web/log_formatter.rb +20 -0
- data/lib/strava/web/raise_response_error.rb +73 -9
- data/lib/strava/web/request.rb +56 -0
- data/lib/strava/web/response.rb +30 -29
- data/lib/strava/webhooks/client.rb +108 -7
- data/lib/strava/webhooks/config.rb +44 -0
- data/lib/strava/webhooks/models/challenge.rb +40 -0
- data/lib/strava/webhooks/models/event.rb +58 -0
- data/lib/strava/webhooks/models/subscription.rb +29 -2
- data/lib/strava-ruby-client.rb +2 -2
- metadata +7 -11
- data/lib/strava/models/club_activity.rb +0 -22
- data/lib/strava/models/club_athlete.rb +0 -21
|
@@ -2,10 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents a training zone range with time spent in that zone.
|
|
7
|
+
#
|
|
8
|
+
# Used in activity zone distributions to show how much time was spent
|
|
9
|
+
# at different intensity levels during an activity.
|
|
10
|
+
#
|
|
11
|
+
# @see https://developers.strava.com/docs/reference/#api-models-TimedZoneRange Strava API TimedZoneRange reference
|
|
12
|
+
# @see Strava::Models::ZoneRange
|
|
13
|
+
# @see Strava::Models::ActivityZone
|
|
14
|
+
#
|
|
15
|
+
# @example Viewing time distribution across zones
|
|
16
|
+
# zones = client.activity_zones(1234567890)
|
|
17
|
+
# hr_zone = zones.find { |z| z.type == 'heartrate' }
|
|
18
|
+
#
|
|
19
|
+
# hr_zone.distribution_buckets.each_with_index do |bucket, i|
|
|
20
|
+
# minutes = bucket.time / 60
|
|
21
|
+
# puts "Zone #{i + 1} (#{bucket.min}-#{bucket.max} bpm): #{minutes} minutes"
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
6
24
|
class TimedZoneRange < Strava::Models::Response
|
|
25
|
+
# @return [Integer] Maximum value for this zone (e.g., maximum heart rate or power)
|
|
7
26
|
property 'max'
|
|
27
|
+
|
|
28
|
+
# Hashie >= 6 does not define property readers that conflict with existing methods.
|
|
29
|
+
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('6.0')
|
|
30
|
+
def max
|
|
31
|
+
self['max']
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Integer] Minimum value for this zone (e.g., minimum heart rate or power)
|
|
8
36
|
property 'min'
|
|
37
|
+
|
|
38
|
+
# Hashie >= 6 does not define property readers that conflict with existing methods.
|
|
39
|
+
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('6.0')
|
|
40
|
+
def min
|
|
41
|
+
self['min']
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [Integer] Time spent in this zone in seconds
|
|
9
46
|
property 'time'
|
|
10
47
|
end
|
|
11
48
|
end
|
data/lib/strava/models/token.rb
CHANGED
|
@@ -2,12 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
+
#
|
|
6
|
+
# Represents an OAuth token response from Strava.
|
|
7
|
+
#
|
|
8
|
+
# This model is returned when exchanging an authorization code for an access token
|
|
9
|
+
# or when refreshing an expired token. It contains the access token, refresh token,
|
|
10
|
+
# expiration time, and basic athlete information.
|
|
11
|
+
#
|
|
12
|
+
# Tokens expire after a period of time (typically 6 hours). When a token expires,
|
|
13
|
+
# use the refresh_token to obtain a new access_token via the OAuth flow.
|
|
14
|
+
#
|
|
15
|
+
# @example Inspecting token information
|
|
16
|
+
# token = client.oauth_token(code: 'auth_code')
|
|
17
|
+
# puts "Access Token: #{token.access_token}"
|
|
18
|
+
# puts "Refresh Token: #{token.refresh_token}"
|
|
19
|
+
# puts "Expires at: #{token.expires_at}"
|
|
20
|
+
# puts "Athlete: #{token.athlete.firstname} #{token.athlete.lastname}"
|
|
21
|
+
#
|
|
22
|
+
# @see Strava::OAuth::Client#oauth_token
|
|
23
|
+
# @see https://developers.strava.com/docs/authentication/
|
|
24
|
+
#
|
|
5
25
|
class Token < Strava::Models::Response
|
|
26
|
+
# @return [String] Type of token, typically "Bearer"
|
|
6
27
|
property 'token_type'
|
|
28
|
+
|
|
29
|
+
# @return [String] OAuth access token for API authentication
|
|
7
30
|
property 'access_token'
|
|
31
|
+
|
|
32
|
+
# @return [String] Refresh token for obtaining new access tokens
|
|
8
33
|
property 'refresh_token'
|
|
34
|
+
|
|
35
|
+
# @return [Integer] Number of seconds until token expires
|
|
9
36
|
property 'expires_in'
|
|
37
|
+
|
|
38
|
+
# @return [Time] Expiration time of the access token
|
|
10
39
|
property 'expires_at', transform_with: ->(v) { Time.at(v) }
|
|
40
|
+
|
|
41
|
+
# @return [Strava::Models::SummaryAthlete] Summary of the authenticated athlete
|
|
11
42
|
property 'athlete', transform_with: ->(v) { Strava::Models::SummaryAthlete.new(v) }
|
|
12
43
|
end
|
|
13
44
|
end
|
data/lib/strava/models/trend.rb
CHANGED
|
@@ -2,13 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents performance trend data.
|
|
7
|
+
#
|
|
8
|
+
# Contains trend information about speed and performance over time,
|
|
9
|
+
# showing whether performance is improving, declining, or staying consistent.
|
|
10
|
+
# This model is not documented in the official Strava API reference.
|
|
11
|
+
#
|
|
12
|
+
# @note This model is not documented by Strava API documentation. Properties
|
|
13
|
+
# are inferred from API responses.
|
|
14
|
+
#
|
|
15
|
+
# @see Strava::Models::SimilarActivities
|
|
16
|
+
#
|
|
17
|
+
# @example Accessing trend data
|
|
18
|
+
# activity = client.activity(1234567890)
|
|
19
|
+
# if activity.similar_activities&.trend
|
|
20
|
+
# trend = activity.similar_activities.trend
|
|
21
|
+
# puts "Trend direction: #{trend.direction}"
|
|
22
|
+
# puts "Speed range: #{trend.min_speed} - #{trend.max_speed} m/s"
|
|
23
|
+
# puts "Current activity index: #{trend.current_activity_index}"
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
6
26
|
class Trend < Strava::Models::Response
|
|
27
|
+
# @return [Array, nil] Array of speed values showing the trend
|
|
28
|
+
# @note Not documented by Strava API
|
|
7
29
|
property 'speeds'
|
|
30
|
+
|
|
31
|
+
# @return [Integer, nil] Index of current activity in the trend series
|
|
32
|
+
# @note Not documented by Strava API
|
|
8
33
|
property 'current_activity_index'
|
|
34
|
+
|
|
35
|
+
# @return [Float, nil] Minimum speed in the trend in meters per second
|
|
36
|
+
# @note Not documented by Strava API
|
|
9
37
|
property 'min_speed'
|
|
38
|
+
|
|
39
|
+
# @return [Float, nil] Median speed in the trend in meters per second
|
|
40
|
+
# @note Not documented by Strava API
|
|
10
41
|
property 'mid_speed'
|
|
42
|
+
|
|
43
|
+
# @return [Float, nil] Maximum speed in the trend in meters per second
|
|
44
|
+
# @note Not documented by Strava API
|
|
11
45
|
property 'max_speed'
|
|
46
|
+
|
|
47
|
+
# @return [Integer, nil] Trend direction indicator (e.g., -1=declining, 0=stable, 1=improving)
|
|
48
|
+
# @note Not documented by Strava API
|
|
12
49
|
property 'direction'
|
|
13
50
|
end
|
|
14
51
|
end
|
|
@@ -2,14 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents the response from updating an activity.
|
|
7
|
+
#
|
|
8
|
+
# When you update an activity using the update_activity endpoint, Strava returns
|
|
9
|
+
# this model containing the fields that were successfully updated. This is a subset
|
|
10
|
+
# of the full activity data.
|
|
11
|
+
#
|
|
12
|
+
# @see https://developers.strava.com/docs/reference/#api-models-UpdatableActivity Strava API UpdatableActivity reference
|
|
13
|
+
# @see Strava::Api::Client#update_activity
|
|
14
|
+
# @see Strava::Models::DetailedActivity
|
|
15
|
+
#
|
|
16
|
+
# @example Updating activity properties
|
|
17
|
+
# updated = client.update_activity(1234567890,
|
|
18
|
+
# name: "Morning Run",
|
|
19
|
+
# description: "Great weather today!",
|
|
20
|
+
# commute: false,
|
|
21
|
+
# trainer: false,
|
|
22
|
+
# gear_id: "g12345"
|
|
23
|
+
# )
|
|
24
|
+
#
|
|
25
|
+
# puts "Activity renamed to: #{updated.name}"
|
|
26
|
+
# puts "Gear ID: #{updated.gear_id}"
|
|
27
|
+
#
|
|
6
28
|
class UpdatableActivity < Strava::Models::Response
|
|
29
|
+
# @return [Boolean, nil] Whether this activity is a commute
|
|
7
30
|
property 'commute'
|
|
31
|
+
|
|
32
|
+
# @return [Boolean, nil] Whether this activity was done on a trainer/treadmill
|
|
8
33
|
property 'trainer'
|
|
34
|
+
|
|
35
|
+
# @return [Boolean, nil] Whether to hide this activity from the home feed
|
|
9
36
|
property 'hide_from_home'
|
|
37
|
+
|
|
38
|
+
# @return [String, nil] Description of the activity
|
|
10
39
|
property 'description'
|
|
40
|
+
|
|
41
|
+
# @return [String, nil] Name/title of the activity
|
|
11
42
|
property 'name'
|
|
43
|
+
|
|
44
|
+
# @return [String, nil] Sport type (e.g., "Run", "Ride", "Swim")
|
|
12
45
|
property 'sport_type'
|
|
46
|
+
|
|
47
|
+
# @return [String, nil] ID of the gear (shoes/bike) used for this activity
|
|
13
48
|
property 'gear_id'
|
|
14
49
|
end
|
|
15
50
|
end
|
data/lib/strava/models/upload.rb
CHANGED
|
@@ -2,20 +2,69 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents an activity file upload status.
|
|
7
|
+
#
|
|
8
|
+
# When uploading activity files (GPX, TCX, FIT) to Strava, the upload is processed
|
|
9
|
+
# asynchronously. This model tracks the upload status and provides helper methods
|
|
10
|
+
# to check if processing is complete.
|
|
11
|
+
#
|
|
12
|
+
# @example Upload and poll for completion
|
|
13
|
+
# upload = client.create_upload(
|
|
14
|
+
# file: Faraday::UploadIO.new('activity.gpx', 'application/gpx+xml'),
|
|
15
|
+
# data_type: 'gpx'
|
|
16
|
+
# )
|
|
17
|
+
#
|
|
18
|
+
# while upload.processing?
|
|
19
|
+
# sleep 2
|
|
20
|
+
# upload = client.upload(upload.id)
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# if upload.error
|
|
24
|
+
# puts "Upload failed: #{upload.error}"
|
|
25
|
+
# else
|
|
26
|
+
# puts "Activity created: #{upload.activity_id}"
|
|
27
|
+
# end
|
|
28
|
+
#
|
|
29
|
+
# @see Strava::Api::Client#create_upload
|
|
30
|
+
# @see Strava::Api::Client#upload
|
|
31
|
+
# @see https://developers.strava.com/docs/reference/#api-models-Upload
|
|
32
|
+
#
|
|
6
33
|
class Upload < Strava::Models::Response
|
|
34
|
+
# @return [Integer] Upload ID
|
|
7
35
|
property 'id'
|
|
36
|
+
|
|
37
|
+
# @return [String] Upload ID as string
|
|
8
38
|
property 'id_str'
|
|
39
|
+
|
|
40
|
+
# @return [String] External identifier for the upload
|
|
9
41
|
property 'external_id'
|
|
42
|
+
|
|
43
|
+
# @return [String, nil] Error message if upload failed
|
|
10
44
|
property 'error'
|
|
45
|
+
|
|
46
|
+
# @return [String] Status message (e.g., "Your activity is ready.", "Your activity is still being processed.")
|
|
11
47
|
property 'status'
|
|
48
|
+
|
|
49
|
+
# @return [Integer, nil] Activity ID once processing is complete
|
|
12
50
|
property 'activity_id'
|
|
13
51
|
|
|
52
|
+
#
|
|
53
|
+
# Checks if the upload is still processing.
|
|
54
|
+
#
|
|
55
|
+
# @return [Boolean] true if upload is still being processed
|
|
56
|
+
# @raise [Strava::Errors::UploadError] if upload failed with an error
|
|
57
|
+
#
|
|
14
58
|
def processing?
|
|
15
59
|
validate!
|
|
16
60
|
activity_id.nil?
|
|
17
61
|
end
|
|
18
62
|
|
|
63
|
+
#
|
|
64
|
+
# Checks if the upload has completed processing.
|
|
65
|
+
#
|
|
66
|
+
# @return [Boolean] true if upload processing is complete
|
|
67
|
+
#
|
|
19
68
|
def processed?
|
|
20
69
|
!processing?
|
|
21
70
|
end
|
|
@@ -2,13 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents a waypoint on a route.
|
|
7
|
+
#
|
|
8
|
+
# Waypoints are markers along a route that can indicate points of interest,
|
|
9
|
+
# turns, or other significant locations. They include GPS coordinates and
|
|
10
|
+
# descriptive information.
|
|
11
|
+
#
|
|
12
|
+
# @see https://developers.strava.com/docs/reference/#api-models-Waypoint Strava API Waypoint reference
|
|
13
|
+
# @see Strava::Models::Route
|
|
14
|
+
# @see Strava::Models::LatLng
|
|
15
|
+
#
|
|
16
|
+
# @example Accessing route waypoints
|
|
17
|
+
# route = client.route(1234567)
|
|
18
|
+
# route.waypoints.each do |waypoint|
|
|
19
|
+
# puts "#{waypoint.title}: #{waypoint.description}"
|
|
20
|
+
# puts " Location: #{waypoint.latlng.lat}, #{waypoint.latlng.lng}"
|
|
21
|
+
# puts " Distance into route: #{waypoint.distance_into_route}m"
|
|
22
|
+
# puts " Categories: #{waypoint.categories.join(', ')}"
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
6
25
|
class Waypoint < Strava::Models::Response
|
|
26
|
+
# @return [LatLng] GPS coordinates of the waypoint
|
|
7
27
|
property 'latlng', transform_with: ->(v) { Strava::Models::LatLng.new(v) }
|
|
28
|
+
|
|
29
|
+
# @return [LatLng, nil] Target GPS coordinates (may differ from latlng for snapped waypoints)
|
|
8
30
|
property 'target_latlng', transform_with: ->(v) { Strava::Models::LatLng.new(v) }
|
|
31
|
+
|
|
32
|
+
# @return [Array<String>] Categories or types for this waypoint (e.g., ["water", "rest"])
|
|
9
33
|
property 'categories'
|
|
34
|
+
|
|
35
|
+
# @return [String] Title or name of the waypoint
|
|
10
36
|
property 'title'
|
|
37
|
+
|
|
38
|
+
# @return [String, nil] Detailed description of the waypoint
|
|
11
39
|
property 'description'
|
|
40
|
+
|
|
41
|
+
# @return [Float] Distance from the start of the route to this waypoint in meters
|
|
12
42
|
property 'distance_into_route'
|
|
13
43
|
end
|
|
14
44
|
end
|
data/lib/strava/models/xoms.rb
CHANGED
|
@@ -2,11 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents segment leaderboard achievements (KOM/QOM).
|
|
7
|
+
#
|
|
8
|
+
# Contains information about King of the Mountain (KOM), Queen of the Mountain (QOM),
|
|
9
|
+
# and overall segment records. This model is not documented in the official Strava
|
|
10
|
+
# API reference.
|
|
11
|
+
#
|
|
12
|
+
# @note This model is not documented by Strava API documentation. Properties
|
|
13
|
+
# are inferred from API responses.
|
|
14
|
+
#
|
|
15
|
+
# @see Strava::Models::DetailedActivity
|
|
16
|
+
# @see Strava::Models::Destination
|
|
17
|
+
#
|
|
18
|
+
# @example Accessing XOM (KOM/QOM) information
|
|
19
|
+
# activity = client.activity(1234567890)
|
|
20
|
+
# if activity.xoms
|
|
21
|
+
# puts "KOM: #{activity.xoms.kom}"
|
|
22
|
+
# puts "QOM: #{activity.xoms.qom}"
|
|
23
|
+
# puts "Overall: #{activity.xoms.overall}"
|
|
24
|
+
# if activity.xoms.destination
|
|
25
|
+
# puts "Segment: #{activity.xoms.destination.name}"
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
#
|
|
6
29
|
class Xoms < Strava::Models::Response
|
|
30
|
+
# @return [String, Integer, nil] King of the Mountain achievement data
|
|
31
|
+
# @note Not documented by Strava API
|
|
7
32
|
property 'kom'
|
|
33
|
+
|
|
34
|
+
# @return [String, Integer, nil] Queen of the Mountain achievement data
|
|
35
|
+
# @note Not documented by Strava API
|
|
8
36
|
property 'qom'
|
|
37
|
+
|
|
38
|
+
# @return [String, Integer, nil] Overall segment record data
|
|
39
|
+
# @note Not documented by Strava API
|
|
9
40
|
property 'overall'
|
|
41
|
+
|
|
42
|
+
# @return [Destination, nil] Link to the segment where this achievement was earned
|
|
43
|
+
# @note Not documented by Strava API
|
|
10
44
|
property 'destination', transform_with: ->(v) { Strava::Models::Destination.new(v) }
|
|
11
45
|
end
|
|
12
46
|
end
|
|
@@ -2,10 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents a single training zone range.
|
|
7
|
+
#
|
|
8
|
+
# Training zones define intensity levels for heart rate or power. Each zone
|
|
9
|
+
# has a minimum and maximum value that defines the range for that intensity level.
|
|
10
|
+
#
|
|
11
|
+
# @see https://developers.strava.com/docs/reference/#api-models-ZoneRange Strava API ZoneRange reference
|
|
12
|
+
# @see Strava::Models::HeartRateZoneRanges
|
|
13
|
+
# @see Strava::Models::PowerZoneRanges
|
|
14
|
+
# @see Strava::Models::TimedZoneRange
|
|
15
|
+
#
|
|
16
|
+
# @example Accessing zone ranges
|
|
17
|
+
# zones = client.athlete_zones
|
|
18
|
+
# zones.heart_rate.zones.each_with_index do |zone, i|
|
|
19
|
+
# puts "Zone #{i + 1}: #{zone.min}-#{zone.max} bpm"
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
6
22
|
class ZoneRange < Strava::Models::Response
|
|
23
|
+
# @return [Integer] Maximum value for this zone (e.g., maximum heart rate or power)
|
|
7
24
|
property 'max'
|
|
25
|
+
|
|
26
|
+
# Hashie >= 6 does not define property readers that conflict with existing methods.
|
|
27
|
+
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('6.0')
|
|
28
|
+
def max
|
|
29
|
+
self['max']
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Integer] Minimum value for this zone (e.g., minimum heart rate or power)
|
|
8
34
|
property 'min'
|
|
35
|
+
|
|
36
|
+
# Hashie >= 6 does not define property readers that conflict with existing methods.
|
|
37
|
+
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('6.0')
|
|
38
|
+
def min
|
|
39
|
+
self['min']
|
|
40
|
+
end
|
|
41
|
+
end
|
|
9
42
|
end
|
|
10
43
|
end
|
|
11
44
|
end
|
data/lib/strava/models/zones.rb
CHANGED
|
@@ -2,9 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Models
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
|
+
# Represents an athlete's training zones configuration.
|
|
7
|
+
#
|
|
8
|
+
# Training zones are used to define intensity levels for heart rate and power.
|
|
9
|
+
# These zones help athletes train at specific intensities and track time spent
|
|
10
|
+
# in each zone during activities.
|
|
11
|
+
#
|
|
12
|
+
# @see https://developers.strava.com/docs/reference/#api-models-Zones Strava API Zones reference
|
|
13
|
+
# @see Strava::Models::HeartRateZoneRanges
|
|
14
|
+
# @see Strava::Models::PowerZoneRanges
|
|
15
|
+
# @see Strava::Api::Client#athlete_zones
|
|
16
|
+
#
|
|
17
|
+
# @example Accessing athlete's training zones
|
|
18
|
+
# zones = client.athlete_zones
|
|
19
|
+
#
|
|
20
|
+
# # Heart rate zones
|
|
21
|
+
# if zones.heart_rate
|
|
22
|
+
# zones.heart_rate.zones.each_with_index do |zone, i|
|
|
23
|
+
# puts "HR Zone #{i + 1}: #{zone.min}-#{zone.max} bpm"
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# # Power zones
|
|
28
|
+
# if zones.power
|
|
29
|
+
# zones.power.zones.each_with_index do |zone, i|
|
|
30
|
+
# puts "Power Zone #{i + 1}: #{zone.min}-#{zone.max}W"
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
6
34
|
class Zones < Strava::Models::Response
|
|
35
|
+
# @return [HeartRateZoneRanges, nil] Heart rate zone configuration with zone ranges
|
|
7
36
|
property 'heart_rate', transform_with: ->(v) { Strava::Models::HeartRateZoneRanges.new(v) }
|
|
37
|
+
|
|
38
|
+
# @return [PowerZoneRanges, nil] Power zone configuration with zone ranges (for cyclists)
|
|
8
39
|
property 'power', transform_with: ->(v) { Strava::Models::PowerZoneRanges.new(v) }
|
|
9
40
|
end
|
|
10
41
|
end
|
data/lib/strava/oauth/client.rb
CHANGED
|
@@ -2,9 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module OAuth
|
|
5
|
+
#
|
|
6
|
+
# OAuth client for Strava authentication.
|
|
7
|
+
#
|
|
8
|
+
# This client handles the OAuth 2.0 authentication flow with Strava, including:
|
|
9
|
+
# * Generating authorization URLs
|
|
10
|
+
# * Exchanging authorization codes for access tokens
|
|
11
|
+
# * Refreshing expired access tokens
|
|
12
|
+
#
|
|
13
|
+
# @example Basic OAuth flow
|
|
14
|
+
# client = Strava::OAuth::Client.new(
|
|
15
|
+
# client_id: "your_client_id",
|
|
16
|
+
# client_secret: "your_client_secret"
|
|
17
|
+
# )
|
|
18
|
+
#
|
|
19
|
+
# # Step 1: Get authorization URL
|
|
20
|
+
# url = client.authorize_url(
|
|
21
|
+
# redirect_uri: 'http://localhost:3000/callback',
|
|
22
|
+
# scope: 'read,activity:read_all'
|
|
23
|
+
# )
|
|
24
|
+
# # Redirect user to this URL
|
|
25
|
+
#
|
|
26
|
+
# # Step 2: Exchange code for token
|
|
27
|
+
# token = client.oauth_token(code: params[:code])
|
|
28
|
+
# # Store token.access_token and token.refresh_token
|
|
29
|
+
#
|
|
30
|
+
# # Step 3: Refresh token when expired
|
|
31
|
+
# new_token = client.oauth_token(
|
|
32
|
+
# refresh_token: saved_refresh_token,
|
|
33
|
+
# grant_type: 'refresh_token'
|
|
34
|
+
# )
|
|
35
|
+
#
|
|
36
|
+
# @see https://developers.strava.com/docs/authentication/
|
|
37
|
+
#
|
|
5
38
|
class Client < Strava::Web::Client
|
|
6
39
|
attr_accessor(*Config::ATTRIBUTES)
|
|
7
40
|
|
|
41
|
+
#
|
|
42
|
+
# Initialize a new OAuth client.
|
|
43
|
+
#
|
|
44
|
+
# @param [Hash] options Configuration options
|
|
45
|
+
# @option options [String] :client_id Strava application client ID (required)
|
|
46
|
+
# @option options [String] :client_secret Strava application client secret (required)
|
|
47
|
+
# @option options [String] :endpoint OAuth endpoint URL (defaults to https://www.strava.com/oauth)
|
|
48
|
+
#
|
|
8
49
|
def initialize(options = {})
|
|
9
50
|
Strava::OAuth::Config::ATTRIBUTES.each do |key|
|
|
10
51
|
send("#{key}=", options[key] || Strava::OAuth.config.send(key))
|
|
@@ -13,20 +54,31 @@ module Strava
|
|
|
13
54
|
end
|
|
14
55
|
|
|
15
56
|
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
# @
|
|
23
|
-
#
|
|
24
|
-
# @option options [
|
|
25
|
-
#
|
|
26
|
-
# @option options [
|
|
27
|
-
#
|
|
57
|
+
# Generate the authorization URL for OAuth flow.
|
|
58
|
+
#
|
|
59
|
+
# Creates a URL to redirect users to for Strava authorization. After the user
|
|
60
|
+
# authorizes your application, they will be redirected back to your redirect_uri
|
|
61
|
+
# with an authorization code.
|
|
62
|
+
#
|
|
63
|
+
# @param [Hash] options Authorization parameters
|
|
64
|
+
# @option options [String] :redirect_uri URL where user is redirected after authorization (default: http://localhost)
|
|
65
|
+
# @option options [String] :response_type Must be 'code' (default: 'code')
|
|
66
|
+
# @option options [String] :approval_prompt 'force' to always show approval page, 'auto' to auto-approve (default: 'auto')
|
|
67
|
+
# @option options [String] :scope Comma-delimited string of permissions (default: 'read')
|
|
68
|
+
# Available scopes: read, read_all, profile:read_all, profile:write, activity:read, activity:read_all, activity:write
|
|
69
|
+
# @option options [String] :state Optional value returned in redirect URI for CSRF protection
|
|
70
|
+
#
|
|
71
|
+
# @return [String] Full authorization URL
|
|
72
|
+
#
|
|
73
|
+
# @example Generate authorization URL
|
|
74
|
+
# url = client.authorize_url(
|
|
75
|
+
# redirect_uri: 'https://myapp.com/callback',
|
|
76
|
+
# scope: 'read,activity:read_all,activity:write',
|
|
77
|
+
# state: 'random_state_value'
|
|
78
|
+
# )
|
|
79
|
+
#
|
|
28
80
|
# @see https://developers.strava.com/docs/authentication/
|
|
29
|
-
#
|
|
81
|
+
#
|
|
30
82
|
def authorize_url(options = {})
|
|
31
83
|
query = options.merge(
|
|
32
84
|
client_id: client_id || raise(ArgumentError, 'Missing Strava client id.'),
|
|
@@ -40,14 +92,33 @@ module Strava
|
|
|
40
92
|
end
|
|
41
93
|
|
|
42
94
|
#
|
|
43
|
-
#
|
|
95
|
+
# Exchange authorization code for access token or refresh an expired token.
|
|
96
|
+
#
|
|
97
|
+
# This method handles two OAuth flows:
|
|
98
|
+
# 1. Initial token exchange: Exchange authorization code for access/refresh tokens
|
|
99
|
+
# 2. Token refresh: Use refresh_token to get new access/refresh tokens
|
|
100
|
+
#
|
|
101
|
+
# @param [Hash] options Token request parameters
|
|
102
|
+
# @option options [String] :code Authorization code from redirect (for initial exchange)
|
|
103
|
+
# @option options [String] :refresh_token Refresh token (for token refresh)
|
|
104
|
+
# @option options [String] :grant_type Grant type: 'authorization_code' (default) or 'refresh_token'
|
|
105
|
+
#
|
|
106
|
+
# @return [Strava::Models::Token] Token object with access_token, refresh_token, expires_at, and athlete
|
|
107
|
+
#
|
|
108
|
+
# @example Exchange authorization code for token
|
|
109
|
+
# token = client.oauth_token(code: 'authorization_code_from_redirect')
|
|
110
|
+
# access_token = token.access_token
|
|
111
|
+
# refresh_token = token.refresh_token
|
|
112
|
+
# expires_at = token.expires_at
|
|
113
|
+
#
|
|
114
|
+
# @example Refresh an expired token
|
|
115
|
+
# new_token = client.oauth_token(
|
|
116
|
+
# refresh_token: 'saved_refresh_token',
|
|
117
|
+
# grant_type: 'refresh_token'
|
|
118
|
+
# )
|
|
44
119
|
#
|
|
45
|
-
# @option options [Object] :code
|
|
46
|
-
# The code parameter obtained in the redirect.
|
|
47
|
-
# @option options [Object] :grant_type
|
|
48
|
-
# The grant type for the request.
|
|
49
120
|
# @see https://developers.strava.com/docs/authentication/
|
|
50
|
-
#
|
|
121
|
+
#
|
|
51
122
|
def oauth_token(options = {})
|
|
52
123
|
query = options.merge(
|
|
53
124
|
client_id: client_id || raise(ArgumentError, 'Missing Strava client id.'),
|
|
@@ -59,10 +130,27 @@ module Strava
|
|
|
59
130
|
end
|
|
60
131
|
|
|
61
132
|
class << self
|
|
133
|
+
#
|
|
134
|
+
# Configure the OAuth client with a block.
|
|
135
|
+
#
|
|
136
|
+
# @yield [Config] Yields the configuration module for setup
|
|
137
|
+
# @return [Module] The Config module
|
|
138
|
+
#
|
|
139
|
+
# @example
|
|
140
|
+
# Strava::OAuth::Client.configure do |config|
|
|
141
|
+
# config.client_id = ENV['STRAVA_CLIENT_ID']
|
|
142
|
+
# config.client_secret = ENV['STRAVA_CLIENT_SECRET']
|
|
143
|
+
# end
|
|
144
|
+
#
|
|
62
145
|
def configure
|
|
63
146
|
block_given? ? yield(Config) : Config
|
|
64
147
|
end
|
|
65
148
|
|
|
149
|
+
#
|
|
150
|
+
# Returns the current OAuth client configuration.
|
|
151
|
+
#
|
|
152
|
+
# @return [Module] The Config module
|
|
153
|
+
#
|
|
66
154
|
def config
|
|
67
155
|
Config
|
|
68
156
|
end
|
data/lib/strava/oauth/config.rb
CHANGED
|
@@ -2,9 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module OAuth
|
|
5
|
+
#
|
|
6
|
+
# Configuration module for the OAuth client.
|
|
7
|
+
#
|
|
8
|
+
# This module manages OAuth-specific configuration settings including the
|
|
9
|
+
# OAuth endpoint URL and application credentials (client ID and secret)
|
|
10
|
+
# required for token exchange and refresh operations.
|
|
11
|
+
#
|
|
12
|
+
# @example Configure OAuth client
|
|
13
|
+
# Strava::OAuth.configure do |config|
|
|
14
|
+
# config.client_id = ENV['STRAVA_CLIENT_ID']
|
|
15
|
+
# config.client_secret = ENV['STRAVA_CLIENT_SECRET']
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# @see https://developers.strava.com/docs/authentication/
|
|
19
|
+
#
|
|
5
20
|
module Config
|
|
6
21
|
extend self
|
|
7
22
|
|
|
23
|
+
# @return [Array<Symbol>] List of configurable OAuth attributes
|
|
8
24
|
ATTRIBUTES = %i[
|
|
9
25
|
endpoint
|
|
10
26
|
client_id
|
|
@@ -13,6 +29,14 @@ module Strava
|
|
|
13
29
|
|
|
14
30
|
attr_accessor(*Config::ATTRIBUTES)
|
|
15
31
|
|
|
32
|
+
#
|
|
33
|
+
# Reset configuration to default values.
|
|
34
|
+
#
|
|
35
|
+
# Sets the endpoint to the default Strava OAuth URL and clears
|
|
36
|
+
# the client credentials.
|
|
37
|
+
#
|
|
38
|
+
# @return [void]
|
|
39
|
+
#
|
|
16
40
|
def reset
|
|
17
41
|
self.endpoint = 'https://www.strava.com/oauth'
|
|
18
42
|
self.client_id = nil
|
|
@@ -21,10 +45,27 @@ module Strava
|
|
|
21
45
|
end
|
|
22
46
|
|
|
23
47
|
class << self
|
|
48
|
+
#
|
|
49
|
+
# Configure the OAuth client with a block.
|
|
50
|
+
#
|
|
51
|
+
# @yield [Config] Yields the configuration module for setup
|
|
52
|
+
# @return [Module] The Config module
|
|
53
|
+
#
|
|
54
|
+
# @example
|
|
55
|
+
# Strava::OAuth.configure do |config|
|
|
56
|
+
# config.client_id = '12345'
|
|
57
|
+
# config.client_secret = 'your_client_secret'
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
24
60
|
def configure
|
|
25
61
|
block_given? ? yield(Config) : Config
|
|
26
62
|
end
|
|
27
63
|
|
|
64
|
+
#
|
|
65
|
+
# Returns the current OAuth configuration.
|
|
66
|
+
#
|
|
67
|
+
# @return [Module] The Config module
|
|
68
|
+
#
|
|
28
69
|
def config
|
|
29
70
|
Config
|
|
30
71
|
end
|