Class: Strava::Athlete
Overview
Strava Athlete class. For the most part, API interaction deals with the currently authenticated athlete.
There are mixins available to provide convenient ways to instantiate an athlete, see model for more information.
Usage:
ca = Strava::Athlete.current_athlete(access_token)
ca.firstname # => 'John'
ca.lastname # => 'Applestrava'
ca.profile # => 'http://pics.com/227615/large.jpg'
Instance Attribute Summary collapse
-
#athlete_type ⇒ Object
readonly
Returns the value of attribute athlete_type.
-
#bikes ⇒ Object
readonly
Returns the value of attribute bikes.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#date_preference ⇒ Object
readonly
Returns the value of attribute date_preference.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#firstname ⇒ Object
readonly
Returns the value of attribute firstname.
-
#follower ⇒ Object
readonly
Returns the value of attribute follower.
-
#follower_count ⇒ Object
readonly
Returns the value of attribute follower_count.
-
#friend ⇒ Object
readonly
Returns the value of attribute friend.
-
#friend_count ⇒ Object
readonly
Returns the value of attribute friend_count.
-
#ftp ⇒ Object
readonly
Returns the value of attribute ftp.
-
#lastname ⇒ Object
readonly
Returns the value of attribute lastname.
-
#measurement_preference ⇒ Object
readonly
Returns the value of attribute measurement_preference.
-
#mutual_friend_count ⇒ Object
readonly
Returns the value of attribute mutual_friend_count.
-
#premium ⇒ Object
readonly
Returns the value of attribute premium.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#profile_medium ⇒ Object
readonly
Returns the value of attribute profile_medium.
-
#sex ⇒ Object
readonly
Returns the value of attribute sex.
-
#shoes ⇒ Object
readonly
Returns the value of attribute shoes.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Attributes inherited from Base
Class Method Summary collapse
-
.current_athlete(token = "ca16caf5b4cb8b57016541f470ae6b3a8aea2252") ⇒ Athlete
Retrieve the currently authenticated athlete.
Instance Method Summary collapse
-
#activities(per_page: nil, page: nil) ⇒ Object
Activities belonging to this user.
- #both_following(other_athlete, per_page: nil, page: nil) ⇒ Object
- #clubs ⇒ Object
-
#current? ⇒ Boolean
Whether this is the currently authenticated athlete.
- #followers(per_page: nil, page: nil) ⇒ Object
- #friends(per_page: nil, page: nil) ⇒ Object
-
#friends_activities(per_page: nil, page: nil, before: nil) ⇒ Object
not working, not listed in docs def heatmaps(per_page: nil, page: nil) if page || per_page get_heatmaps(per_page: per_page, page: page) else get_heatmaps if @heatmaps.empty? @heatmaps.values end end.
-
#gear ⇒ Array<Gear>
Gear list.
-
#get_details ⇒ Object
retrieval methods.
-
#initialize(data, client: nil, token: nil, **opts) ⇒ Athlete
constructor
A new instance of Athlete.
- #koms(per_page: nil, page: nil) ⇒ Object
-
#list_races(year = Time.now.year) ⇒ Object
Retrieve running races.
- #path_base ⇒ Object
- #routes(per_page: nil, page: nil) ⇒ Object
-
#segment_explorer(bounds = '37.821362,-122.505373,37.842038,-122.465977') ⇒ Object
Segment Explorer will find popular segments within a given area.
- #starred_segments(per_page: nil, page: nil) ⇒ Object
- #stats ⇒ Object (also: #totals)
-
#update(data, **opts) ⇒ self
Update an existing athlete.
- #zones ⇒ Object
Methods inherited from Base
#detailed?, #resource_state, resource_states, #summary?
Constructor Details
#initialize(data, client: nil, token: nil, **opts) ⇒ Athlete
Returns a new instance of Athlete.
38 39 40 41 |
# File 'lib/strava/athlete.rb', line 38 def initialize(data, client: nil, token: nil, **opts) @current = !!opts[:current] super end |
Instance Attribute Details
#athlete_type ⇒ Object (readonly)
Returns the value of attribute athlete_type.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def athlete_type @athlete_type end |
#bikes ⇒ Object (readonly)
Returns the value of attribute bikes.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def bikes @bikes end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def country @country end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def created_at @created_at end |
#date_preference ⇒ Object (readonly)
Returns the value of attribute date_preference.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def date_preference @date_preference end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def email @email end |
#firstname ⇒ Object (readonly)
Returns the value of attribute firstname.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def firstname @firstname end |
#follower ⇒ Object (readonly)
Returns the value of attribute follower.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def follower @follower end |
#follower_count ⇒ Object (readonly)
Returns the value of attribute follower_count.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def follower_count @follower_count end |
#friend ⇒ Object (readonly)
Returns the value of attribute friend.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def friend @friend end |
#friend_count ⇒ Object (readonly)
Returns the value of attribute friend_count.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def friend_count @friend_count end |
#ftp ⇒ Object (readonly)
Returns the value of attribute ftp.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def ftp @ftp end |
#lastname ⇒ Object (readonly)
Returns the value of attribute lastname.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def lastname @lastname end |
#measurement_preference ⇒ Object (readonly)
Returns the value of attribute measurement_preference.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def measurement_preference @measurement_preference end |
#mutual_friend_count ⇒ Object (readonly)
Returns the value of attribute mutual_friend_count.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def mutual_friend_count @mutual_friend_count end |
#premium ⇒ Object (readonly)
Returns the value of attribute premium.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def premium @premium end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def profile @profile end |
#profile_medium ⇒ Object (readonly)
Returns the value of attribute profile_medium.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def profile_medium @profile_medium end |
#sex ⇒ Object (readonly)
Returns the value of attribute sex.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def sex @sex end |
#shoes ⇒ Object (readonly)
Returns the value of attribute shoes.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def shoes @shoes end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def state @state end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def updated_at @updated_at end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
16 17 18 |
# File 'lib/strava/athlete.rb', line 16 def weight @weight end |
Class Method Details
.current_athlete(token = "ca16caf5b4cb8b57016541f470ae6b3a8aea2252") ⇒ Athlete
Retrieve the currently authenticated athlete. Will make request to Strava API.
358 359 360 361 362 |
# File 'lib/strava/athlete.rb', line 358 def current_athlete(token = "ca16caf5b4cb8b57016541f470ae6b3a8aea2252") client = Client.new(token) res = client.get('athlete').to_h new(res, client: client, current: true) end |
Instance Method Details
#activities(per_page: nil, page: nil) ⇒ Object
Activities belonging to this user. If no activities have been retrieved, an API call will be made. If activities exist, they will be returned. Pagination is supported, and will always trigger an API call. Paged requests will return the activities from that page. Non-paged calls will return all downloaded activities.
129 130 131 132 133 134 135 136 |
# File 'lib/strava/athlete.rb', line 129 def activities(per_page: nil, page: nil) if page || per_page get_activities(per_page: per_page, page: page) else get_activities if @activities.empty? @activities.values end end |
#both_following(other_athlete, per_page: nil, page: nil) ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/strava/athlete.rb', line 218 def both_following(other_athlete, per_page: nil, page: nil) other_id = other_athlete.is_a?(Athlete) ? other_athlete.id : other_athlete if page || per_page get_both_following(other_id, per_page: per_page, page: page) else get_both_following(other_id) if @both_following[other_id].nil? @both_following[other_id] end end |
#clubs ⇒ Object
175 176 177 178 |
# File 'lib/strava/athlete.rb', line 175 def clubs get_clubs if @clubs.empty? @clubs.values end |
#current? ⇒ Boolean
Whether this is the currently authenticated athlete. Strava's API has reduced access for athletes other than the currently authenticated one.
89 90 91 |
# File 'lib/strava/athlete.rb', line 89 def current? @current end |
#followers(per_page: nil, page: nil) ⇒ Object
208 209 210 211 212 213 214 215 216 |
# File 'lib/strava/athlete.rb', line 208 def followers(per_page: nil, page: nil) # paginate('followers', struct: Array, per_page: per_page, page: page) if page || per_page get_followers(per_page: per_page, page: page) else get_followers if @followers.empty? @followers.uniq(&:id) end end |
#friends(per_page: nil, page: nil) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/strava/athlete.rb', line 198 def friends(per_page: nil, page: nil) # paginate('friends', struct: Array, per_page: per_page, page: page) if page || per_page get_friends(per_page: per_page, page: page) else get_friends if @friends.empty? @friends.uniq(&:id) end end |
#friends_activities(per_page: nil, page: nil, before: nil) ⇒ Object
not working, not listed in docs def heatmaps(per_page: nil, page: nil) if page || per_page get_heatmaps(per_page: per_page, page: page) else get_heatmaps if @heatmaps.empty? @heatmaps.values end end
148 149 150 151 152 153 154 155 |
# File 'lib/strava/athlete.rb', line 148 def friends_activities(per_page: nil, page: nil, before: nil) if page || per_page get_friends_activities(per_page: per_page, page: page) else get_friends_activities if @friends_activities.empty? @friends_activities.values end end |
#gear ⇒ Array<Gear>
Gear list. Includes shoes and bikes.
118 119 120 |
# File 'lib/strava/athlete.rb', line 118 def gear @gear.values end |
#get_details ⇒ Object
retrieval methods
229 230 231 232 233 |
# File 'lib/strava/athlete.rb', line 229 def get_details return self if detailed? res = client.get(path_base).to_h update(res) end |
#koms(per_page: nil, page: nil) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/strava/athlete.rb', line 166 def koms(per_page: nil, page: nil) if page || per_page get_koms(per_page: per_page, page: page) else get_koms if @koms.empty? @koms.values end end |
#list_races(year = Time.now.year) ⇒ Object
Retrieve running races. This is not related to the current athlete, but does require an access token.
Also available via RunningRace.list_races
101 102 103 |
# File 'lib/strava/athlete.rb', line 101 def list_races(year = Time.now.year) client.list_races(year) end |
#path_base ⇒ Object
298 299 300 |
# File 'lib/strava/athlete.rb', line 298 def path_base current? ? 'athlete' : "athletes/#{id}" end |
#routes(per_page: nil, page: nil) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/strava/athlete.rb', line 180 def routes(per_page: nil, page: nil) if page || per_page get_routes(per_page: per_page, page: page) else get_routes if @routes.empty? @routes.values end end |
#segment_explorer(bounds = '37.821362,-122.505373,37.842038,-122.465977') ⇒ Object
Segment Explorer will find popular segments within a given area. Requires a comma separated list of bounding box corners.
Also available via Segment.explorer
111 112 113 |
# File 'lib/strava/athlete.rb', line 111 def segment_explorer(bounds = '37.821362,-122.505373,37.842038,-122.465977') client.segment_explorer(bounds) end |
#starred_segments(per_page: nil, page: nil) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/strava/athlete.rb', line 189 def starred_segments(per_page: nil, page: nil) if page || per_page get_starred_segments(per_page: per_page, page: page) else get_starred_segments if @starred_segments.empty? @starred_segments.values end end |
#stats ⇒ Object Also known as: totals
157 158 159 |
# File 'lib/strava/athlete.rb', line 157 def stats @stats || get_stats end |
#update(data, **opts) ⇒ self
Update an existing athlete. Used by other methods in the gem. Should not be used directly.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/strava/athlete.rb', line 50 def update(data, **opts) @id = data["id"] @username = data["username"] @resource_state = data["resource_state"] @firstname = data["firstname"] @lastname = data["lastname"] @city = data["city"] @state = data["state"] @country = data["country"] @sex = data["sex"] @premium = data["premium"] @created_at = data["created_at"] @updated_at = data["updated_at"] @badge_type_id = data["badge_type_id"] @profile_medium = data["profile_medium"] @profile = data["profile"] @friend = data["friend"] @follower = data["follower"] @follower_count = data["follower_count"] @friend_count = data["friend_count"] @mutual_friend_count = data["mutual_friend_count"] @athlete_type = data["athlete_type"] @date_preference = data["date_preference"] @measurement_preference = data["measurement_preference"] @email = data["email"] @ftp = data["ftp"] @weight = data["weight"] @bikes = parse_data(@gear, data['bikes'], klass: Gear, client: @client) @shoes = parse_data(@gear, data['shoes'], klass: Gear, client: @client) parse_data(@clubs, data['clubs'], klass: Club, client: @client) self end |
#zones ⇒ Object
162 163 164 |
# File 'lib/strava/athlete.rb', line 162 def zones @zones || get_zones end |