Class: Strava::Segment

Inherits:
Base
  • Object
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

#leaderboardObject (readonly)

Class to represent Strava Activity https://strava.github.io/api/v3/activities/ Your code goes here...



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)
  # paginate('efforts', struct: Array, per_page: per_page, page: page)
  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_detailsObject



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_baseObject



65
66
67
# File 'lib/strava/segment.rb', line 65

def path_base
  "segments/#{id}"
end

#path_effortsObject



69
70
71
# File 'lib/strava/segment.rb', line 69

def path_efforts
  "#{path_base}/all_efforts"
end

#path_starObject



73
74
75
# File 'lib/strava/segment.rb', line 73

def path_star
  "#{path_base}/starred"
end

#path_streamsObject



77
78
79
# File 'lib/strava/segment.rb', line 77

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

#set_ivarsObject



8
9
10
11
# File 'lib/strava/segment.rb', line 8

def set_ivars
  @efforts  = {}
  @streams = StreamSet.new
end

#starObject

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

#unstarObject



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