cyclinganalytics

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Endpoint

func Endpoint() oauth2.Endpoint

Endpoint is CyclingAnalytics's OAuth 2.0 endpoint

Types

type APIOption added in v0.6.0

type APIOption func(url.Values) error

APIOption for configuring API requests

func WithRideOptions added in v0.6.0

func WithRideOptions(r RideOptions) APIOption

type Client

type Client struct {
	User  *UserService
	Rides *RidesService
	// contains filtered or unexported fields
}

Client for accessing Cycling Analytics' API

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new client and applies all provided Options

func (*Client) Uploader

func (c *Client) Uploader() activity.Uploader

type Datetime

type Datetime struct {
	time.Time
}

func (Datetime) MarshalJSON

func (d Datetime) MarshalJSON() ([]byte, error)

func (*Datetime) UnmarshalJSON

func (d *Datetime) UnmarshalJSON(b []byte) error

type Fault

type Fault struct {
	Code    int    `json:"code"`
	Message string `json:"error"`
}

Fault represents an error response

func (*Fault) Error

func (f *Fault) Error() string

type Has

type Has struct {
	Cadence     bool `json:"cadence"`
	Elevation   bool `json:"elevation"`
	GPS         bool `json:"gps"`
	Heartrate   bool `json:"heartrate"`
	Power       bool `json:"power"`
	Speed       bool `json:"speed"`
	Temperature bool `json:"temperature"`
}

type Metadata

type Metadata struct {
	Type string `json:"type"`
}

type Option

type Option func(*Client) error

Option provides a configuration mechanism for a Client

func WithAutoRefresh

func WithAutoRefresh(ctx context.Context) Option

WithAutoRefresh refreshes access tokens automatically. The order of this option matters because it is dependent on the client's config and token. Use this option after With*Credentials.

func WithBaseURL added in v0.2.0

func WithBaseURL(baseURL string) Option

WithBaseURL specifies the base url

func WithClientCredentials

func WithClientCredentials(clientID, clientSecret string) Option

WithAPICredentials provides the client api credentials for the application.

func WithConfig

func WithConfig(config oauth2.Config) Option

WithConfig sets the underlying oauth2.Config.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the underlying http client.

func WithHTTPTracing

func WithHTTPTracing(debug bool) Option

WithHTTPTracing enables tracing http calls.

func WithRateLimiter

func WithRateLimiter(r *rate.Limiter) Option

WithRateLimiter rate limits the client's api calls

func WithToken

func WithToken(token *oauth2.Token) Option

WithToken sets the underlying oauth2.Token.

func WithTokenCredentials

func WithTokenCredentials(accessToken, refreshToken string, expiry time.Time) Option

WithTokenCredentials provides the tokens for an authenticated user.

func WithTransport

func WithTransport(t http.RoundTripper) Option

WithTransport sets the underlying http client transport.

type Ride

type Ride struct {
	Format        string   `json:"format"`
	Has           Has      `json:"has"`
	ID            int64    `json:"id"`
	LocalDatetime Datetime `json:"local_datetime"`
	Metadata      Metadata `json:"metadata"`
	Notes         string   `json:"notes"`
	Purpose       string   `json:"purpose"`
	Streams       Streams  `json:"streams"`
	Subtype       string   `json:"subtype"`
	Summary       Summary  `json:"summary"`
	Title         string   `json:"title"`
	Trainer       bool     `json:"trainer"`
	UserID        UserID   `json:"user_id"`
	UTCDatetime   Datetime `json:"utc_datetime"`
}

func (*Ride) GPX

func (r *Ride) GPX() (*gpx.GPX, error)

type RideOptions

type RideOptions struct {
	// Streams is a list of valid data streams
	Streams []string
	// Curves specifies the difference curves to return
	Curves struct {
		// AveragePower will be returned if true
		AveragePower bool
		// EffectivePower will be returned if true
		EffectivePower bool
	}
}

RideOptions specify additional detail to return for a queried ride

type RidesService

type RidesService service

RidesService manages rides for a user

func (*RidesService) Ride

func (s *RidesService) Ride(ctx context.Context, rideID int64, opts ...APIOption) (*Ride, error)

Ride returns a single ride with available options

func (*RidesService) Rides

func (s *RidesService) Rides(ctx context.Context, userID UserID, spec activity.Pagination) ([]*Ride, error)

Rides returns a slice of rides for the user

func (*RidesService) Status

func (s *RidesService) Status(ctx context.Context, uploadID int64) (*Upload, error)

Status returns the status of an upload request

func (*RidesService) StatusWithUser

func (s *RidesService) StatusWithUser(ctx context.Context, userID UserID, uploadID int64) (*Upload, error)

Status returns the status of an upload request for the user

func (*RidesService) StreamSets

func (s *RidesService) StreamSets() map[string]string

StreamSets returns the list of valid stream names

func (*RidesService) Upload

