Skip to content

Instantly share code, notes, and snippets.

@justinramel
Created October 31, 2012 23:18
Show Gist options
  • Save justinramel/3990574 to your computer and use it in GitHub Desktop.
Save justinramel/3990574 to your computer and use it in GitHub Desktop.
strava yellow jersey proof of concept
require 'faraday'
class StravaGateway
def self.get_athlete(id)
response = Faraday.get("http://www.strava.com/athletes/#{id}")
body = response.body
name = body.slice(/<h1 class='topless' id='athlete-name'>(.+?)</, 1)
miles = body.slice(/<strong>(.+?)<abbr class='unit' title='miles'>/, 1)
hours = body.slice(/<strong>(.+?)<abbr class='unit' title='hours'>/, 1)
minutes = body.slice(/abbr>(.+?)<abbr class='unit' title='minutes'>/, 1)
feet = body.slice(/<strong>(.+?)<abbr class='unit' title='feet'>/, 1)
Athlete.new.tap do |a|
a.name = name
a.miles = miles
a.hours = hours
a.minutes = minutes
a.feet = feet
end
end
end
class Athlete
attr_accessor :name, :miles, :hours, :minutes, :feet
def to_s
"#{name}\t#{miles}mi\t#{hours}hr#{minutes}m\t#{feet}ft"
end
end
justin = StravaGateway.get_athlete(1108047)
robin = StravaGateway.get_athlete(1193339)
puts justin
puts robin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment