Documentation ¶
Overview ¶
Package doarama provides a client to doarama.com's API. See http://www.doarama.com/api/0.2/docs.
Example ¶
// Create the client using anonymous authentication client := doarama.NewClient( doarama.APIKey("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), doarama.APIName("Your API Name"), doarama.Anonymous("userid"), ) // Open the GPS track filename := "activity GPS filename (GPX or IGC)" gpsTrack, err := os.Open(filename) if err != nil { return } defer gpsTrack.Close() ctx := context.Background() // Create the activity activity, err := client.CreateActivity(ctx, filepath.Base(filename), gpsTrack) if err != nil { return } log.Printf("ActivityId: %d", activity.ID) // Set the activity info if err := activity.SetInfo(ctx, &doarama.ActivityInfo{ TypeID: doarama.FlyParaglide, }); err != nil { return } // Create the visualisation activities := []*doarama.Activity{activity} visualisation, err := client.CreateVisualisation(ctx, activities) if err != nil { return } log.Printf("VisualisationKey: %s", visualisation.Key) log.Printf("VisualisationURL: %s", visualisation.URL(nil))
Output:
Index ¶
- Constants
- Variables
- func WriteGPX(w io.Writer, samples []Sample) error
- func WriteIGC(w io.Writer, samples []Sample) error
- type Activity
- type ActivityInfo
- type ActivityType
- type ActivityTypes
- type Client
- func (c *Client) Activity(id int) *Activity
- func (c *Client) ActivityTypes(ctx context.Context) (ActivityTypes, error)
- func (c *Client) Close() error
- func (c *Client) CreateActivity(ctx context.Context, filename string, gpsTrack io.Reader) (*Activity, error)
- func (c *Client) CreateActivityWithInfo(ctx context.Context, filename string, gpsTrack io.Reader, ...) (*Activity, error)
- func (c *Client) CreateLiveActivity(ctx context.Context, startLatitude, startLongitude float64, ...) (*Activity, error)
- func (c *Client) CreateVisualisation(ctx context.Context, activities []*Activity) (*Visualisation, error)
- func (c *Client) Visualisation(key string) *Visualisation
- type ClientOption
- func APIKey(apiKey string) ClientOption
- func APIName(apiName string) ClientOption
- func APIURL(apiURL string) ClientOption
- func Anonymous(userID string) ClientOption
- func Delegate(userKey string) ClientOption
- func HTTPClient(httpClient *http.Client) ClientOption
- func UserAgent(userAgent string) ClientOption
- type Coords
- type ErrAmbiguousActivityType
- type ErrUnknownActivityType
- type Error
- type Sample
- type Timestamp
- type Visualisation
- type VisualisationURLOptions
Examples ¶
Constants ¶
const ( BoatCanoe = 10 BoatKayak = 10 BoatMotor = 9 BoatRow = 10 BoatSail = 8 CycleMountain = 6 CycleOffRoad = 6 CycleRoad = 4 CycleSport = 4 CycleTransport = 5 DriveBus = 24 DriveCar = 24 DriveTruck = 24 FlyAircraft = 12 FlyAves = 31 FlyBalloon = 34 FlyBird = 31 FlyDrone = 30 FlyGlide = 11 FlyGlider = 28 FlyHangGlide = 27 FlyHikeAndGlide = 35 FlyParaglide = 29 FlySailplane = 28 FlyUAV = 30 Motorcycle = 7 RailTrain = 25 RideCamel = 26 RideEquestrian = 26 RunFitness = 3 SkateIce = 18 SkateRoller = 19 SkateScooter = 19 SkateSkateboard = 19 SkateWindskate = 32 SkiCrossCountry = 13 SkiDownhill = 14 SkiRoller = 15 SkiWakeboard = 16 SkiWaterski = 16 Snowboard = 17 SurfKite = 21 SurfWave = 20 SurfWindsurf = 22 Swim = 23 UndefinedAerial = 33 UndefinedGroundBased = 0 WalkFitness = 1 WalkHike = 2 WalkTrek = 2 )
Activity types
const DefaultAPIURL = "https://api.doarama.com/api/0.2"
DefaultAPIURL is the default Doarama API endpoint.
const Version = "0.2"
Variables ¶
var DefaultActivityTypes = ActivityTypes{
{ID: 0, Name: "Undefined - Ground Based"},
{ID: 1, Name: "Walk - Fitness"},
{ID: 2, Name: "Walk - Hike/Trek etc"},
{ID: 3, Name: "Run - Fitness"},
{ID: 4, Name: "Cycle - Sport/Road etc"},
{ID: 5, Name: "Cycle - Transport"},
{ID: 6, Name: "Cycle - Mountain/Off Road etc"},
{ID: 7, Name: "Motorcycle"},
{ID: 8, Name: "Boat - Sail"},
{ID: 9, Name: "Boat - Motor"},
{ID: 10, Name: "Boat - Kayak/Canoe/Row etc"},
{ID: 11, Name: "Fly - Glide"},
{ID: 12, Name: "Fly - Aircraft"},
{ID: 13, Name: "Ski - Cross Country"},
{ID: 14, Name: "Ski - Downhill"},
{ID: 15, Name: "Ski - Roller"},
{ID: 16, Name: "Ski - Waterski/Wakeboard etc"},
{ID: 17, Name: "Snowboard"},
{ID: 18, Name: "Skate - Ice"},
{ID: 19, Name: "Skate - Roller/Skateboard/Scooter etc"},
{ID: 20, Name: "Surf - Wave"},
{ID: 21, Name: "Surf - Kite"},
{ID: 22, Name: "Surf - Windsurf"},
{ID: 23, Name: "Swim"},
{ID: 24, Name: "Drive - Car/Truck/Bus etc"},
{ID: 25, Name: "Rail - Train"},
{ID: 26, Name: "Ride - Equestrian/Camel etc"},
{ID: 27, Name: "Fly - Hang Glide"},
{ID: 28, Name: "Fly - Sailplane / Glider"},
{ID: 29, Name: "Fly - Paraglide"},
{ID: 30, Name: "Fly - UAV / Drone"},
{ID: 31, Name: "Fly - Bird / Aves"},
{ID: 32, Name: "Skate - Windskate"},
{ID: 33, Name: "Undefined - Aerial"},
{ID: 34, Name: "Fly - Balloon"},
{ID: 35, Name: "Fly - Hike + Glide"},
}
DefaultActivityTypes contains the default activity types.
Functions ¶
Types ¶
type Activity ¶
An Activity represents an activity on the server.
func (*Activity) Record ¶
Record records zero or more samples. altitudeReference should normally be "WGS84".
type ActivityInfo ¶
type ActivityInfo struct { TypeID int `json:"activityTypeId,omitempty"` UserName string `json:"userName,omitempty"` UserAvatarURL string `json:"userAvatarUrl,omitempty"` }
An ActivityInfo represents the info associated with an activity.
type ActivityType ¶
An ActivityType is an activity type.
type ActivityTypes ¶
type ActivityTypes []ActivityType
An ActivityTypes is an array of ActivityTypes.
func (ActivityTypes) Find ¶
func (ats ActivityTypes) Find(s string) (ActivityType, error)
Find returns the activity type that most closely matches s.
func (ActivityTypes) FindByID ¶
func (ats ActivityTypes) FindByID(id int) (ActivityType, bool)
FindByID returns the activity type with the given id.
func (ActivityTypes) FindByName ¶
func (ats ActivityTypes) FindByName(name string) (ActivityType, bool)
FindByName returns the activity type with the given name.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client is an opaque type for a Doarama client.
func NewClient ¶
func NewClient(options ...ClientOption) *Client
NewClient creates a new unauthenticated Doarama client.
func (*Client) ActivityTypes ¶
func (c *Client) ActivityTypes(ctx context.Context) (ActivityTypes, error)
ActivityTypes returns an array of activity types.
func (*Client) CreateActivity ¶
func (c *Client) CreateActivity(ctx context.Context, filename string, gpsTrack io.Reader) (*Activity, error)
CreateActivity creates a new activity.
func (*Client) CreateActivityWithInfo ¶
func (c *Client) CreateActivityWithInfo(ctx context.Context, filename string, gpsTrack io.Reader, activityInfo *ActivityInfo) (*Activity, error)
CreateActivityWithInfo creates a new doarama.Activity with the specified doarama.ActivityInfo.
func (*Client) CreateLiveActivity ¶
func (c *Client) CreateLiveActivity(ctx context.Context, startLatitude, startLongitude float64, startTime Timestamp) (*Activity, error)
CreateLiveActivity creates a new live activity.
func (*Client) CreateVisualisation ¶
func (c *Client) CreateVisualisation(ctx context.Context, activities []*Activity) (*Visualisation, error)
CreateVisualisation creates a new visualiztion.
func (*Client) Visualisation ¶
func (c *Client) Visualisation(key string) *Visualisation
Visualisation returns the visualisation with the specified key.
type ClientOption ¶
type ClientOption func(*Client)
An ClientOption sets an option on a client.
func Anonymous ¶
func Anonymous(userID string) ClientOption
Anonymous sets anonymous authentication.
func HTTPClient ¶
func HTTPClient(httpClient *http.Client) ClientOption
HTTPClient sets the http.Client used for requests.
type Coords ¶
type Coords struct { Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` Altitude float64 `json:"altitude"` AltitudeAccuracy float64 `json:"altitudeAccuracy"` Speed float64 `json:"speed"` Heading float64 `json:"heading"` }
A Coords represents a coordinate.
type ErrAmbiguousActivityType ¶
type ErrAmbiguousActivityType struct { S string Matches []ActivityType }
An ErrAmbiguousActivityType is returned when an activity type is ambiguous.
func (*ErrAmbiguousActivityType) Error ¶
func (e *ErrAmbiguousActivityType) Error() string
Error implements error.
type ErrUnknownActivityType ¶
type ErrUnknownActivityType struct {
S string
}
An ErrUnknownActivityType is returned when an activity type is unknown.
func (*ErrUnknownActivityType) Error ¶
func (e *ErrUnknownActivityType) Error() string
type Sample ¶
type Sample struct { Time Timestamp `json:"time"` Coords Coords `json:"coords"` UserData map[string]interface{} `json:"userData,omitempty"` }
A Sample represents a live sample.
type Timestamp ¶
type Timestamp int64
A Timestamp represents at Doarama timestamp. Doarama timestamps are in milliseconds since the epoch.
func NewTimestamp ¶
NewTimestamp creates a Timestamp from a time.Time.
type Visualisation ¶
A Visualisation represents a visualisation on the server.
func (*Visualisation) AddActivities ¶
func (v *Visualisation) AddActivities(ctx context.Context, activities []*Activity) error
AddActivities adds the activities to the visualisation.
func (*Visualisation) URL ¶
func (v *Visualisation) URL(vo *VisualisationURLOptions) *url.URL
URL returns a URL with the specificed options.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
generate-activity-types
FIXME there must be a better way to pad constants in templates
|
FIXME there must be a better way to pad constants in templates |
Package doaramacache provides caching of Doarama activities.
|
Package doaramacache provides caching of Doarama activities. |
Package doaramacli provides integration between github.com/twpayne/go-doarama and github.com/urfave/cli.
|
Package doaramacli provides integration between github.com/twpayne/go-doarama and github.com/urfave/cli. |