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
data/bin/strava-webhooks
CHANGED
|
@@ -11,47 +11,59 @@ logger.level = Logger::INFO
|
|
|
11
11
|
client = Strava::Webhooks::Client.new(
|
|
12
12
|
client_id: ENV.fetch('STRAVA_CLIENT_ID', nil),
|
|
13
13
|
client_secret: ENV.fetch('STRAVA_CLIENT_SECRET', nil),
|
|
14
|
-
logger: logger
|
|
14
|
+
logger: logger,
|
|
15
|
+
log_formatter: Strava::Web::LogFormatter
|
|
15
16
|
)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
client.logger.info "Unsubscribing #{id} ..."
|
|
30
|
-
client.delete_push_subscription(id: id)
|
|
31
|
-
client.logger.info 'Done.'
|
|
32
|
-
when 'handle'
|
|
33
|
-
server = WEBrick::HTTPServer.new(Port: 4242)
|
|
34
|
-
|
|
35
|
-
trap 'INT' do
|
|
36
|
-
server.shutdown
|
|
37
|
-
end
|
|
18
|
+
begin
|
|
19
|
+
case ARGV[0]
|
|
20
|
+
when 'create'
|
|
21
|
+
callback_url = ARGV[1]
|
|
22
|
+
raise 'Missing callback_url.' unless callback_url
|
|
23
|
+
|
|
24
|
+
client.logger.info "Subscribing to #{callback_url} ..."
|
|
25
|
+
subscription = client.create_push_subscription(callback_url: callback_url, verify_token: 'token')
|
|
26
|
+
puts subscription
|
|
27
|
+
when 'delete'
|
|
28
|
+
id = ARGV[1]
|
|
29
|
+
raise 'Missing id.' unless id
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
client.logger.info "Unsubscribing #{id} ..."
|
|
32
|
+
client.delete_push_subscription(id: id)
|
|
33
|
+
client.logger.info 'Done.'
|
|
34
|
+
when 'handle'
|
|
35
|
+
server = WEBrick::HTTPServer.new(Port: Integer(ENV.fetch('PORT', 4242)))
|
|
36
|
+
|
|
37
|
+
trap 'INT' do
|
|
38
|
+
server.shutdown
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
server.mount_proc '/' do |req, res|
|
|
42
|
+
case req.request_method
|
|
43
|
+
when 'GET'
|
|
44
|
+
challenge = Strava::Webhooks::Models::Challenge.new(req.query)
|
|
45
|
+
res.content_type = 'application/json'
|
|
46
|
+
res.body = challenge.response.to_json
|
|
47
|
+
when 'POST'
|
|
48
|
+
event = Strava::Webhooks::Models::Event.new(JSON.parse(req.body))
|
|
49
|
+
server.logger.info event
|
|
50
|
+
server.logger.info req.body
|
|
51
|
+
res.content_type = 'application/json'
|
|
52
|
+
res.body = { ok: true }.to_json
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
server.start
|
|
56
|
+
else
|
|
57
|
+
client.push_subscriptions.each do |s|
|
|
58
|
+
puts s
|
|
50
59
|
end
|
|
51
60
|
end
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
rescue Faraday::Error => e
|
|
62
|
+
# Display only the response body, since request URLs may include client_secret.
|
|
63
|
+
body = e.response&.dig(:body)
|
|
64
|
+
body = {} unless body.is_a?(Hash)
|
|
65
|
+
message = body['message'] || "Request failed with status #{e.response&.dig(:status) || 'unknown'}"
|
|
66
|
+
reasons = Array(body['errors']).map { |error| error.values_at('resource', 'field', 'code').reject { |v| v.to_s.empty? }.join(' ') }
|
|
67
|
+
warn reasons.empty? ? "#{message}." : "#{message}: #{reasons.join(', ')}."
|
|
68
|
+
exit 1
|
|
57
69
|
end
|
data/lib/strava/api/client.rb
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Api
|
|
5
|
+
#
|
|
6
|
+
# Main API client for interacting with the Strava API v3.
|
|
7
|
+
#
|
|
8
|
+
# This class provides a complete Ruby interface to the Strava API, including support for:
|
|
9
|
+
# * Activities (create, read, update, list)
|
|
10
|
+
# * Athletes (profile, stats, zones)
|
|
11
|
+
# * Clubs (details, members, activities)
|
|
12
|
+
# * Gear (equipment details)
|
|
13
|
+
# * Routes (details, GPX/TCX export)
|
|
14
|
+
# * Segments and Segment Efforts
|
|
15
|
+
# * Streams (activity, route, segment data)
|
|
16
|
+
# * Uploads (activity file uploads)
|
|
17
|
+
# * OAuth (token refresh, deauthorization)
|
|
18
|
+
#
|
|
19
|
+
# @example Create a client with an access token
|
|
20
|
+
# client = Strava::Api::Client.new(access_token: "your_access_token")
|
|
21
|
+
# athlete = client.athlete
|
|
22
|
+
# activities = client.athlete_activities(per_page: 10)
|
|
23
|
+
#
|
|
24
|
+
# @example Configure globally
|
|
25
|
+
# Strava::Api::Client.configure do |config|
|
|
26
|
+
# config.access_token = "your_access_token"
|
|
27
|
+
# end
|
|
28
|
+
# client = Strava::Api::Client.new
|
|
29
|
+
#
|
|
30
|
+
# @see https://developers.strava.com/docs/reference/ Strava API Documentation
|
|
31
|
+
#
|
|
5
32
|
class Client < Strava::Web::Client
|
|
6
33
|
include Endpoints::Activities
|
|
7
34
|
include Endpoints::Athletes
|
|
@@ -16,6 +43,26 @@ module Strava
|
|
|
16
43
|
|
|
17
44
|
attr_accessor(*Config::ATTRIBUTES)
|
|
18
45
|
|
|
46
|
+
#
|
|
47
|
+
# Initialize a new API client.
|
|
48
|
+
#
|
|
49
|
+
# @param [Hash] options Configuration options for the client
|
|
50
|
+
# @option options [String] :access_token OAuth access token for API authentication (required)
|
|
51
|
+
# @option options [String] :endpoint API endpoint URL (defaults to https://www.strava.com/api/v3)
|
|
52
|
+
# @option options [String] :user_agent User agent string for HTTP requests
|
|
53
|
+
# @option options [Logger] :logger Logger instance for request/response logging
|
|
54
|
+
# @option options [Integer] :timeout HTTP request timeout in seconds
|
|
55
|
+
# @option options [Integer] :open_timeout HTTP connection timeout in seconds
|
|
56
|
+
# @option options [String] :proxy HTTP proxy URL
|
|
57
|
+
# @option options [String] :ca_path Path to SSL CA certificates
|
|
58
|
+
# @option options [String] :ca_file Path to SSL CA certificate file
|
|
59
|
+
#
|
|
60
|
+
# @example
|
|
61
|
+
# client = Strava::Api::Client.new(
|
|
62
|
+
# access_token: "your_access_token",
|
|
63
|
+
# user_agent: "My Strava App/1.0"
|
|
64
|
+
# )
|
|
65
|
+
#
|
|
19
66
|
def initialize(options = {})
|
|
20
67
|
Config::ATTRIBUTES.each do |key|
|
|
21
68
|
send("#{key}=", options[key] || Strava::Api.config.send(key))
|
|
@@ -23,15 +70,37 @@ module Strava
|
|
|
23
70
|
super
|
|
24
71
|
end
|
|
25
72
|
|
|
73
|
+
#
|
|
74
|
+
# Returns HTTP headers for API requests.
|
|
75
|
+
#
|
|
76
|
+
# @return [Hash] Headers including OAuth bearer token authorization
|
|
77
|
+
# @api private
|
|
78
|
+
#
|
|
26
79
|
def headers
|
|
27
80
|
{ 'Authorization' => "Bearer #{access_token}" }
|
|
28
81
|
end
|
|
29
82
|
|
|
30
83
|
class << self
|
|
84
|
+
#
|
|
85
|
+
# Configure the API client globally.
|
|
86
|
+
#
|
|
87
|
+
# @yield [Config] Configuration object
|
|
88
|
+
# @return [Strava::Api::Config] Configuration object
|
|
89
|
+
#
|
|
90
|
+
# @example
|
|
91
|
+
# Strava::Api::Client.configure do |config|
|
|
92
|
+
# config.access_token = "your_access_token"
|
|
93
|
+
# end
|
|
94
|
+
#
|
|
31
95
|
def configure
|
|
32
96
|
block_given? ? yield(Config) : Config
|
|
33
97
|
end
|
|
34
98
|
|
|
99
|
+
#
|
|
100
|
+
# Returns the configuration object.
|
|
101
|
+
#
|
|
102
|
+
# @return [Strava::Api::Config] Configuration object
|
|
103
|
+
#
|
|
35
104
|
def config
|
|
36
105
|
Config
|
|
37
106
|
end
|
data/lib/strava/api/config.rb
CHANGED
|
@@ -2,9 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Api
|
|
5
|
+
#
|
|
6
|
+
# Configuration module for the Strava API client.
|
|
7
|
+
#
|
|
8
|
+
# This module manages configuration settings for the API client, including
|
|
9
|
+
# the API endpoint URL and access token for authentication.
|
|
10
|
+
#
|
|
11
|
+
# @example Configure the API client
|
|
12
|
+
# Strava::Api.configure do |config|
|
|
13
|
+
# config.access_token = 'your_access_token_here'
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# @example Access current configuration
|
|
17
|
+
# Strava::Api.config.endpoint
|
|
18
|
+
# # => 'https://www.strava.com/api/v3'
|
|
19
|
+
#
|
|
5
20
|
module Config
|
|
6
21
|
extend self
|
|
7
22
|
|
|
23
|
+
# @return [Array<Symbol>] List of configurable attributes
|
|
8
24
|
ATTRIBUTES = %i[
|
|
9
25
|
endpoint
|
|
10
26
|
access_token
|
|
@@ -12,6 +28,14 @@ module Strava
|
|
|
12
28
|
|
|
13
29
|
attr_accessor(*Config::ATTRIBUTES)
|
|
14
30
|
|
|
31
|
+
#
|
|
32
|
+
# Reset configuration to default values.
|
|
33
|
+
#
|
|
34
|
+
# Sets the endpoint to the default Strava API v3 URL and
|
|
35
|
+
# clears the access token.
|
|
36
|
+
#
|
|
37
|
+
# @return [void]
|
|
38
|
+
#
|
|
15
39
|
def reset
|
|
16
40
|
self.endpoint = 'https://www.strava.com/api/v3'
|
|
17
41
|
self.access_token = nil
|
|
@@ -19,10 +43,26 @@ module Strava
|
|
|
19
43
|
end
|
|
20
44
|
|
|
21
45
|
class << self
|
|
46
|
+
#
|
|
47
|
+
# Configure the API client with a block.
|
|
48
|
+
#
|
|
49
|
+
# @yield [Config] Yields the configuration module for setup
|
|
50
|
+
# @return [Module] The Config module
|
|
51
|
+
#
|
|
52
|
+
# @example
|
|
53
|
+
# Strava::Api.configure do |config|
|
|
54
|
+
# config.access_token = ENV['STRAVA_ACCESS_TOKEN']
|
|
55
|
+
# end
|
|
56
|
+
#
|
|
22
57
|
def configure
|
|
23
58
|
block_given? ? yield(Config) : Config
|
|
24
59
|
end
|
|
25
60
|
|
|
61
|
+
#
|
|
62
|
+
# Returns the current API configuration.
|
|
63
|
+
#
|
|
64
|
+
# @return [Module] The Config module
|
|
65
|
+
#
|
|
26
66
|
def config
|
|
27
67
|
Config
|
|
28
68
|
end
|
data/lib/strava/api/cursor.rb
CHANGED
|
@@ -2,11 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Api
|
|
5
|
+
#
|
|
6
|
+
# Handles paginated iteration through API endpoints.
|
|
7
|
+
#
|
|
8
|
+
# This class provides an Enumerable interface for iterating through
|
|
9
|
+
# paginated API responses. It supports both traditional page-based
|
|
10
|
+
# pagination and cursor-based pagination.
|
|
11
|
+
#
|
|
12
|
+
# @see Strava::Api::Pagination
|
|
13
|
+
#
|
|
14
|
+
# @example Iterating through pages
|
|
15
|
+
# cursor = Strava::Api::Cursor.new(client, 'athlete/activities', per_page: 30)
|
|
16
|
+
# cursor.each do |page|
|
|
17
|
+
# page.each do |activity|
|
|
18
|
+
# puts activity.name
|
|
19
|
+
# end
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
5
22
|
class Cursor
|
|
6
23
|
include Enumerable
|
|
7
24
|
|
|
8
|
-
|
|
25
|
+
# @return [Strava::Api::Client] API client instance
|
|
26
|
+
attr_reader :client
|
|
9
27
|
|
|
28
|
+
# @return [String] API endpoint path
|
|
29
|
+
attr_reader :path
|
|
30
|
+
|
|
31
|
+
# @return [Hash] Query parameters for the request
|
|
32
|
+
attr_reader :params
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# Initialize a new Cursor for paginated iteration.
|
|
36
|
+
#
|
|
37
|
+
# @param client [Strava::Api::Client] API client to use for requests
|
|
38
|
+
# @param path [String] API endpoint path to paginate
|
|
39
|
+
# @param params [Hash] Query parameters (excluding :limit which is removed)
|
|
40
|
+
#
|
|
10
41
|
def initialize(client, path, params = {})
|
|
11
42
|
@client = client
|
|
12
43
|
@path = path
|
|
@@ -3,19 +3,70 @@
|
|
|
3
3
|
module Strava
|
|
4
4
|
module Api
|
|
5
5
|
module Endpoints
|
|
6
|
+
#
|
|
7
|
+
# API endpoints for Strava activities.
|
|
8
|
+
#
|
|
9
|
+
# Activities represent workouts, rides, runs, and other athletic pursuits recorded on Strava.
|
|
10
|
+
# This module provides methods for creating, retrieving, updating, and listing activities,
|
|
11
|
+
# as well as accessing related data like comments, kudos, laps, and zones.
|
|
12
|
+
#
|
|
13
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities
|
|
14
|
+
#
|
|
6
15
|
module Activities
|
|
7
16
|
#
|
|
8
|
-
# Create
|
|
17
|
+
# Create a manual activity.
|
|
18
|
+
#
|
|
19
|
+
# Creates a new manual activity for an athlete. Requires write access.
|
|
20
|
+
#
|
|
21
|
+
# @param [Hash] options Activity attributes
|
|
22
|
+
# @option options [String] :name Activity name (required)
|
|
23
|
+
# @option options [String] :sport_type Activity type (required, e.g., 'Run', 'Ride', 'Swim')
|
|
24
|
+
# @option options [Time, String] :start_date_local Local start date and time (required)
|
|
25
|
+
# @option options [Integer] :elapsed_time Activity duration in seconds (required)
|
|
26
|
+
# @option options [String] :description Activity description
|
|
27
|
+
# @option options [Float] :distance Distance in meters
|
|
28
|
+
# @option options [Boolean] :trainer Whether activity was on a trainer
|
|
29
|
+
# @option options [Boolean] :commute Whether activity was a commute
|
|
30
|
+
#
|
|
31
|
+
# @return [Strava::Models::DetailedActivity] The created activity
|
|
32
|
+
#
|
|
33
|
+
# @example
|
|
34
|
+
# activity = client.create_activity(
|
|
35
|
+
# name: 'Morning Run',
|
|
36
|
+
# sport_type: 'Run',
|
|
37
|
+
# start_date_local: Time.now,
|
|
38
|
+
# elapsed_time: 3600,
|
|
39
|
+
# distance: 10000,
|
|
40
|
+
# description: 'Easy recovery run'
|
|
41
|
+
# )
|
|
42
|
+
#
|
|
43
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-createActivity
|
|
9
44
|
#
|
|
10
45
|
def create_activity(options = {})
|
|
11
46
|
Strava::Models::DetailedActivity.new(post('activities', options))
|
|
12
47
|
end
|
|
13
48
|
|
|
14
49
|
#
|
|
15
|
-
# Get activity.
|
|
50
|
+
# Get detailed information about a specific activity.
|
|
51
|
+
#
|
|
52
|
+
# Returns the given activity that is owned by the authenticated athlete.
|
|
53
|
+
# Includes all activity details such as splits, laps, segment efforts, and photos.
|
|
16
54
|
#
|
|
17
|
-
# @
|
|
18
|
-
#
|
|
55
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
56
|
+
# @param [Hash] options Additional options
|
|
57
|
+
# @option options [Boolean] :include_all_efforts Include all segment efforts
|
|
58
|
+
#
|
|
59
|
+
# @return [Strava::Models::DetailedActivity] The activity
|
|
60
|
+
#
|
|
61
|
+
# @example Get activity by ID
|
|
62
|
+
# activity = client.activity(1234567890)
|
|
63
|
+
# puts activity.name
|
|
64
|
+
# puts activity.distance_s
|
|
65
|
+
#
|
|
66
|
+
# @example Get activity with options hash
|
|
67
|
+
# activity = client.activity(id: 1234567890, include_all_efforts: true)
|
|
68
|
+
#
|
|
69
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getActivityById
|
|
19
70
|
#
|
|
20
71
|
def activity(id_or_options, options = {})
|
|
21
72
|
id, options = parse_args(id_or_options, options)
|
|
@@ -23,17 +74,29 @@ module Strava
|
|
|
23
74
|
end
|
|
24
75
|
|
|
25
76
|
#
|
|
26
|
-
# List activity
|
|
77
|
+
# List comments for an activity.
|
|
78
|
+
#
|
|
79
|
+
# Returns the comments on the given activity. Supports cursor-based pagination.
|
|
27
80
|
#
|
|
28
|
-
# @
|
|
29
|
-
#
|
|
30
|
-
# @option options [Integer] :page
|
|
31
|
-
#
|
|
32
|
-
# @option options [Integer] :
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
81
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
82
|
+
# @param [Hash] options Pagination options
|
|
83
|
+
# @option options [Integer] :page_size Number of items per page (default: 30)
|
|
84
|
+
# @option options [String] :after_cursor Cursor for pagination
|
|
85
|
+
# @option options [Integer] :limit Maximum number of items to return
|
|
86
|
+
# @option options [Integer] :per_page (Deprecated) Use :page_size instead
|
|
87
|
+
#
|
|
88
|
+
# @yield [Strava::Models::Comment] Yields each comment if block given
|
|
89
|
+
# @return [Array<Strava::Models::Comment>] Array of comments
|
|
90
|
+
#
|
|
91
|
+
# @example Get all comments
|
|
92
|
+
# comments = client.activity_comments(1234567890)
|
|
93
|
+
#
|
|
94
|
+
# @example Paginate through comments
|
|
95
|
+
# client.activity_comments(1234567890, page_size: 50) do |comment|
|
|
96
|
+
# puts "#{comment.athlete.username}: #{comment.text}"
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getCommentsByActivityId
|
|
37
100
|
#
|
|
38
101
|
def activity_comments(id_or_options, options = {}, &block)
|
|
39
102
|
id, options = parse_args(id_or_options, options)
|
|
@@ -41,14 +104,26 @@ module Strava
|
|
|
41
104
|
end
|
|
42
105
|
|
|
43
106
|
#
|
|
44
|
-
# List activity
|
|
107
|
+
# List photos for an activity.
|
|
108
|
+
#
|
|
109
|
+
# Returns the photos on the given activity. This is an undocumented Strava API endpoint.
|
|
110
|
+
# By default, retrieves full-size photos (5000px).
|
|
45
111
|
#
|
|
46
|
-
# @
|
|
47
|
-
#
|
|
48
|
-
# @option options [Integer] :
|
|
49
|
-
#
|
|
50
|
-
# @option options [Integer] :per_page
|
|
51
|
-
#
|
|
112
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
113
|
+
# @param [Hash] options Pagination options
|
|
114
|
+
# @option options [Integer] :size Photo size in pixels (default: 5000 for full size)
|
|
115
|
+
# @option options [Integer] :page Page number
|
|
116
|
+
# @option options [Integer] :per_page Number of items per page (default: 30)
|
|
117
|
+
#
|
|
118
|
+
# @yield [Strava::Models::DetailedPhoto] Yields each photo if block given
|
|
119
|
+
# @return [Array<Strava::Models::DetailedPhoto>] Array of photos
|
|
120
|
+
#
|
|
121
|
+
# @example Get all photos
|
|
122
|
+
# photos = client.activity_photos(1234567890)
|
|
123
|
+
# photos.each { |photo| puts photo.urls }
|
|
124
|
+
#
|
|
125
|
+
# @example Get specific size
|
|
126
|
+
# photos = client.activity_photos(1234567890, size: 1920)
|
|
52
127
|
#
|
|
53
128
|
def activity_photos(id_or_options, options = {}, &block)
|
|
54
129
|
id, options = parse_args(id_or_options, options)
|
|
@@ -57,14 +132,23 @@ module Strava
|
|
|
57
132
|
end
|
|
58
133
|
|
|
59
134
|
#
|
|
60
|
-
# List activity
|
|
135
|
+
# List athletes who kudoed an activity.
|
|
136
|
+
#
|
|
137
|
+
# Returns the athletes who kudoed an activity identified by an identifier.
|
|
138
|
+
#
|
|
139
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
140
|
+
# @param [Hash] options Pagination options
|
|
141
|
+
# @option options [Integer] :page Page number
|
|
142
|
+
# @option options [Integer] :per_page Number of items per page (default: 30)
|
|
61
143
|
#
|
|
62
|
-
# @
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
144
|
+
# @yield [Strava::Models::SummaryAthlete] Yields each athlete if block given
|
|
145
|
+
# @return [Array<Strava::Models::SummaryAthlete>] Array of athletes
|
|
146
|
+
#
|
|
147
|
+
# @example Get all kudoers
|
|
148
|
+
# kudoers = client.activity_kudos(1234567890)
|
|
149
|
+
# kudoers.each { |athlete| puts athlete.username }
|
|
150
|
+
#
|
|
151
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getKudoersByActivityId
|
|
68
152
|
#
|
|
69
153
|
def activity_kudos(id_or_options, options = {}, &block)
|
|
70
154
|
id, options = parse_args(id_or_options, options)
|
|
@@ -72,10 +156,21 @@ module Strava
|
|
|
72
156
|
end
|
|
73
157
|
|
|
74
158
|
#
|
|
75
|
-
#
|
|
159
|
+
# List laps for an activity.
|
|
160
|
+
#
|
|
161
|
+
# Returns the laps of an activity identified by an identifier.
|
|
162
|
+
# Laps are split segments either created manually or auto-generated.
|
|
163
|
+
#
|
|
164
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
165
|
+
# @param [Hash] options Additional options
|
|
166
|
+
#
|
|
167
|
+
# @return [Array<Strava::Models::Lap>] Array of laps
|
|
168
|
+
#
|
|
169
|
+
# @example Get activity laps
|
|
170
|
+
# laps = client.activity_laps(1234567890)
|
|
171
|
+
# laps.each { |lap| puts "#{lap.name}: #{lap.distance_s}" }
|
|
76
172
|
#
|
|
77
|
-
# @
|
|
78
|
-
# Activity id.
|
|
173
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getLapsByActivityId
|
|
79
174
|
#
|
|
80
175
|
def activity_laps(id_or_options, options = {})
|
|
81
176
|
id, options = parse_args(id_or_options, options)
|
|
@@ -85,16 +180,36 @@ module Strava
|
|
|
85
180
|
end
|
|
86
181
|
|
|
87
182
|
#
|
|
88
|
-
# List
|
|
183
|
+
# List activities for the authenticated athlete.
|
|
184
|
+
#
|
|
185
|
+
# Returns the currently logged-in athlete's activities. Supports pagination and time-based filtering.
|
|
186
|
+
# Activities are returned in descending order by start date.
|
|
187
|
+
#
|
|
188
|
+
# @param [Hash] options Pagination and filtering options
|
|
189
|
+
# @option options [Time, Integer] :before Epoch timestamp or Time object for filtering activities before this time
|
|
190
|
+
# @option options [Time, Integer] :after Epoch timestamp or Time object for filtering activities after this time
|
|
191
|
+
# @option options [Integer] :page Page number
|
|
192
|
+
# @option options [Integer] :per_page Number of items per page (default: 30)
|
|
193
|
+
# @option options [Integer] :limit Maximum number of items to return
|
|
194
|
+
#
|
|
195
|
+
# @yield [Strava::Models::SummaryActivity] Yields each activity if block given
|
|
196
|
+
# @return [Array<Strava::Models::SummaryActivity>] Array of activities
|
|
197
|
+
#
|
|
198
|
+
# @example Get recent activities
|
|
199
|
+
# activities = client.athlete_activities(per_page: 10)
|
|
200
|
+
#
|
|
201
|
+
# @example Get activities with time filter
|
|
202
|
+
# activities = client.athlete_activities(
|
|
203
|
+
# after: Time.now - 7.days,
|
|
204
|
+
# per_page: 50
|
|
205
|
+
# )
|
|
89
206
|
#
|
|
90
|
-
# @
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
# @option options [Integer] :per_page
|
|
97
|
-
# Number of items per page. Defaults to 30.
|
|
207
|
+
# @example Paginate through all activities
|
|
208
|
+
# client.athlete_activities(per_page: 100) do |activity|
|
|
209
|
+
# puts "#{activity.name}: #{activity.distance_s}"
|
|
210
|
+
# end
|
|
211
|
+
#
|
|
212
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getLoggedInAthleteActivities
|
|
98
213
|
#
|
|
99
214
|
def athlete_activities(options = {}, &block)
|
|
100
215
|
options = options.dup if options.key?(:after) || options.key?(:before)
|
|
@@ -104,10 +219,24 @@ module Strava
|
|
|
104
219
|
end
|
|
105
220
|
|
|
106
221
|
#
|
|
107
|
-
# Get activity
|
|
222
|
+
# Get zones for an activity.
|
|
223
|
+
#
|
|
224
|
+
# Returns the zones of a given activity. Summit feature required.
|
|
225
|
+
# Zones include heart rate and power zones with distribution buckets.
|
|
226
|
+
#
|
|
227
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
228
|
+
# @param [Hash] options Additional options
|
|
229
|
+
#
|
|
230
|
+
# @return [Array<Strava::Models::ActivityZone>] Array of activity zones
|
|
231
|
+
#
|
|
232
|
+
# @example Get activity zones
|
|
233
|
+
# zones = client.activity_zones(1234567890)
|
|
234
|
+
# zones.each do |zone|
|
|
235
|
+
# puts "Type: #{zone.type}"
|
|
236
|
+
# zone.distribution_buckets.each { |bucket| puts "#{bucket.min}-#{bucket.max}: #{bucket.time}s" }
|
|
237
|
+
# end
|
|
108
238
|
#
|
|
109
|
-
# @
|
|
110
|
-
# Activity id.
|
|
239
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-getZonesByActivityId
|
|
111
240
|
#
|
|
112
241
|
def activity_zones(id_or_options, options = {})
|
|
113
242
|
id, options = parse_args(id_or_options, options)
|
|
@@ -119,20 +248,31 @@ module Strava
|
|
|
119
248
|
#
|
|
120
249
|
# Update an activity.
|
|
121
250
|
#
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
-
#
|
|
125
|
-
#
|
|
126
|
-
# @
|
|
127
|
-
#
|
|
128
|
-
# @option options [
|
|
129
|
-
#
|
|
130
|
-
# @option options [String] :name
|
|
131
|
-
#
|
|
132
|
-
# @option options [String] :
|
|
133
|
-
#
|
|
134
|
-
# @
|
|
135
|
-
#
|
|
251
|
+
# Updates the given activity that is owned by the authenticated athlete.
|
|
252
|
+
# Requires write access.
|
|
253
|
+
#
|
|
254
|
+
# @param [Integer, Hash] id_or_options Activity ID or options hash with :id key
|
|
255
|
+
# @param [Hash] options Activity attributes to update
|
|
256
|
+
# @option options [Boolean] :commute Whether this activity is a commute
|
|
257
|
+
# @option options [Boolean] :trainer Whether this activity was recorded on a training machine
|
|
258
|
+
# @option options [String] :description Activity description
|
|
259
|
+
# @option options [String] :name Activity name
|
|
260
|
+
# @option options [String] :sport_type Activity type (e.g., 'Run', 'Ride')
|
|
261
|
+
# @option options [String] :gear_id Equipment ID (specify "none" to clear gear)
|
|
262
|
+
#
|
|
263
|
+
# @return [Strava::Models::DetailedActivity] The updated activity
|
|
264
|
+
#
|
|
265
|
+
# @example Update activity name and description
|
|
266
|
+
# activity = client.update_activity(
|
|
267
|
+
# id: 1234567890,
|
|
268
|
+
# name: 'Updated Activity Name',
|
|
269
|
+
# description: 'New description'
|
|
270
|
+
# )
|
|
271
|
+
#
|
|
272
|
+
# @example Mark as commute
|
|
273
|
+
# activity = client.update_activity(1234567890, commute: true)
|
|
274
|
+
#
|
|
275
|
+
# @see https://developers.strava.com/docs/reference/#api-Activities-updateActivityById
|
|
136
276
|
#
|
|
137
277
|
def update_activity(id_or_options, options = {})
|
|
138
278
|
id, options = parse_args(id_or_options, options)
|