Module: Strava::Api::Endpoints::Segments

Included in:
Client
Defined in:
lib/strava/api/endpoints/segments.rb

Instance Method Summary collapse

Instance Method Details

#explore_segments(options = {}) ⇒ Object

Returns the top 10 segments matching a specified query.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :bounds (Array[Float])

    The latitude and longitude for two points describing a rectangular boundary for the search: [southwest corner latitude, southwest corner longitude, northeast corner latitude, northeast corner longitude].

  • :activity_type (String)

    Desired activity type. May take one of the following values: running, riding.

  • :min_cat (Integer)

    The minimum climbing category.

  • :max_cat (Integer)

    The maximum climbing category.



19
20
21
22
23
24
25
26
# File 'lib/strava/api/endpoints/segments.rb', line 19

def explore_segments(options = {})
  throw ArgumentError.new('Required argument :bounds missing') if options[:bounds].nil?
  bounds = options[:bounds]
  bounds = bounds.map(&:to_s).join(',') if bounds.is_a?(Array)
  get('segments/explore', options.merge(bounds: bounds))['segments'].map do |row|
    Strava::Models::ExplorerSegment.new(row)
  end
end

#segment(id_or_options, options = {}) ⇒ Object

Returns the specified segment.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :id (String)

    The identifier of the segment.



46
47
48
49
# File 'lib/strava/api/endpoints/segments.rb', line 46

def segment(id_or_options, options = {})
  id, options = parse_args(id_or_options, options)
  Strava::Models::Segment.new(get("segments/#{id}", options))
end

#star_segment(id_or_options, options = {}) ⇒ Object

Stars/Unstars the given segment for the authenticated athlete.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :id (String)

    The identifier of the segment to star.

  • :starred (Boolean)

    If true, star the segment; if false, unstar the segment.



59
60
61
62
63
# File 'lib/strava/api/endpoints/segments.rb', line 59

def star_segment(id_or_options, options = {})
  id, options = parse_args(id_or_options, options)
  throw ArgumentError.new('Required argument :starred missing') if options[:starred].nil?
  Strava::Models::Segment.new(put("segments/#{id}/starred", options))
end

#starred_segments(options = {}, &block) ⇒ Object

List of the authenticated athlete’s starred segments.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :page (Integer)

    Page number.

  • :per_page (Integer)

    Number of items per page. Defaults to 30.



36
37
38
# File 'lib/strava/api/endpoints/segments.rb', line 36

def starred_segments(options = {}, &block)
  paginate 'segments/starred', options, Strava::Models::Segment, &block
end