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.



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

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.



90
91
92
93
# File 'lib/strava/api/endpoints/segments.rb', line 90

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

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

Returns the specified segment leaderboard.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :id (Integer)

    The identifier of the segment leaderboard.

  • :gender (String)

    Filter by gender.

  • :age_group (String)

    Filter by age group.

  • :weight_class (String)

    Filter by weight class.

  • :following (Boolean)

    Filter by friends of the authenticated athlete.

  • :club_id (Integer)

    Filter by club.

  • :date_range (String)

    Filter by date range.

  • :context_entries (Integer)

    ?

  • :page (Integer)

    Page number.

  • :per_page (Integer)

    Number of items per page. Defaults to 30.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/strava/api/endpoints/segments.rb', line 50

def segment_leaderboard(id_or_options, options = {})
  id, options = parse_args(id_or_options, options)

  if block_given?
    next_page = 1
    total_count = 0
    loop do
      query = options.merge(page: next_page)
      response = Strava::Models::SegmentLeaderboard.new(get("segments/#{id}/leaderboard", query))
      total_count += response.entries.count
      break unless response.entries.any?

      yield response
      break if total_count >= response.entry_count

      next_page += 1
    end
  else
    Strava::Models::SegmentLeaderboard.new(get("segments/#{id}/leaderboard", options))
  end
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.



103
104
105
106
107
# File 'lib/strava/api/endpoints/segments.rb', line 103

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.



80
81
82
# File 'lib/strava/api/endpoints/segments.rb', line 80

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