Skip to content

Instantly share code, notes, and snippets.

@pmargreff
Created January 24, 2023 01:38
Show Gist options
  • Save pmargreff/d234339271ae066b633b3943134d66a8 to your computer and use it in GitHub Desktop.
Save pmargreff/d234339271ae066b633b3943134d66a8 to your computer and use it in GitHub Desktop.
Updating your strava activities to use a given gear
gem 'strava-ruby-client'
require 'strava-ruby-client'
client = Strava::Api::Client.new(
access_token: "access_code"
)
#time interval to update
after = Time.new(2022, 1, 1).to_i
before = Time.new(2023, 1, 1).to_i
gear_id_to_be_replaced = "1"
new_gear_id = "2"
client.athlete_activities(after: after, before: before, per_page: 200) do |activity|
if activity.gear_id == gear_id_to_be_replaced
puts "Starting to update #{activity.id}..."
updated_activity = client.update_activity(
id: activity.id,
gear_id: new_gear_id
)
puts updated_activity
puts "Finished to update #{activity.id}!\n\n"
else
puts "Skipping update for #{activity.id}!\n\n"
end
end
gem 'strava-ruby-client'
require 'strava-ruby-client'
# replace with your app id https://www.strava.com/settings/api
client = Strava::OAuth::Client.new(
client_id: 'client_id',
client_secret: 'client_secret'
)
redirect_url = client.authorize_url(
redirect_uri: 'redirect_url', # strava owned https://developers.strava.com can be used here
approval_prompt: 'force',
response_type: 'code',
scope: 'activity:read_all,activity:write',
state: 'magic'
)
puts redirect_url # enter the url and authorize the application access
response = client.oauth_token(code: 'code') #use the code in the url you were redirected after authorization here
puts response.access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment