stravax

package module
v0.0.0-...-c113787 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2018 License: MIT Imports: 14 Imported by: 0

README

stravax

version  Build Status

stravax extends the Strava API to allow for retrieving complete Strava leaderboard information for a logged in user.

The generated GoDoc can be viewed at godoc.org/github.com/scheibo/stravax.

Usage

client, err := stravax.NewClient(email, password)

leaderboard, err :=
  client.GetLeaderboardPage(
    segmentId, stravax.Genders.Male, stravax.Filters.CurrentYear, 1)

for _, e := range leaderboard.Entries {
  fmt.Printf("%d) %s: %v (%s)\n",
    e.Rank,
    e.Athlete.Name,
    time.Duration(e.ElapsedTime)*time.Second,
    e.StartDate)
}

Documentation

Overview

Package stravax extends the Strava API to allow for retrieving complete Strava leaderboard information for a logged in user.

Index

Constants

View Source
const CLIMB_THRESHOLD = 0.03

CLIMB_THRESHOLD is the mininum gradient that is considered a climb for purposes of adjusting the TotalElevationGained/AverageGrade metrics.

View Source
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.

View Source
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.

View Source
const USER_AGENT = "stravax/0.1.0"

USER_AGENT is the user agent we will use when making requests against the frontend.

Variables

View Source
var Filters = struct {
	Overall     Filter
	CurrentYear Filter
}{"overall", "current_year"}

Filters represents the Strava filters this client supports.

View Source
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 NewClient

func NewClient(email, password string, accessToken ...string) (*Client, error)

NewClient returns an authenticated Client for querying Strava.

func NewStubClient

func NewStubClient(content ...string) *Client

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.

func (*Client) GetSegment

func (c *Client) GetSegment(segmentID int64) (*Segment, error)

GetSegment returns the data for the segment identified by segmentID using the Strava API.

type Filter

type Filter string

Filter is the filter used on the leaderboard.

type Gender

type Gender string

Gender is the gender of the athlete.

type LatLng

type LatLng struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

LatLng represents a location on the Earth.

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.

Directories

Path Synopsis
leaderboard provides a CLI for retrieving the full details of a page of a Strava leaderboard.
leaderboard provides a CLI for retrieving the full details of a page of a Strava leaderboard.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL