strava

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

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

Go to latest
Published: Mar 21, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GrantAuthorizationCode = "authorization_code"
	GrantRefreshToken      = "refresh_token"
)

Variables

View Source
var AuthorizationError = errors.New("authorization error")

AuthorizationError describe the token authorization error.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Type         string `json:"token_type"`
	ExpiresAt    int64  `json:"expires_at"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	AccessToken  string `json:"access_token"`
	Athlete      struct {
		ID        uint64 `json:"id"`
		Username  string `json:"username"`
		Firstname string `json:"firstname"`
		Lastname  string `json:"lastname"`
	} `json:"athlete"`
}

AccessToken is the response of the Authorization.

type ActivitiesRequest

type ActivitiesRequest struct {
	Before  types.Date `json:"before"`
	After   types.Date `json:"after"`
	Page    uint64     `json:"page"`
	PerPage uint64     `json:"per_page"`
}

ActivitiesRequest contains parameters to request activities from Strava.

func (ActivitiesRequest) Queries

func (p ActivitiesRequest) Queries() types.Map

Queries convert the request to queries.

type Activity

type Activity struct {
	ID                 uint64    `json:"id"`
	ExternalID         string    `json:"external_id"`
	UploadId           int64     `json:"upload_id"`
	Name               string    `json:"name"`
	Description        string    `json:"description"`
	Type               string    `json:"type"`
	Distance           float64   `json:"distance"`
	MovingTime         uint64    `json:"moving_time"`
	ElapsedTime        uint64    `json:"elapsed_time"`
	AverageSpeed       float64   `json:"average_speed"`
	AverageCadence     float64   `json:"average_cadence"`
	AverageHeartRate   float64   `json:"average_heartrate"`
	MaxSpeed           float64   `json:"max_speed"`
	MaxHeartRate       float64   `json:"max_heartrate"`
	MaxWatts           float64   `json:"max_watts"`
	Score              float64   `json:"suffer_score"`
	Calories           float64   `json:"calories"`
	TotalElevationGain float64   `json:"total_elevation_gain"`
	HighestElevation   float64   `json:"elev_high"`
	LowestElevation    float64   `json:"elev_low"`
	StartLocation      []float64 `json:"start_latlng"`
	EndLocation        []float64 `json:"end_latlng"`
	DeviceName         string    `json:"device_name"`

	StartAt time.Time `json:"start_date"`

	// Nested
	Splits []Split `json:"splits_metric"`
	Laps   []Lap   `json:"laps"`

	Athlete struct {
		ID uint64 `json:"id"`
	} `json:"athlete"`

	Map struct {
		ID              string `json:"id"`
		Polyline        string `json:"polyline"`
		SummaryPolyline string `json:"summary_polyline"`
	} `json:"map"`
}

Activity is a representation of an Activity on Strava.com.

type Client

type Client interface {
	// AuthorizationURL returns the URL to get the authorization from the user.
	AuthorizationURL(string) string

	// AuthorizationAccessToken get an access token from the code or refresh token.
	AuthorizationAccessToken(tok, grant string) (at AccessToken, err error)

	// Activity returns an activity
	Activity(uint64) (Activity, error)

	// Activities returns a list of activities.
	Activities(ActivitiesRequest) ([]Activity, error)

	// SetAccessToken set a new token.
	SetAccessToken(tok string)

	// SetUserID set a new default user id for user's requests.
	SetUserID(id uint64)
}

Client is the client interface of Strava service.

func New

func New(cfg Config) Client

New create a new Strava client from the given config.

func NewEnv

func NewEnv() Client

NewEnv create a new Strava client from the environment variables.

type Config

type Config struct {
	Host         string `json:"host" env:"STRAVA_HOST"`
	ClientID     string `json:"client_id" env:"STRAVA_ID"`
	ClientSecret string `json:"client_secret" env:"STRAVA_SECRET"`
	RedirectURI  string `json:"redirect_uri" env:"STRAVA_REDIRECT_URI"`
	Timeout      uint16 `json:"timeout" env:"STRAVA_TIMEOUT"`
	Scope        string `json:"scope" env:"STRAVA_SCOPE"`
}

Config is the configuration for the client to request the Strava API.

type Lap

type Lap struct {
	ID                 uint64  `json:"id"`
	Split              uint64  `json:"split"`
	Index              uint64  `json:"lap_index"`
	Name               string  `json:"name"`
	Distance           float64 `json:"distance"`
	ElapsedTime        uint64  `json:"elapsed_time"`
	MovingTime         uint64  `json:"moving_time"`
	AverageSpeed       float64 `json:"average_speed"`
	AverageHeartRate   float64 `json:"average_heartrate"`
	AverageCadence     float64 `json:"average_cadence"`
	MaxSpeed           float64 `json:"max_speed"`
	MaxHeartRate       float64 `json:"max_heartrate"`
	TotalElevationGain float64 `json:"total_elevation_gain"`
	PaceZone           uint64  `json:"pace_zone"`
}

Lap is a representation of an Lap on Strava.com

type RequestParams

type RequestParams struct {
	Queries            types.Map
	Values             types.Map
	WithBearer         bool
	WithFormURLEncoded bool
}

RequestParams define the parameters to request the API.

type Split

type Split struct {
	Distance                  float64 `json:"distance"`
	ElevationDifference       float64 `json:"elevation_difference"`
	ElapsedTime               uint64  `json:"elapsed_time"`
	MovingTime                uint64  `json:"moving_time"`
	AverageSpeed              float64 `json:"average_speed"`
	AverageGradeAdjustedSpeed float64 `json:"average_grade_adjusted_speed"`
	AverageHeartRate          float64 `json:"average_heartrate"`
	PaceZone                  uint64  `json:"pace_zone"`
}

Split is a representation of an Split on Strava.com.

Jump to

Keyboard shortcuts

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