Documentation
¶
Overview ¶
Package stravax extends the Strava API to allow for retrieving complete Strava leaderboard information for a logged in user.
Index ¶
- Constants
- Variables
- type Athlete
- type Client
- func (c *Client) GetLeaderboard(segmentID int64, gender Gender, filter Filter) (*Leaderboard, error)
- func (c *Client) GetLeaderboardAndSegment(segmentID int64, gender Gender, filter Filter) (*Leaderboard, *Segment, error)
- func (c *Client) GetLeaderboardPage(segmentID int64, gender Gender, filter Filter, page int) (*Leaderboard, error)
- func (c *Client) GetLeaderboardPageAndSegment(segmentID int64, gender Gender, filter Filter, page int) (*Leaderboard, *Segment, error)
- func (c *Client) GetSegment(segmentID int64) (*Segment, error)
- type Filter
- type Gender
- type LatLng
- type Leaderboard
- type LeaderboardEntry
- type Segment
Constants ¶
const CLIMB_THRESHOLD = 0.03
CLIMB_THRESHOLD is the mininum gradient that is considered a climb for purposes of adjusting the TotalElevationGained/AverageGrade metrics.
const MAX_PER_PAGE = 100
MAX_PER_PAGE is the maximum number of entries which can be requested per page. NOTE: This is 200 when using the API, but for some reason 100 is the limit when scraping the frontend.
const QPS_LIMIT = 10
QPS_LIMIT is the maximum number of requests we will make in a second to both the API and the frontend combined.
const USER_AGENT = "stravax/0.1.0"
USER_AGENT is the user agent we will use when making requests against the frontend.
Variables ¶
var Filters = struct { Overall Filter CurrentYear Filter }{"overall", "current_year"}
Filters represents the Strava filters this client supports.
var Genders = struct { Unspecified Gender Male Gender Female Gender }{"", "M", "F"}
Genders represents all possible genders Strava supports.
Functions ¶
This section is empty.
Types ¶
type Athlete ¶
type Athlete struct { URL string `json:"url"` Name string `json:"name"` Gender Gender `json:"gender"` }
Athlete holds information about a Strava athlete required to render a leaderboard.
type Client ¶
type Client struct { RequestCount int64 // contains filtered or unexported fields }
Client is used to retrieve Segment and Leaderboard information from the Strava API and frontend. Calls to Strava are rate limiting to QPS_LIMIT requests/second, and the number of requests issued is tracked by RequestCount.
func NewStubClient ¶
NewStubClient returns content for each subsequent request that is made.
func (*Client) GetLeaderboard ¶
func (c *Client) GetLeaderboard(segmentID int64, gender Gender, filter Filter) (*Leaderboard, error)
GetLeaderboard returns the leaderboard of segmentID for the specified gender and filter.
func (*Client) GetLeaderboardAndSegment ¶
func (c *Client) GetLeaderboardAndSegment(segmentID int64, gender Gender, filter Filter) (*Leaderboard, *Segment, error)
GetLeaderboardAndSegment returns the leaderboard of segmentID for the specified gender and filter as well the segment details.
func (*Client) GetLeaderboardPage ¶
func (c *Client) GetLeaderboardPage(segmentID int64, gender Gender, filter Filter, page int) (*Leaderboard, error)
GetLeaderboardPage returns the specified page of the leaderboard for segmentID for given gender and filter.
func (*Client) GetLeaderboardPageAndSegment ¶
func (c *Client) GetLeaderboardPageAndSegment(segmentID int64, gender Gender, filter Filter, page int) (*Leaderboard, *Segment, error)
GetLeaderboardPageAndSegment returns the specified page of the leaderboard for segmentID for given gender and filter as well as the segment details.
type Leaderboard ¶
type Leaderboard struct { Entries []*LeaderboardEntry `json:"entries"` EntriesCount int64 `json:"entries_count"` }
Leaderboard contains LeaderboardEntry objects sorted by their rank according to Strava. len(Entries) may not equal EntriesCount if the Leaderboard has not been completely fetched or entries were added or removed from the leaderboard during fetching.
type LeaderboardEntry ¶
type LeaderboardEntry struct { Rank int64 `json:"rank"` Athlete Athlete `json:"athlete"` EffortID int64 `json:"effort_id"` StartDate time.Time `json:"start_date"` ElapsedTime int64 `json:"elapsed_time"` }
LeaderboardEntry is a single entry in a leaderboard, representing the best effort on a segment by a particular athlete.
type Segment ¶
type Segment struct { ID int64 `json:"id"` Name string `json:"name"` Location string `json:"location"` Distance float64 `json:"distance"` AverageGrade float64 `json:"average_grade"` ElevationLow float64 `json:"elevation_low"` ElevationHigh float64 `json:"elevation_high"` TotalElevationGain float64 `json:"total_elevation_gain"` MedianElevation float64 `json:"median_elevation"` StartLocation LatLng `json:"start_location"` EndLocation LatLng `json:"end_location"` Map string `json:"map,omitempty"` }
Segment contains the Strava segment details. NOTE: The segment information stored in the frontend leaderboard page is inherently less accurate than the information from the API.