rwgps

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Users *UsersService
	Trips *TripsService
	// contains filtered or unexported fields
}

Client for communicating with RWGPS

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 Fault

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

Fault is an error

func (*Fault) Error

func (f *Fault) Error() string

type Metrics

type Metrics struct {
	AscentTime    int         `json:"ascentTime"`
	Cadence       *Summary    `json:"cad"`
	Calories      int         `json:"calories"`
	CreatedAt     time.Time   `json:"created_at"`
	DescentTime   int         `json:"descentTime"`
	Distance      unit.Length `json:"distance" units:"m"`
	Duration      int         `json:"duration"`
	Elevation     *Summary    `json:"ele"`
	ElevationGain unit.Length `json:"ele_gain" units:"m"`
	ElevationLoss unit.Length `json:"ele_loss" units:"m"`
	EndElevation  unit.Length `json:"endElevation" units:"m"`
	FirstTime     int         `json:"firstTime"`
	Grade         *Summary    `json:"grade"`
	HeartRate     *Summary    `json:"hr"`
	ID            int         `json:"id"`
	MovingPace    float64     `json:"movingPace"`
	MovingTime    int         `json:"movingTime"`
	NumPoints     int         `json:"numPoints"`
	Pace          float64     `json:"pace"`
	ParentID      int         `json:"parent_id"`
	ParentType    string      `json:"parent_type"`
	Speed         *Summary    `json:"speed"`
	Stationary    bool        `json:"stationary"`
	StoppedTime   int         `json:"stoppedTime"`
	UpdatedAt     *time.Time  `json:"updated_at"`
	V             int         `json:"v"`
	VAM           float64     `json:"vam"`
	Watts         *Summary    `json:"watts"`
}

type Option

type Option func(*Client) error

Option provides a configuration mechanism for a Client

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 Summary

type Summary struct {
	Avg    float64 `json:"avg"`
	AvgRaw float64 `json:"_avg"`
	Max    float64 `json:"max"`
	MaxI   float64 `json:"max_i"`
	MaxRaw float64 `json:"_max"`
	Min    float64 `json:"min"`
	MinI   float64 `json:"min_i"`
	MinRaw float64 `json:"_min"`
}

type Task

type Task struct {
	ID        int    `json:"id"`
	Message   string `json:"message"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UserID    int    `json:"user_id"`
	Status    int    `json:"status"`
}

type TrackPoint

type TrackPoint struct {
	Longitude float64     `json:"x"`
	Latitude  float64     `json:"y"`
	Elevation unit.Length `json:"e" units:"m"`
	Distance  unit.Length `json:"d" units:"m"`
	Time      float64     `json:"t"` // seconds since epoch, unix timestamp
	Cadence   float64     `json:"c"`
	Grade     float64     `json:"g"`
	Speed     unit.Speed  `json:"s" units:"kph"`
}

TrackPoint represents data about a point along a trip

type Trip

type Trip struct {
	CreatedAt     time.Time     `json:"created_at"`
	DepartedAt    time.Time     `json:"departed_at"`
	Description   string        `json:"description"`
	Distance      unit.Length   `json:"distance" units:"m"`
	Duration      int           `json:"duration"`
	ElevationGain unit.Length   `json:"elevation_gain" units:"m"`
	ElevationLoss unit.Length   `json:"elevation_loss" units:"m"`
	ID            int64         `json:"id"`
	Name          string        `json:"name"`
	Type          string        `json:"type"`
	TrackID       string        `json:"track_id"`
	TrackPoints   []*TrackPoint `json:"track_points,omitempty"`
	UpdatedAt     time.Time     `json:"updated_at"`
	UserID        UserID        `json:"user_id"`
	Visibility    int           `json:"visibility"`
	FirstLat      float64       `json:"first_lat"`
	FirstLng      float64       `json:"first_lng"`
	LastLat       float64       `json:"last_lat"`
	LastLng       float64       `json:"last_lng"`
	Metrics       *Metrics      `json:"metrics,omitempty"`
}

A Trip represents both a planned and completed activity

func (*Trip) GPX

func (t *Trip) GPX() (*gpx.GPX, error)

type TripsService

type TripsService service

TripsService provides access to Trips and Routes via the RWGPS API

func (*TripsService) Route

func (s *TripsService) Route(ctx context.Context, routeID int64) (*Trip, error)

Route returns a trip for the `routeID`

func (*TripsService) Routes

func (s *TripsService) Routes(ctx context.Context, userID UserID, spec activity.Pagination) ([]*Trip, error)

Routes returns a slice of routes

func (*TripsService) Status

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

Status returns the status of an upload request

func (*TripsService) Trip

func (s *TripsService) Trip(ctx context.Context, tripID int64) (*Trip, error)

Trip returns a trip for the `tripID`

func (*TripsService) Trips

func (s *TripsService) Trips(ctx context.Context, userID UserID, spec activity.Pagination) ([]*Trip, error)

Trips returns a slice of trips

func (*TripsService) Upload

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

Upload the file for the user

type Type

type Type int

Type of the trip

const (
	// TypeTrip is a ride which was recorded by GPS
	TypeTrip Type = iota // trip
	// TypeRoute is a ride which was planned on the RWGPS route builder
	TypeRoute // route
)

func (Type) String

func (i Type) String() string

type Upload

type Upload struct {
	// TaskID of the enqueued request
	TaskID int64 `json:"task_id"`
	// Success is -1 for failed, 0 for pending, 1 for success
	Success int `json:"success"`
	// Tasks is a list of queued tasks and their status
	Tasks []*Task `json:"queued_tasks"`
}

Upload is the state representation of an uploaded activity

func (*Upload) Done

func (u *Upload) Done() bool

func (*Upload) Identifier

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

type User

type User struct {
	ID        UserID `json:"id"`
	Name      string `json:"name"`
	AuthToken string `json:"auth_token"`
}

User is a user

type UserID

type UserID int64
const (
	Me UserID = 0
)

type UsersService

type UsersService service

UsersService provides access to the user API

func (*UsersService) AuthenticatedUser

func (s *UsersService) AuthenticatedUser(ctx context.Context) (*User, error)

AuthenticatedUser returns the authenticated user

Jump to

Keyboard shortcuts

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