func (s *RidesService) Upload(ctx context.Context, file *activity.File) (*Upload, error)

Upload the file for the authenticated user

func (*RidesService) UploadWithUser

func (s *RidesService) UploadWithUser(ctx context.Context, userID UserID, file *activity.File) (*Upload, error)

Upload the file for the user

type Shift

type Shift []int

type Shifts

type Shifts struct {
	Shifts []Shift `json:"shifts"`
}

type Streams

type Streams struct {
	Power                []float64 `json:"power,omitempty"`
	Speed                []float64 `json:"speed,omitempty"`
	Distance             []float64 `json:"distance,omitempty"`
	Heartrate            []float64 `json:"heartrate,omitempty"`
	Cadence              []float64 `json:"cadence,omitempty"`
	LRBalance            []float64 `json:"lrbalance,omitempty"`
	Latitude             []float64 `json:"latitude,omitempty"`
	Longitude            []float64 `json:"longitude,omitempty"`
	Elevation            []float64 `json:"elevation,omitempty"`
	Gradient             []float64 `json:"gradient,omitempty"`
	Temperature          []float64 `json:"temperature,omitempty"`
	TorqueEffectiveness  []float64 `json:"torque_effectiveness,omitempty"`
	PedalSmoothness      []float64 `json:"pedal_smoothness,omitempty"`
	PlatformCenterOffset []float64 `json:"platform_center_offset,omitempty"`
	PowerPhase           []float64 `json:"power_phase,omitempty"`
	PowerDirection       []float64 `json:"power_direction,omitempty"`
	THB                  []float64 `json:"thb,omitempty"`
	SMO2                 []float64 `json:"smo2,omitempty"`
	RespirationRate      []float64 `json:"respiration_rate,omitempty"`
	HeartRateVariability []float64 `json:"heart_rate_variability,omitempty"`
	Gears                *Shifts   `json:"gears,omitempty"`
}

type Summary

type Summary struct {
	AvgCadence     float64 `json:"avg_cadence"`
	AvgHeartrate   float64 `json:"avg_heartrate"`
	AvgPower       float64 `json:"avg_power"`
	AvgSpeed       float64 `json:"avg_speed"`
	AvgTemperature float64 `json:"avg_temperature"`
	Climbing       float64 `json:"climbing"`
	Decoupling     float64 `json:"decoupling"`
	Distance       float64 `json:"distance"`
	Duration       float64 `json:"duration"`
	Epower         float64 `json:"epower"`
	Intensity      float64 `json:"intensity"`
	Load           float64 `json:"load"`
	LRBalance      float64 `json:"lrbalance"`
	MaxCadence     float64 `json:"max_cadence"`
	MaxHeartrate   float64 `json:"max_heartrate"`
	MaxPower       float64 `json:"max_power"`
	MaxSpeed       float64 `json:"max_speed"`
	MaxTemperature float64 `json:"max_temperature"`
	MinTemperature float64 `json:"min_temperature"`
	MovingTime     float64 `json:"moving_time"`
	PWC150         float64 `json:"pwc150"` // physical working capacity
	PWC170         float64 `json:"pwc170"` // physical working capacity
	PWCR2          float64 `json:"pwc_r2"` // physical working capacity
	RidingTime     float64 `json:"riding_time"`
	TotalTime      float64 `json:"total_time"`
	TRIMP          float64 `json:"trimp"`
	Variability    float64 `json:"variability"`
	Work           float64 `json:"work"`
	Zones          Zones   `json:"zones"`
}

type Upload

type Upload struct {
	ID        int64    `json:"upload_id"`
	Status    string   `json:"status"`
	RideID    int64    `json:"ride_id"`
	UserID    UserID   `json:"user_id"`
	Format    string   `json:"format"`
	Datetime  Datetime `json:"datetime"`
	Filename  string   `json:"filename"`
	Size      int64    `json:"size"`
	Error     string   `json:"error"`
	ErrorCode string   `json:"error_code"`
}

func (*Upload) Done

func (u *Upload) Done() bool

func (*Upload) Identifier

func (u *Upload) Identifier() activity.UploadID

type UploadResult

type UploadResult struct {
	Upload *Upload `json:"upload"`
	Err    error   `json:"error"`
}

type User

type User struct {
	Email    string `json:"email"`
	ID       UserID `json:"id"`
	Name     string `json:"name"`
	Sex      string `json:"sex"`
	Timezone string `json:"timezone"`
	Units    string `json:"units"`
}

type UserID

type UserID int
const (
	// Me represents the user id of the authenticated user
	Me UserID = 0
)

type UserService

type UserService service

UserService .

func (*UserService) Me

func (s *UserService) Me(ctx context.Context) (*User, error)

type Zones

type Zones struct {
	Heartrate []float64 `json:"heartrate"`
	Power     []float64 `json:"power"`
}

Jump to

Keyboard shortcuts

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