Class: Strava::Segment
- Inherits:
-
Base
- Object
- Base
- Strava::Segment
show all
- Defined in:
- lib/strava/segment.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#client, #id, #response
Class Method Summary
collapse
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
#leaderboard ⇒ Object
6
7
8
|
# File 'lib/strava/segment.rb', line 6
def leaderboard
@leaderboard
end
|
Class Method Details
.explorer(client, bounds = '37.821362,-122.505373,37.842038,-122.465977') ⇒ Object
81
82
83
84
|
# File 'lib/strava/segment.rb', line 81
def self.explorer(client, bounds = '37.821362,-122.505373,37.842038,-122.465977')
res = client.get("segments/explore", bounds: bounds).to_h
res['segments'].map { |hash| new(hash, client: client) }
end
|
Instance Method Details
#efforts(per_page: nil, page: nil, **params) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/strava/segment.rb', line 22
def efforts(per_page: nil, page: nil, **params)
if page || per_page || !params.empty?
get_efforts(per_page: per_page, page: page, **params)
else
get_efforts if @efforts.empty?
@efforts.values
end
end
|
#get_details ⇒ Object
47
48
49
50
51
52
|
# File 'lib/strava/segment.rb', line 47
def get_details
return self if detailed?
res = client.get(path_base).to_h
update(res)
res
end
|
#get_streams(types = '', **params) ⇒ Object
54
55
56
57
|
# File 'lib/strava/segment.rb', line 54
def get_streams(types = '', **params)
res = client.get(path_streams + types.join(','), **params).to_a
@streams.update(res)
end
|
#path_base ⇒ Object
65
66
67
|
# File 'lib/strava/segment.rb', line 65
def path_base
"segments/#{id}"
end
|
#path_efforts ⇒ Object
69
70
71
|
# File 'lib/strava/segment.rb', line 69
def path_efforts
"#{path_base}/all_efforts"
end
|
#path_star ⇒ Object
73
74
75
|
# File 'lib/strava/segment.rb', line 73
def path_star
"#{path_base}/starred"
end
|
#path_streams ⇒ Object
77
78
79
|
# File 'lib/strava/segment.rb', line 77
def path_streams
"#{path_base}/streams/"
end
|
#set_ivars ⇒ Object
8
9
10
11
|
# File 'lib/strava/segment.rb', line 8
def set_ivars
@efforts = {}
@streams = StreamSet.new
end
|
#star ⇒ Object
don't know if this really works or not. doesn't seem to work
33
34
35
|
# File 'lib/strava/segment.rb', line 33
def star
res = client.put(path_star, star: true).to_h
end
|
#streams(types = [:distance, :altitude, :latlng], **params) ⇒ Object
41
42
43
44
|
# File 'lib/strava/segment.rb', line 41
def streams(types = [:distance, :altitude, :latlng], **params)
get_streams(types, **params) if @streams.empty?
@streams
end
|
#unstar ⇒ Object
37
38
39
|
# File 'lib/strava/segment.rb', line 37
def unstar
res = client.put(path_star, star: false).to_h
end
|
#update(data, **opts) ⇒ Object
16
17
18
19
20
|
# File 'lib/strava/segment.rb', line 16
def update(data, **opts)
@response = data
@id = data["id"]
@resource_state = data['resource_state']
end
|