Sha256: f6b52b35506669d6211d310ae8512ade41792db30f85915e563be55ef8b876d4

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module Strava
  class Leaderboard < Base
    # Class to represent Strava Activity
    # https://strava.github.io/api/v3/activities/
    # Your code goes here...

    def set_ivars
      @entries      = {}
    end

    def standings
      @entries.values.sort { |a, b| a.rank <=> b.rank }
    end
    alias :entries :standings

    def update(data, **opts)
      @response = data
      @segment_id = data['segment_id'] if data['segment_id']

      @entry_count  = data['entry_count'] if data['entry_count']
      if data['entries']
        data['entries'].each { |hash| hash['id'] = hash['effort_id'] }
        parse_data(@entries, data['entries'], klass: LeaderboardEntry, client: @client)
      end

      self
    end

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

    def get_standings(per_page: nil, page: nil, **params)
      res = client.get(path_base, per_page: per_page, page: page, **params).to_h
      update(res)
    end

    def path_base
      "segments/#{@segment_id}/leaderboard"
    end


  end
end

__END__

ca = Strava::Athlete.current_athlete;
rlk = ca.friends.detect{|a| a.id == 3635502 };
segments = rlk.starred_segments;
seg = segments.first
seg.leaderboard
seg.leaderboard.get_standings;
seg.leaderboard.standings

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strava-0.1.0 lib/strava/leaderboard.rb