doarama

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

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 14 Imported by: 0

README

DEPRECATED

On 2018-08-31, doarama.com moves to ayvri.com with a new API. This client for the Doarama API is deprecated.

go-doarama

Build Status GoDoc Report Card

go-doarama is a Go client library for the Doarama GPS track visualizer.

You should read the Doarama REST API documentation before using this library. You will need to request an API key.

You can view the API documentation at https://godoc.org/github.com/twpayne/go-doarama.

It includes a command line interface in cmd/doarama/.

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

Examples

Constants

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

View Source
const DefaultAPIURL = "https://api.doarama.com/api/0.2"

DefaultAPIURL is the default Doarama API endpoint.

View Source
const Version = "0.2"

Variables

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

func WriteGPX

func WriteGPX(w io.Writer, samples []Sample) error

WriteGPX writes samples to w in GPX format.

func WriteIGC

func WriteIGC(w io.Writer, samples []Sample) error

WriteIGC writes samples to w in IGC format.

Types

type Activity

type Activity struct {
	Client *Client
	ID     int
}

An Activity represents an activity on the server.

func (*Activity) Delete

func (a *Activity) Delete(ctx context.Context) error

Delete deletes the activity.

func (*Activity) Record

func (a *Activity) Record(ctx context.Context, samples []*Sample, altitudeReference string) error

Record records zero or more samples. altitudeReference should normally be "WGS84".

func (*Activity) SetInfo

func (a *Activity) SetInfo(ctx context.Context, activityInfo *ActivityInfo) error

SetInfo sets the info.

func (*Activity) URL

func (a *Activity) URL() string

URL returns the URL for the activity.

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

type ActivityType struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

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) Activity

func (c *Client) Activity(id int) *Activity

Activity returns the activity with the specified id.

func (*Client) ActivityTypes

func (c *Client) ActivityTypes(ctx context.Context) (ActivityTypes, error)

ActivityTypes returns an array of activity types.

func (*Client) Close

func (c *Client) Close() error

Close releases any associated resources.

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 APIKey

func APIKey(apiKey string) ClientOption

APIKey sets the API key.

func APIName

func APIName(apiName string) ClientOption

APIName sets the API name.

func APIURL

func APIURL(apiURL string) ClientOption

APIURL sets the API URL.

func Anonymous

func Anonymous(userID string) ClientOption

Anonymous sets anonymous authentication.

func Delegate

func Delegate(userKey string) ClientOption

Delegate sets delegate authentication.

func HTTPClient

func HTTPClient(httpClient *http.Client) ClientOption

HTTPClient sets the http.Client used for requests.

func UserAgent

func UserAgent(userAgent string) ClientOption

UserAgent sets the user agent.

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 Error

type Error struct {
	HTTPStatusCode int
	HTTPStatus     string
	Status         string
	Message        string
}

An Error represents a Doarama server error.

func (Error) Error

func (e Error) Error() string

Error returns a string representation of the error.

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

func NewTimestamp(t time.Time) Timestamp

NewTimestamp creates a Timestamp from a time.Time.

func (Timestamp) Time

func (ts Timestamp) Time() time.Time

Time returns ts as a time.Time.

type Visualisation

type Visualisation struct {
	Client *Client
	Key    string `json:"key"`
}

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

URL returns a URL with the specificed options.

type VisualisationURLOptions

type VisualisationURLOptions struct {
	Names         []string
	Avatars       []string
	AvatarBaseURL string
	FixedAspect   bool
	MinimalView   bool
	DZML          string
}

A VisualisationURLOptions represents the options that can be set for a visualisation URL.

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.

Jump to

Keyboard shortcuts

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