### Install Strava Ruby Client Source: https://context7.com/dblock/strava-ruby-client/llms.txt Instructions for installing the strava-ruby-client gem using Bundler. This involves adding the gem to your Gemfile and running the bundle install command. ```ruby # Gemfile gem 'strava-ruby-client' ``` ```bash bundle install ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/dblock/strava-ruby-client/blob/master/CONTRIBUTING.md Commands to install project dependencies using Bundler and run the test suite to ensure the project builds correctly. ```bash bundle install bundle exec rake ``` -------------------------------- ### Install Dependencies and Run Tests (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/RELEASING.md Installs project dependencies using Bundler and runs the test suite using Rake. This is a crucial step before releasing to ensure the client is stable. ```bash bundle install rake ``` -------------------------------- ### Initialize Strava API Client with Access Token Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Demonstrates how to initialize the Strava API client in Ruby using an access token. The client can then be used to interact with the Strava API, for example, to retrieve the authenticated athlete's details. ```ruby client = Strava::Api::Client.new( access_token: "12345678987654321" ) client.athlete # => Strava::Models::DetailedAthlete ``` -------------------------------- ### Get Activity Photos Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve photos attached to an activity. ```APIDOC ## GET /activities/{id}/photos ### Description Retrieve photos attached to an activity. ### Method GET ### Endpoint `/activities/{id}/photos` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters - **size** (integer) - Optional - The desired size of the photos (e.g., 1920). If not specified, full-size photos are returned. #### Request Body None ### Request Example ```ruby # Get full-size photos photos = client.activity_photos(1982980795) # Get specific size photos = client.activity_photos(1982980795, size: 1920) photos.each do |photo| puts photo.unique_id puts photo.urls # Hash of size => URL puts photo.created_at end ``` ### Response #### Success Response (200) - **photos** (array) - An array of photo objects. - **unique_id** (string) - The unique identifier of the photo. - **urls** (object) - A hash where keys are photo sizes (integers) and values are the corresponding URLs. - **created_at** (datetime) - The date and time the photo was created. #### Response Example ```json [ { "unique_id": "photo123", "urls": { "1920": "http://example.com/photo_1920.jpg", "600": "http://example.com/photo_600.jpg" }, "created_at": "2023-10-27T14:30:00Z" } ] ``` ``` -------------------------------- ### POST /activities Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Creates a manual activity for an athlete. This endpoint allows for the creation of new activities with details such as name, sport type, start time, duration, description, and distance. ```APIDOC ## POST /activities ### Description Creates a manual activity for an athlete. ### Method POST ### Endpoint /activities ### Parameters #### Request Body - **name** (string) - Required - The name of the activity. - **sport_type** (string) - Required - The type of sport (e.g., 'Run', 'Ride'). - **start_date_local** (datetime) - Required - The local start date and time of the activity. - **elapsed_time** (integer) - Required - The total duration of the activity in seconds. - **description** (string) - Optional - A description for the activity. - **distance** (number) - Optional - The distance covered in meters. ### Request Example ```json { "name": "Afternoon Run", "sport_type": "Run", "start_date_local": "2023-10-27T14:00:00Z", "elapsed_time": 1234, "description": "Test run.", "distance": 1000 } ``` ### Response #### Success Response (201 Created) - **activity** (object) - The created detailed activity object. #### Response Example ```json { "id": 1234567890, "name": "Afternoon Run", "strava_url": "https://www.strava.com/activities/1234567890" } ``` ``` -------------------------------- ### GET /athlete/activities Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieves a list of activities for the authenticated athlete, supporting pagination and filtering. ```APIDOC ## GET /athlete/activities ### Description Retrieve a list of activities for the authenticated athlete. Supports pagination, filtering by date, and limiting results. ### Method GET ### Endpoint `/api/v3/athlete/activities` ### Parameters #### Path Parameters None #### Query Parameters - **before** (Integer) - Optional - Unix timestamp to filter activities before this date. - **after** (Integer) - Optional - Unix timestamp to filter activities after this date. - **page** (Integer) - Optional - Page number for pagination. - **per_page** (Integer) - Optional - Number of activities per page (default: 30, max: 200). - **limit** (Integer) - Optional - Total number of activities to return. #### Request Body None ### Request Example ```ruby client = Strava::Api::Client.new(access_token: 'YOUR_ACCESS_TOKEN') # Get recent activities (default: 30) activities = client.athlete_activities # Get with pagination activities = client.athlete_activities(per_page: 50, page: 1) # Get all activities with iteration client.athlete_activities(per_page: 100) do |activity| puts "#{activity.name}: #{activity.distance_s} in #{activity.moving_time_in_hours_s}" end # Filter by date activities = client.athlete_activities( after: Time.now - (7 * 24 * 60 * 60), # Last 7 days before: Time.now, per_page: 50 ) # Limit total results activities = client.athlete_activities(per_page: 30, limit: 100) ``` ### Response #### Success Response (200) - **Array** - An array of activity objects. - **id** (Integer) - Activity's unique identifier. - **name** (String) - Name of the activity. - **distance_s** (String) - Formatted distance string (e.g., "10.5km"). - **moving_time_in_hours_s** (String) - Formatted moving time string (e.g., "1h30m0s"). - ... (other activity details) #### Response Example ```json [ { "id": 123456789, "name": "Morning Run", "distance": 10500.0, "distance_s": "10.5km", "moving_time": 5400, "moving_time_in_hours_s": "1h30m0s", "elapsed_time": 6000, "total_elevation_gain": 50.0, "type": "Run", "sport_type": "Run", "start_date_local": "2024-01-15T08:00:00Z", "utc_offset": -28800, "achievement_count": 1, "kudos_count": 10, "comment_count": 2, "athlete_count": 1, "photo_count": 0, "map": { "id": "", "polyline": "", "resource_state": 2, "summary_polyline": "" }, "trainer": false, "commute": false, "manual": false, "private": false, "visibility": "everyone", "flagged": false, "gear_id": "b12345", "start_date": "2024-01-15T16:00:00Z", "external_id": "garmin_connect_123456789", "from_accepted_tag": false, "upload_id": 1234567890, "workout_type": null } ] ``` ``` -------------------------------- ### Get Route Details Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Retrieves a specific route using its identifier. It returns a Route object, and properties like name and description can be accessed. ```ruby route = client.route(16341573) # => Strava::Models::Route route.name # => 'Lower Manhattan Loop' route.description # => 'My usual long run when I am too lazy to go to Central Park.' ``` -------------------------------- ### Get Activity Comments Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve comments on an activity with cursor-based pagination. ```APIDOC ## GET /activities/{id}/comments ### Description Retrieve comments on an activity with cursor-based pagination. ### Method GET ### Endpoint `/activities/{id}/comments` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters - **page_size** (integer) - Optional - The number of comments to retrieve per page (default is 200). - **before_id** (integer) - Optional - Retrieve comments before this comment ID. - **after_id** (integer) - Optional - Retrieve comments after this comment ID. #### Request Body None ### Request Example ```ruby # Get all comments comments = client.activity_comments(1982980795) # Paginate through comments client.activity_comments(1982980795, page_size: 50) do |comment| puts "#{comment.athlete.username}: #{comment.text}" puts "Posted at: #{comment.created_at}" end ``` ### Response #### Success Response (200) - **comments** (array) - An array of comment objects. - **id** (integer) - The ID of the comment. - **text** (string) - The content of the comment. - **created_at** (datetime) - The date and time the comment was created. - **athlete** (object) - The athlete who posted the comment. - **username** (string) - The username of the athlete. - **firstname** (string) - The first name of the athlete. - **lastname** (string) - The last name of the athlete. #### Response Example ```json [ { "id": 12345, "text": "Great run!", "created_at": "2023-10-27T15:00:00Z", "athlete": { "username": "john_doe", "firstname": "John", "lastname": "Doe" } } ] ``` ``` -------------------------------- ### Handle Strava Webhook Challenge (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md This snippet demonstrates how to handle the initial GET challenge request from Strava webhooks. It verifies the token and sends back the challenge response. Ensure your server is running and accessible at the specified callback URL. ```ruby challenge = Strava::Webhooks::Models::Challenge.new(request.query) raise 'Bad Request' unless challenge.verify_token == 'token' response.content_type = 'application/json' response.body = challenge.response.to_json ``` -------------------------------- ### Create Strava Activity (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Creates a manual activity for a Strava athlete. Requires activity details such as name, sport type, start time, duration, and distance. Returns a DetailedActivity object. ```ruby activity = client.create_activity( name: 'Afternoon Run', sport_type: 'Run', start_date_local: Time.now, elapsed_time: 1234, # in seconds description: 'Test run.', distance: 1000 # in meters ) activity.name # => 'Afternoon Run' activity.strava_url # => 'https://www.strava.com/activities/1982980795' ``` -------------------------------- ### Handle Strava Webhook Challenges and Events in Ruby Source: https://context7.com/dblock/strava-ruby-client/llms.txt Provides Ruby code examples for handling Strava webhook challenges and events within a web application endpoint. This includes validating the `verify_token` for challenges and parsing incoming event data for activities and athletes. ```ruby # Handle Webhook Challenge # In your webhook endpoint (Rails example) def webhook if request.get? challenge = Strava::Webhooks::Models::Challenge.new(request.query_parameters) if challenge.verify_token == ENV['STRAVA_VERIFY_TOKEN'] render json: challenge.response else head :forbidden end end end # Handle Webhook Events # In your webhook endpoint (Rails example) def webhook if request.post? event = Strava::Webhooks::Models::Event.new(JSON.parse(request.body.read)) event.object_type # => "activity" or "athlete" event.id # => 1982980795 (object ID) event.aspect_type # => "create", "update", or "delete" event.updates # => {"title" => "New Title"} (for updates) event.owner_id # => 26462176 (athlete ID) event.subscription_id # => 131300 event.event_time # => Time case event.object_type when 'activity' case event.aspect_type when 'create' process_new_activity(event.id, event.owner_id) when 'update' process_activity_update(event.id, event.updates) when 'delete' process_activity_deletion(event.id) end when 'athlete' # Handle athlete deauthorization handle_athlete_update(event.owner_id, event.updates) end head :ok end end ``` -------------------------------- ### Access Ratelimit Information from API Response (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md This example shows how to access ratelimit details from the HTTP response of a Strava API call. The `#http_response` method on the returned object provides access to the `Strava::Web::ApiResponse` object, which contains ratelimit information. ```ruby comments = client.activity_comments(id: 123_456_789) # comments == Array comments.http_response.ratelimit.to_h ``` ```ruby athlete = client.athlete # => Strava::Models::Athlete athlete.http_response.ratelimit ``` -------------------------------- ### Get Activity Details Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve detailed information about a specific Strava activity, including basic info, metrics, map data, segment efforts, splits, laps, and photos. ```APIDOC ## GET /activities/{id} ### Description Retrieve detailed information about a specific activity. ### Method GET ### Endpoint `/activities/{id}` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```ruby activity = client.activity(1982980795) ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the activity. - **name** (string) - The name of the activity. - **description** (string) - A description of the activity. - **sport_type** (string) - The type of sport (e.g., 'Run', 'Ride'). - **start_date** (datetime) - The start date and time of the activity. - **start_date_local** (datetime) - The start date and time of the activity in the local timezone. - **timezone** (string) - The timezone of the activity. - **distance_s** (string) - The distance of the activity in a human-readable format (e.g., '10.0km'). - **moving_time_in_hours_s** (string) - The moving time of the activity in a human-readable format (e.g., '55m30s'). - **average_heartrate** (float) - The average heart rate during the activity. - **max_heartrate** (float) - The maximum heart rate during the activity. - **average_cadence** (float) - The average cadence during the activity. - **calories** (float) - The number of calories burned during the activity. - **map** (object) - Contains map-related data. - **id** (string) - The ID of the map. - **summary_polyline** (string) - An encoded polyline string for the activity's route. - **polyline** (string) - A detailed encoded polyline string for the activity's route. - **segment_efforts** (array) - An array of segment effort objects. - **splits_metric** (array) - An array of split metric objects. - **laps** (array) - An array of lap objects. - **photos** (array) - An array of photo objects. #### Response Example ```json { "id": 1982980795, "name": "Afternoon Run", "description": "Easy recovery run", "sport_type": "Run", "start_date": "2023-10-27T14:00:00Z", "start_date_local": "2023-10-27T09:00:00-05:00", "timezone": "(GMT-05:00) America/New_York", "distance_s": "10.0km", "moving_time_in_hours_s": "55m30s", "average_heartrate": 145.5, "max_heartrate": 172, "average_cadence": 85.2, "calories": 650, "map": { "id": "a1982980795", "summary_polyline": "encoded_polyline_string", "polyline": "detailed_polyline_string" }, "segment_efforts": [], "splits_metric": [], "laps": [], "photos": [] } ``` ``` -------------------------------- ### Create Manual Activity with Strava Ruby Client Source: https://context7.com/dblock/strava-ruby-client/llms.txt Creates a new manual activity for the authenticated athlete using the Strava Ruby Client. Requires activity details such as name, sport type, start date, elapsed time, and distance. Returns the created activity object with its ID and URL. ```ruby activity = client.create_activity( name: 'Morning Run', sport_type: 'Run', start_date_local: Time.now - 3600, elapsed_time: 3600, # seconds distance: 10000, # meters description: 'Easy morning jog', trainer: false, commute: false ) activity.id # => 1998557443 activity.name # => "Morning Run" activity.strava_url # => "https://www.strava.com/activities/1998557443" ``` -------------------------------- ### GET /activities/{id} Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Returns the given activity that is owned by the authenticated athlete. This endpoint retrieves detailed information about a specific activity. ```APIDOC ## GET /activities/{id} ### Description Returns the given activity that is owned by the authenticated athlete. ### Method GET ### Endpoint /activities/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the activity. ### Response #### Success Response (200 OK) - **activity** (object) - The detailed activity object. #### Response Example ```json { "id": 1982980795, "name": "Afternoon Run", "strava_url": "https://www.strava.com/activities/1982980795" } ``` ``` -------------------------------- ### Access Rate Limiting Information in Strava Ruby Client Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieves and displays rate limit information from Strava API responses. It shows both the limits and current usage for 15-minute and daily intervals. Includes an example of how to catch and handle `Strava::Errors::RatelimitError`. ```ruby athlete = client.athlete # Access rate limit from response ratelimit = athlete.http_response.ratelimit ratelimit.fifteen_minutes # => 600 (15-min limit) ratelimit.fifteen_minutes_usage # => 150 (requests made) ratelimit.fifteen_minutes_remaining # => 450 ratelimit.total_day # => 30000 (daily limit) ratelimit.total_day_usage # => 5000 ratelimit.total_day_remaining # => 25000 ratelimit.to_h # => Full hash of all limits # Handle rate limit exceeded begin activities = client.athlete_activities(per_page: 100) rescue Strava::Errors::RatelimitError => e puts "Rate limited! Try again later." puts "15-min remaining: #{e.ratelimit.fifteen_minutes_remaining}" puts "Daily remaining: #{e.ratelimit.total_day_remaining}" end ``` -------------------------------- ### Get Gear Details (Ruby) Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieves detailed information about an athlete's equipment, such as bikes or shoes, identified by a gear ID. Includes details like name, brand, model, description, frame type, weight, and total distance used. Requires an authenticated client. ```ruby gear = client.gear('b2338517') gear.id # => "b2338517" gear.name # => "Trek Madone" gear.brand_name # => "Trek" gear.model_name # => "Madone" gear.description # => "Carbon road bike" gear.frame_type # => "3" (road bike) gear.weight # => 7.5 (kg) gear.distance # => 380939.0 (meters) gear.distance_s # => "380.94km" gear.primary # => true gear.retired # => false ``` -------------------------------- ### Process Strava Activity Map Data (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Parses an activity's map polyline data to extract start and end points, and constructs URLs for static map images using Google Maps Static API and MapBox Static API. Requires the 'polylines' and 'cgi' gems. ```ruby require 'cgi' require 'polylines' map = activity.map # => Strava::Models::Map decoded_summary_polyline = Polylines::Decoder.decode_polyline(map.summary_polyline) start_latlng = decoded_summary_polyline[0] end_latlng = decoded_summary_polyline[-1] # Google Maps Static API google_maps_api_key = ENV['GOOGLE_STATIC_MAPS_API_KEY'] google_image_url = "https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap&path=enc:#{CGI.escape(map.summary_polyline)}&size=800x800&markers=color:yellow|label:S|#{start_latlng[0]},#{start_latlng[1]}&markers=color:green|label:F|#{end_latlng[0]},#{end_latlng[1]}&key=#{google_maps_api_key}" # MapBox Static API mapbox_access_token = ENV['MAPBOX_ACCESS_TOKEN'] mapbox_image_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-5+787af2-1.0(#{CGI.escape(map.summary_polyline)}),pin-s-s+e5b22e(#{start_latlng[1]},#{start_latlng[0]}),pin-s-f+89ae00(#{end_latlng[1]},#{end_latlng[0]})/auto/800x800?access_token=#{mapbox_access_token}" ``` -------------------------------- ### API Client Initialization Source: https://context7.com/dblock/strava-ruby-client/llms.txt Initializes the API client either with a direct access token or through global configuration. ```APIDOC ## API Client Initialization ### Description Initializes the API client with an access token to make authenticated requests. Configuration can be done directly or globally. ### Method N/A (Client-side initialization) ### Endpoint N/A (Client-side initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby # Initialize with access token client = Strava::Api::Client.new( access_token: ENV['STRAVA_ACCESS_TOKEN'] ) # Or configure globally Strava::Api::Client.configure do |config| config.access_token = ENV['STRAVA_ACCESS_TOKEN'] end client = Strava::Api::Client.new ``` ### Response #### Success Response (200) N/A (Initialization does not return a response) #### Response Example N/A ``` -------------------------------- ### Get Activity Laps Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve lap information for an activity. ```APIDOC ## GET /activities/{id}/laps ### Description Retrieve lap information for an activity. ### Method GET ### Endpoint `/activities/{id}/laps` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters None #### Request Body None ### Request Example ```ruby laps = client.activity_laps(1982980795) laps.each do |lap| puts "#{lap.name}" puts " Distance: #{lap.distance_s}" puts " Time: #{lap.moving_time_in_hours_s}" puts " Avg HR: #{lap.average_heartrate} bpm" puts " Avg Pace: #{lap.pace_s}" end ``` ### Response #### Success Response (200) - **laps** (array) - An array of lap objects. - **name** (string) - The name of the lap. - **distance_s** (string) - The distance of the lap in a human-readable format. - **moving_time_in_hours_s** (string) - The moving time of the lap in a human-readable format. - **average_heartrate** (float) - The average heart rate during the lap. - **pace_s** (string) - The average pace of the lap in a human-readable format. #### Response Example ```json [ { "name": "Lap 1", "distance_s": "1.0km", "moving_time_in_hours_s": "5m30s", "average_heartrate": 140.0, "pace_s": "5m30s/km" } ] ``` ``` -------------------------------- ### GET /athlete Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieves the profile of the currently authenticated athlete. ```APIDOC ## GET /athlete ### Description Retrieve the profile of the currently authenticated athlete. ### Method GET ### Endpoint `/api/v3/athlete` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby client = Strava::Api::Client.new(access_token: 'YOUR_ACCESS_TOKEN') athlete = client.athlete ``` ### Response #### Success Response (200) - **id** (Integer) - Athlete's unique identifier. - **firstname** (String) - Athlete's first name. - **lastname** (String) - Athlete's last name. - **city** (String) - Athlete's city. - **state** (String) - Athlete's state. - **country** (String) - Athlete's country. - **sex** (String) - Athlete's sex. - **premium** (Boolean) - Whether the athlete is a premium member. - **created_at** (Time) - The date and time the athlete account was created. - **profile** (String) - URL to the athlete's profile picture. - **follower_count** (Integer) - The number of followers the athlete has. - **friend_count** (Integer) - The number of friends the athlete has. #### Response Example ```json { "id": 26462176, "firstname": "Daniel", "lastname": "Block", "city": "New York", "state": "NY", "country": "United States", "sex": "M", "premium": true, "created_at": "2016-01-01T12:00:00Z", "profile": "https://example.com/profile.jpg", "follower_count": 150, "friend_count": 200 } ``` ``` -------------------------------- ### Initialize Strava Webhooks Client (Ruby) Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md This snippet shows how to create an instance of the Strava::Webhooks::Client. You need to provide your Strava application's client ID and client secret for authentication when interacting with the Strava API. ```ruby client = Strava::Webhooks::Client.new( client_id: "12345", client_secret: "12345678987654321" ) ``` -------------------------------- ### Get Activity Kudos Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve athletes who gave kudos to an activity. ```APIDOC ## GET /activities/{id}/kudos ### Description Retrieve athletes who gave kudos to an activity. ### Method GET ### Endpoint `/activities/{id}/kudos` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters - **per_page** (integer) - Optional - The number of athletes to retrieve per page (default is 200, max is 200). - **page** (integer) - Optional - The page number to retrieve. #### Request Body None ### Request Example ```ruby kudoers = client.activity_kudos(1982980795, per_page: 100) kudoers.each do |athlete| puts "#{athlete.firstname} #{athlete.lastname} (@#{athlete.username})" end ``` ### Response #### Success Response (200) - **athletes** (array) - An array of athlete objects who gave kudos. - **id** (integer) - The ID of the athlete. - **username** (string) - The username of the athlete. - **firstname** (string) - The first name of the athlete. - **lastname** (string) - The last name of the athlete. #### Response Example ```json [ { "id": 67890, "username": "jane_smith", "firstname": "Jane", "lastname": "Smith" } ] ``` ``` -------------------------------- ### Configure Strava Clients Globally in Ruby Source: https://context7.com/dblock/strava-ruby-client/llms.txt Shows how to configure Strava clients globally for an application. This includes setting user agent, proxy, CA path, logger, and timeouts for the web client, and access token and endpoint for the API client. ```ruby # Web client options (inherited by all clients) Strava::Web::Client.configure do |config| config.user_agent = 'My Strava App/1.0' config.proxy = 'http://proxy.example.com:8080' config.ca_path = '/path/to/certs' config.logger = Logger.new(STDOUT) config.timeout = 30 config.open_timeout = 10 end # API client options Strava::Api::Client.configure do |config| config.access_token = ENV['STRAVA_ACCESS_TOKEN'] config.endpoint = 'https://www.strava.com/api/v3' end ``` -------------------------------- ### Strava API Client Initialization Source: https://context7.com/dblock/strava-ruby-client/llms.txt Shows how to initialize the Strava API client, either by providing an access token directly or by configuring it globally. This client is used to make authenticated requests to the Strava API. ```ruby # Initialize with access token client = Strava::Api::Client.new( access_token: ENV['STRAVA_ACCESS_TOKEN'] ) # Or configure globally Strava::Api::Client.configure do |config| config.access_token = ENV['STRAVA_ACCESS_TOKEN'] end client = Strava::Api::Client.new ``` -------------------------------- ### Create Manual Activity Source: https://context7.com/dblock/strava-ruby-client/llms.txt Create a new manual activity for the authenticated athlete. ```APIDOC ## POST /activities ### Description Create a new manual activity for the authenticated athlete. ### Method POST ### Endpoint `/activities` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - The name of the activity. - **sport_type** (string) - Required - The type of sport (e.g., 'Run', 'Ride'). - **start_date_local** (datetime) - Required - The local start date and time of the activity. - **elapsed_time** (integer) - Required - The total elapsed time in seconds. - **distance** (float) - Required - The distance in meters. - **description** (string) - Optional - A description of the activity. - **trainer** (boolean) - Optional - Whether the activity was performed on a trainer. - **commute** (boolean) - Optional - Whether the activity was a commute. ### Request Example ```ruby activity = client.create_activity( name: 'Morning Run', sport_type: 'Run', start_date_local: Time.now - 3600, elapsed_time: 3600, # seconds distance: 10000, # meters description: 'Easy morning jog', trainer: false, commute: false ) ``` ### Response #### Success Response (201) - **id** (integer) - The unique identifier of the created activity. - **name** (string) - The name of the activity. - **strava_url** (string) - The URL to the activity on Strava. #### Response Example ```json { "id": 1998557443, "name": "Morning Run", "strava_url": "https://www.strava.com/activities/1998557443" } ``` ``` -------------------------------- ### Get Segment Effort Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Returns a segment effort from an activity that is owned by the authenticated athlete. ```APIDOC ## GET /segment_efforts/:id ### Description Returns a segment effort from an activity that is owned by the authenticated athlete. ### Method GET ### Endpoint `/segment_efforts/:id` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the segment effort. #### Query Parameters None #### Request Body None ### Request Example ```ruby client.segment_effort(41494197089) ``` ### Response #### Success Response (200) - **name** (string) - The name of the segment effort. - **activity** (object) - The activity associated with the effort. - **elapsed_time** (integer) - The elapsed time in seconds. - **athlete_segment_stats** (object) - Statistics for the athlete's segment efforts. - **pr_elapsed_time** (integer) - The athlete's personal record elapsed time. - **elapsed_time_in_hours_s** (string) - The elapsed time formatted as a string. - **pr_date** (date) - The date of the athlete's personal record. - **effort_count** (integer) - The total number of efforts by the athlete on this segment. #### Response Example ```json { "name": "E 14th St Climb", "activity": {}, "elapsed_time": 116, "athlete_segment_stats": { "pr_elapsed_time": 116, "elapsed_time_in_hours_s": "1m56s", "pr_date": "2023-10-27", "effort_count": 3 } } ``` ``` -------------------------------- ### Get Activity Zones Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve heart rate and power zone distribution for an activity. ```APIDOC ## GET /activities/{id}/zones ### Description Retrieve heart rate and power zone distribution for an activity. ### Method GET ### Endpoint `/activities/{id}/zones` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters None #### Request Body None ### Request Example ```ruby zones = client.activity_zones(1982980795) zones.each do |zone| puts "Zone type: #{zone.type}" # 'heartrate' or 'power' zone.distribution_buckets.each do |bucket| puts " #{bucket.min}-#{bucket.max}: #{bucket.time}s" end end ``` ### Response #### Success Response (200) - **zones** (array) - An array of zone objects. - **type** (string) - The type of zone ('heartrate' or 'power'). - **distribution_buckets** (array) - An array of distribution bucket objects. - **min** (integer) - The minimum value of the bucket. - **max** (integer) - The maximum value of the bucket. - **time** (integer) - The time spent in the bucket in seconds. #### Response Example ```json [ { "type": "heartrate", "distribution_buckets": [ { "min": 120, "max": 140, "time": 3000 }, { "min": 140, "max": 160, "time": 6000 } ] } ] ``` ``` -------------------------------- ### Manage Webhook Subscriptions with Strava Webhooks Client Source: https://context7.com/dblock/strava-ruby-client/llms.txt Demonstrates how to create, list, and delete webhook subscriptions using the `Strava::Webhooks::Client`. This allows for real-time event notifications. Creating a subscription requires a publicly accessible HTTPS callback URL and a verify token. ```ruby # Create subscription webhooks_client = Strava::Webhooks::Client.new( client_id: ENV['STRAVA_CLIENT_ID'], client_secret: ENV['STRAVA_CLIENT_SECRET'] ) subscription = webhooks_client.create_push_subscription( callback_url: 'https://myapp.com/strava/webhook', verify_token: 'my_secret_verify_token' ) subscription.id # => 131300 subscription.callback_url # => "https://myapp.com/strava/webhook" # List subscriptions subscriptions = webhooks_client.push_subscriptions subscriptions.each do |sub| puts "ID: #{sub.id}" puts "URL: #{sub.callback_url}" end # Delete subscription webhooks_client.delete_push_subscription(131300) ``` -------------------------------- ### OAuth Client Configuration Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Configure OAuth client options, inheriting web client options and adding application-specific settings. Configuration can be global or per client instance. ```APIDOC ## OAuth Client Options The OAuth client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance. ```ruby Strava::OAuth.configure do |config| config.client_id = "..." # Strava client ID config.client_secret = "..." # Strava client secret end ``` ```ruby client = Strava::OAuth::Client.new( client_id: "...", client_secret: "...", user_agent: "..." ) ``` The following settings are supported: | setting | description | | ------------- | ------------------------------------------- | | client_id | Application client ID. | | client_secret | Application client secret. | | endpoint | Defaults to `https://www.strava.com/oauth`. | ``` -------------------------------- ### GET /athlete/zones Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieves the athlete's heart rate and power training zones. ```APIDOC ## GET /athlete/zones ### Description Retrieve the athlete's heart rate and power training zones. ### Method GET ### Endpoint `/api/v3/athlete/zones` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby client = Strava::Api::Client.new(access_token: 'YOUR_ACCESS_TOKEN') zones = client.athlete_zones ``` ### Response #### Success Response (200) - **heart_rate** (Object) - Heart rate zones. - **custom_zones** (Boolean) - Whether custom zones are enabled. - **zones** (Array) - Array of heart rate zone objects. - **min** (Integer) - Minimum heart rate for the zone. - **max** (Integer) - Maximum heart rate for the zone. - **power** (Object) - Power zones (if available). #### Response Example ```json { "heart_rate": { "custom_zones": false, "zones": [ { "min": 0, "max": 123 }, { "min": 123, "max": 153 }, { "min": 153, "max": 169 }, { "min": 169, "max": 184 }, { "min": 184, "max": 220 } ] }, "power": { "zones": [ { "min": 0, "max": 100 }, { "min": 100, "max": 150 }, { "min": 150, "max": 200 }, { "min": 200, "max": 250 }, { "min": 250, "max": 300 }, { "min": 300, "max": 350 } ] } } ``` ``` -------------------------------- ### Webhooks Client Configuration Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Configure Webhooks client options, inheriting web client options and adding application-specific settings. Configuration can be global or per client instance. ```APIDOC ## Webhooks Client Options The Webhooks client inherits web client options and provides additional application configuration. These can be configured globally or for a client instance. ```ruby Strava::Webhooks.configure do |config| config.client_id = "..." # Strava client ID config.client_secret = "..." # Strava client secret end ``` ```ruby client = Strava::Webhooks::Client.new( client_id: "...", client_secret: "...", user_agent: "..." ) ``` The following settings are supported: | setting | description | | ------------- | -------------------------------------------- | | client_id | Application client ID. | | client_secret | Application client secret. | | endpoint | Defaults to `https://www.strava.com/api/v3`. | ``` -------------------------------- ### Web Client Configuration Source: https://github.com/dblock/strava-ruby-client/blob/master/README.md Configure global web client options used in OAuth and API clients. This includes settings for user agent, proxy, SSL certificates, logging, and timeouts. ```APIDOC ## Web Client Options You can configure web client options used in the OAuth and API clients, globally. ```ruby Strava::Web::Client.configure do |config| config.user_agent = 'Strava Ruby Client/3.0' end ``` The following settings are supported: | setting | description | | ------------ | ----------------------------------------------------- | | user_agent | User-agent, defaults to _Strava Ruby Client/version_. | | proxy | Optional HTTP proxy. | | ca_path | Optional SSL certificates path. | | ca_file | Optional SSL certificates file. | | logger | Optional `Logger` instance that logs HTTP requests. | | timeout | Optional open/read timeout in seconds. | | open_timeout | Optional connection open timeout in seconds. | ``` -------------------------------- ### Get Activity Streams Source: https://context7.com/dblock/strava-ruby-client/llms.txt Retrieve time-series data for an activity (GPS, heart rate, power, etc.). ```APIDOC ## GET /activities/{id}/streams ### Description Retrieve time-series data for an activity (GPS, heart rate, power, etc.). ### Method GET ### Endpoint `/activities/{id}/streams` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the activity. #### Query Parameters - **keys** (array of strings) - Required - A comma-separated list of stream types to retrieve (e.g., 'time', 'latlng', 'distance', 'altitude', 'heartrate', 'power'). #### Request Body None ### Request Example ```ruby streams = client.activity_streams(1946417534, keys: %w[time latlng distance altitude heartrate]) ``` ### Response #### Success Response (200) - **streams** (array) - An array of stream objects. - **type** (string) - The type of the stream (e.g., 'time', 'latlng'). - **data** (array) - An array of data points for the stream. - **series_type** (string) - The type of series ('time' or 'distance'). - **original_size** (integer) - The original number of data points. - **resolution** (string) - The resolution of the stream ('auto', 'high', or 'medium'). #### Response Example ```json [ { "type": "time", "data": [ 0, 5, 10, 15 ], "series_type": "time", "original_size": 4, "resolution": "medium" }, { "type": "latlng", "data": [ [37.7749, -122.4194], [37.7750, -122.4195], [37.7751, -122.4196], [37.7752, -122.4197] ], "series_type": "time", "original_size": 4, "resolution": "medium" } ] ``` ```