Class: Strava::Activity

Inherits:
Base
  • Object
show all
Defined in:
lib/strava/activity.rb

Overview

Class to represent Strava Activity

Constant Summary collapse

ATTRIBUTES =

activity attributes, all have getter method

[:external_id, :upload_id, :athlete, :name, :description, :distance, :moving_time, :elapsed_time, :total_elevation_gain, :elev_high, :elev_low, :type, :start_date, :start_date_local, :timezone, :start_latlng, :end_latlng, :location_city, :location_state, :location_country, :achievement_count, :kudos_count, :comment_count, :athlete_count, :photo_count, :total_photo_count, :map, :trainer, :commute, :manual, :private, :device_name, :embed_token, :flagged, :workout_type, :gear_id, :average_speed, :max_speed, :average_cadence, :average_temp, :average_watts, :max_watts, :weighted_average_watts, :kilojoules, :device_watts, :has_heartrate, :average_heartrate, :max_heartrate, :calories, :suffer_score, :has_kudoed, :splits_metric, :splits_standard, :best_efforts]

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #id, #response

Instance Method Summary collapse

Methods inherited from Base

#detailed?, #initialize, #resource_state, resource_states, #summary?

Constructor Details

This class inherits a constructor from Strava::Base

Instance Attribute Details

#gearObject (readonly)

Returns the value of attribute gear.



7
8
9
# File 'lib/strava/activity.rb', line 7

def gear
  @gear
end

#photos_infoObject (readonly)

Returns the value of attribute photos_info.



7
8
9
# File 'lib/strava/activity.rb', line 7

def photos_info
  @photos_info
end

Instance Method Details

#comment(message) ⇒ Object



99
100
101
# File 'lib/strava/activity.rb', line 99

def comment(message)
  res = client.post(path_comments, text: message).to_h
end

#comments(per_page: nil, page: nil) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/strava/activity.rb', line 55

def comments(per_page: nil, page: nil)
  if page || per_page
    get_comments(per_page: per_page, page: page)
  else
    get_comments if @comments.empty?
    @comments.values
  end
end

#get_comments(per_page: nil, page: nil) ⇒ Object



117
118
119
120
# File 'lib/strava/activity.rb', line 117

def get_comments(per_page: nil, page: nil)
  res = client.get(path_comments, per_page: per_page, page: page).to_a
  parse_data(@comments, res, klass: Comment, client: @client)
end

#get_detailsObject



108
109
110
111
112
# File 'lib/strava/activity.rb', line 108

def get_details
  return self if detailed?
  res = client.get(path_base).to_h
  update(res)
end

#get_kudos(per_page: nil, page: nil) ⇒ Object



113
114
115
116
# File 'lib/strava/activity.rb', line 113

def get_kudos(per_page: nil, page: nil)
  res = client.get(path_kudos, per_page: per_page, page: page).to_a
  parse_data(@kudos, res, klass: Athlete, client: @client)
end

#get_lapsObject



137
138
139
140
# File 'lib/strava/activity.rb', line 137

def get_laps
  res = client.get(path_laps).to_a
  parse_data(@laps, res, klass: Lap, client: @client)
end

#get_photos(per_page: nil, page: nil) ⇒ Object



121
122
123
124
# File 'lib/strava/activity.rb', line 121

def get_photos(per_page: nil, page: nil)
  res = client.get(path_photos, per_page: per_page, page: page).to_a
  parse_data(@photos, res, klass: Photo, client: @client)
end


125
126
127
128
# File 'lib/strava/activity.rb', line 125

def get_related(per_page: nil, page: nil)
  res = client.get(path_related, per_page: per_page, page: page).to_a
  parse_data(@related, res, klass: Activity, client: @client)
end

#get_streams(types = '', **params) ⇒ Object



129
130
131
132
# File 'lib/strava/activity.rb', line 129

def get_streams(types = '', **params)
  res = client.get(path_streams + types.join(','), **params).to_a
  @streams.update(res)
end

#get_zonesObject



133
134
135
136
# File 'lib/strava/activity.rb', line 133

def get_zones
  res = client.get(path_zones).to_a
  @zones = res
end

#kudoObject



103
104
105
# File 'lib/strava/activity.rb', line 103

def kudo
  res = client.post(path_kudos).to_h
end

#kudos(per_page: nil, page: nil) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/strava/activity.rb', line 46

def kudos(per_page: nil, page: nil)
  if page || per_page
    get_kudos(per_page: per_page, page: page)
  else
    get_kudos if @kudos.empty?
    @kudos.values
  end
end

#lapsObject



94
95
96
97
# File 'lib/strava/activity.rb', line 94

def laps
  get_laps if @laps.empty?
  @laps.values
end

#path_baseObject



143
144
145
# File 'lib/strava/activity.rb', line 143

def path_base
  "activities/#{id}"
end

#path_commentsObject



149
150
151
# File 'lib/strava/activity.rb', line 149

def path_comments
  "#{path_base}/comments"
end

#path_kudosObject



146
147
148
# File 'lib/strava/activity.rb', line 146

def path_kudos
  "#{path_base}/kudos"
end

#path_lapsObject



164
165
166
# File 'lib/strava/activity.rb', line 164

def path_laps
  "#{path_base}/laps"
end

#path_photosObject



152
153
154
# File 'lib/strava/activity.rb', line 152

def path_photos
  "#{path_base}/photos?photo_sources=true"
end


155
156
157
# File 'lib/strava/activity.rb', line 155

def path_related
  "#{path_base}/related"
end

#path_streamsObject



158
159
160
# File 'lib/strava/activity.rb', line 158

def path_streams
  "#{path_base}/streams/"
end

#path_zonesObject



161
162
163
# File 'lib/strava/activity.rb', line 161

def path_zones
  "#{path_base}/zones"
end

#photos(per_page: nil, page: nil) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/strava/activity.rb', line 64

def photos(per_page: nil, page: nil)
  if page || per_page
    get_photos(per_page: per_page, page: page)
  else
    get_photos if @photos.empty?
    @photos.values
  end
end

Activities that were matched as “with this group”. The number equals activity.athlete_count-1. Pagination is supported.

Returns:



75
76
77
78
79
80
81
82
# File 'lib/strava/activity.rb', line 75

def related(per_page: nil, page: nil)
  if page || per_page
    get_related(per_page: per_page, page: page)
  else
    get_related if @related.empty?
    @related.values
  end
end

#segment_effortsObject



42
43
44
# File 'lib/strava/activity.rb', line 42

def segment_efforts
  @segment_efforts.values
end

#streams(types = [:time, :distance, :latlng], **params) ⇒ Object



84
85
86
87
# File 'lib/strava/activity.rb', line 84

def streams(types = [:time, :distance, :latlng], **params)
  get_streams(types, **params) if @streams.empty?
  @streams
end

#zonesObject



89
90
91
92
# File 'lib/strava/activity.rb', line 89

def zones
  get_zones unless @zones
  @zones
end