cloudwebv2

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cloudwebv2 implements the APIs described here http://docs.pacelink.net/cloud/api-web-v2.html

Index

Constants

View Source
const (
	// TripTypeUnset type of the trip is not set by the user
	TripTypeUnset = ""
	// TripTypeBusiness business trip
	TripTypeBusiness = "business"
	// TripTypeWork work trip
	TripTypeWork = "work"
	// TripTypePersonal personal trip
	TripTypePersonal = "personal"
)
View Source
const EndpointDevelopment = "https://cl-1-dev.pacelink.net"

EndpointDevelopment URL for the development environment

View Source
const EndpointProduction = "https://cl-1-prod.pacelink.net"

EndpointProduction URL for the production environment

View Source
const EndpointStaging = "https://cl-1-stage.pacelink.net"

EndpointStaging URL for the staging environment

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*client.Client
}

Client implements a Cloud Web v2 API client

func New

func New(endpoint string) *Client

New creates new client with the passed endpoint

func (*Client) GetTripGroup

func (c *Client) GetTripGroup(ctx context.Context, r *TripGroupRequest) (*TripGroupResponse, error)

GetTripGroup fetches the trips for a certain group identifier

func (*Client) GetTripGroupSamples

GetTripGroupSamples returns the CVS or GPX data for the trip

func (*Client) GetVehiclesStats

GetVehiclesStats returns various car stats calculated for ALL trips belonging to the currently authenticated user’s car.

func (*Client) ListAllTrips

func (c *Client) ListAllTrips(ctx context.Context, r *ListTripsRequest, trips chan<- *Trip) error

ListAllTrips and pushes them into the passed trips channel. The first trip (oldest trip) will be pushed first the last trip (newest) will be pushed last.

func (*Client) ListTrips

func (c *Client) ListTrips(ctx context.Context, r *ListTripsRequest) (*ListTripsResponse, error)

ListTrips returns a list of trips for the current user and the given VIN

type EcoEventCounts

type EcoEventCounts struct {
	Rpm          int `json:"rpm,omitempty"`
	Acceleration int `json:"acceleration,omitempty"`
	Braking      int `json:"braking,omitempty"`
	Idle         int `json:"idle,omitempty"`
	Speeding     int `json:"speeding,omitempty"`
}

EcoEventCounts for a single car

type GeoEvent

type GeoEvent struct {
	Type       string              `json:"type,omitempty"`
	Geometry   *GeoJSON            `json:"geometry,omitempty"`
	Properties *GeoEventProperties `json:"properties,omitempty"`
}

GeoEvent combines the geo location and its event data

type GeoEventProperties

type GeoEventProperties struct {
	Type        string  `json:"type,omitempty"`
	ElapsedTime float64 `json:"elapsed_time,omitempty"`
}

GeoEventProperties custom properties for the geo event

type GeoJSON

type GeoJSON struct {
	Type        string    `json:"type,omitempty"`
	Coordinates []float64 `json:"coordinates,omitempty"`
}

GeoJSON geo json object as defined in http://geojson.org/

type GeoScore

type GeoScore struct {
	ElapsedTime float64 `json:"elapsed_time,omitempty"`
	Latitude    float64 `json:"latitude,omitempty"`
	Longitude   float64 `json:"longitude,omitempty"`
	Score       float64 `json:"score,omitempty"`
}

GeoScore pace scoring for the specified Latitude and Longitude

type GetTripGroupSamplesRequest

type GetTripGroupSamplesRequest struct {
	UniqueIdentifier string
	GroupIdentifier  string // (required) group_identifer of the trips the trip samples are for.
	Format           TripSamplesFormat
}

GetTripGroupSamplesRequest contains the request parameters

func (*GetTripGroupSamplesRequest) Query

Query converts the request data into query parameters

type GetTripGroupSamplesResponse

type GetTripGroupSamplesResponse struct {
	Rows []*TripSampleRow
}

GetTripGroupSamplesResponse contains the trip sample data

type GetVehiclesStatsRequest

type GetVehiclesStatsRequest struct {
	UniqueIdentifier string    // Unique identifier for this user
	Vin              string    // VIN of car to get stats for
	StartAt          time.Time // Needs to be younger than EndAt
	EndAt            time.Time // Needs to be older than StartAt
}

GetVehiclesStatsRequest for various car stats calculated for ALL trips in time frame.

start_at and end_at may seem to be switched but we decided to use the go-back-in-time principle. This makes more sense when looking at the trips itself but we wanted this to be aligned with the cloud app api.

Although start_at and end_at are both optional, they are mutually required, that is, if one is provided, the other must also. Otherwise the sole value sent will be ignored.

This includes all trips with status ready. Ongoing trips or somewhy unfinished trips are not being counted.

func (*GetVehiclesStatsRequest) Query

func (r *GetVehiclesStatsRequest) Query() url.Values

Query generate the query based on the request data

type GetVehiclesStatsResponse

type GetVehiclesStatsResponse struct {
	CurrentMileage          int                 `json:"current_mileage,omitempty"`
	TripCountTotal          int                 `json:"trip_count_total,omitempty"`
	TripCountBusiness       int                 `json:"trip_count_business,omitempty"`
	TripCountPersonal       int                 `json:"trip_count_personal,omitempty"`
	TripCountWork           int                 `json:"trip_count_work,omitempty"`
	RefuelCostsInCents      int                 `json:"refuel_costs_in_cents,omitempty"`
	AvgSpeedInKmPerH        float64             `json:"avg_speed_in_km_per_h,omitempty"`
	MaxSpeedInKmPerH        float64             `json:"max_speed_in_km_per_h,omitempty"`
	AvgDistanceInKm         float64             `json:"avg_distance_in_km,omitempty"`
	MaxDistanceInKm         float64             `json:"max_distance_in_km,omitempty"`
	TotalDistanceInKm       float64             `json:"total_distance_in_km,omitempty"`
	AvgEcoScore             float64             `json:"avg_eco_score,omitempty"`
	AvgFuelUsagePer100Km    float64             `json:"avg_fuel_usage_per_100_km,omitempty"`
	AvgCostsInCentsPer100Km int                 `json:"avg_costs_in_cents_per_100_km,omitempty"`
	AvgDurationInS          int                 `json:"avg_duration_in_s,omitempty"`
	MaxDurationInS          int                 `json:"max_duration_in_s,omitempty"`
	KilometersDriven        []*KilometersDriven `json:"kilometers_driven,omitempty"`
	EcoEventCounts          *EcoEventCounts     `json:"eco_event_counts,omitempty"`
	TroubleCodesCount       int                 `json:"trouble_codes_count,omitempty"`
	FirstRecordedMileageInM int                 `json:"first_recorded_mileage_in_m,omitempty"`
	AvgMonthlyDistanceInM   int                 `json:"avg_monthly_distance_in_m,omitempty"`
	CurrentMileageInM       int                 `json:"current_mileage_in_m,omitempty"`
}

GetVehiclesStatsResponse for a single car

type KilometersDriven

type KilometersDriven struct {
	Date     string `json:"date,omitempty"`
	Business int    `json:"business,omitempty"`
	Personal int    `json:"personal,omitempty"`
	Work     int    `json:"work,omitempty"`
	Unset    int    `json:"unset,omitempty"`
}

KilometersDriven for a single car

type ListTripsRequest

type ListTripsRequest struct {
	Vin              string    // vehicle identification number
	UniqueIdentifier string    // unique identifier of the user
	StartAt          time.Time //	The point in time at which to scope trips to, going into the past
	EndAt            time.Time //	scope trips up to this point in time. When passing end_at you’ll get back all trips between start_at and end_at.
	ContinueAt       time.Time // Time at which to continue on from for pagination
	Attributes       []string  // Filter the list of attributes you want to get back for each trip. For instance, if you specify attributes=vin,uuid, you will only get the vin and the uuid (applies to all trips in the collection).
	TripType         TripType  // Filter by trip type
	Limit            int       // The exact number of trips which the cloud will return.
	Mode             ListTripsRequestMode
	// Order define the order in which trips will be returned.
	// NOTE: If you sort by ASC the cloud will respond with the oldest trips first. Also sorting defaults to DESC when not otherwise specified therefore sending DESC is redundant.
	// Returns a 400 error if the value is neither of these two.
	Order Order
}

ListTripsRequest request for ListTrips

func (*ListTripsRequest) Query

func (r *ListTripsRequest) Query() url.Values

Query generates a HTTP query based on the request data

type ListTripsRequestMode

type ListTripsRequestMode string

ListTripsRequestMode accepts all_pages or single_page, defaults to single_page

const (
	// ModeAllPages returns all of the pages up to the continue at plus 25 trips
	ModeAllPages ListTripsRequestMode = "all_pages"
	// ModeSinglePage returns the next 25 trips from continue_at onwards.
	ModeSinglePage ListTripsRequestMode = "single_page"
)

type ListTripsResponse

type ListTripsResponse struct {
	Trips []*Trip `json:"trips"`
}

ListTripsResponse response for ListTrips

type Order

type Order string

Order accepts either ASC or DESC

const (
	// OrderASC order asc
	OrderASC Order = "ASC"
	// OrderDESC order desc
	OrderDESC Order = "DESC"
)

type Trip

type Trip struct {
	ID                  int             `json:"id,omitempty"`
	UUID                string          `json:"uuid,omitempty"`
	Vin                 string          `json:"vin,omitempty"`
	StartMileage        int             `json:"start_mileage,omitempty"`
	StartMileageInM     int             `json:"start_mileage_in_m,omitempty"`
	StartTime           client.UnixTime `json:"start_time,omitempty"`
	EndMileage          int             `json:"end_mileage,omitempty"`
	EndMileageInM       int             `json:"end_mileage_in_m,omitempty"`
	EndTime             client.UnixTime `json:"end_time,omitempty"`
	GroupIdentifier     string          `json:"group_identifier,omitempty"`
	Status              TripStatus      `json:"status,omitempty"`
	TripType            string          `json:"trip_type,omitempty"`
	DriverName          string          `json:"driver_name,omitempty"`
	StartAddress        *TripAddress    `json:"start_address,omitempty"`
	EndAddress          *TripAddress    `json:"end_address,omitempty"`
	StartPosition       *TripPosition   `json:"start_position,omitempty"`
	EndPosition         *TripPosition   `json:"end_position,omitempty"`
	BusinessReason      string          `json:"business_reason,omitempty"`
	BusinessPartnerName string          `json:"business_partner_name,omitempty"`
	Stats               *TripStats      `json:"stats,omitempty"`
	EcoScores           *TripEcoScores  `json:"eco_scores,omitempty"`
	SafetyScore         float64         `json:"safety_score,omitempty"`
	ManuallyCreated     bool            `json:"manually_created,omitempty"`
	UpdatedAt           client.UnixTime `json:"updated_at,omitempty"`
	GeoScore            []*GeoScore     `json:"geo,omitempty"`
	Events              []*GeoEvent     `json:"events,omitempty"`
}

Trip individual trip of a user

type TripAddress

type TripAddress struct {
	Name             string `json:"name,omitempty"`
	SourceIdentifier string `json:"source_identifier,omitempty"`
	Street           string `json:"street,omitempty"`
	HouseNumber      string `json:"house_number,omitempty"`
	Zip              string `json:"zip,omitempty"`
	Suburb           string `json:"suburb,omitempty"`
	State            string `json:"state,omitempty"`
	City             string `json:"city,omitempty"`
	Country          string `json:"country,omitempty"`
	AddressType      string `json:"address_type,omitempty"`
}

TripAddress of trip start and end address

type TripEcoScores

type TripEcoScores struct {
	RpmScore          float64 `json:"rpm_score,omitempty"`
	AccelerationScore float64 `json:"acceleration_score,omitempty"`
	BrakingScore      float64 `json:"braking_score,omitempty"`
	IdleScore         float64 `json:"idle_score,omitempty"`
	SpeedingScore     float64 `json:"speeding_score,omitempty"`
	TotalScore        float64 `json:"total_score,omitempty"`
}

TripEcoScores of a trip

type TripGroupRequest

type TripGroupRequest struct {
	GroupIdentifier  string // UUID of the trip group
	UniqueIdentifier string // unique identifier of the user
}

TripGroupRequest for trip groups with eco events

func (*TripGroupRequest) Query

func (r *TripGroupRequest) Query() url.Values

Query generates a HTTP query based on the request data

type TripGroupResponse

type TripGroupResponse struct {
	Trips []*Trip `json:"trips,omitempty"`
}

TripGroupResponse contains trips for a group and their eco events

type TripPosition

type TripPosition struct {
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
	Altitude  float64 `json:"altitude,omitempty"`
}

TripPosition of trip start and end position

type TripSampleRow

type TripSampleRow struct {
	AcclPitch         float64 `csv:"Gyroscope Pitch" json:"gyroscope_pitch,omitempty"`
	AcclRoll          float64 `csv:"Gyroscope Roll" json:"gyroscope_roll,omitempty"`
	AcclYaw           float64 `csv:"Gyroscope Yaw" json:"gyroscope_roll_yaw,omitempty"`
	AcclX             float64 `csv:"Accelerometer X" json:"accelerometer_x,omitempty"`
	AcclY             float64 `csv:"Accelerometer Y" json:"accelerometer_y,omitempty"`
	AcclZ             float64 `csv:"Accelerometer Z" json:"accelerometer_z,omitempty"`
	ElapsedKilometers float64 `csv:"Elapsed distance" json:"elapsed_kilometers,omitempty"`
	ElapsedTime       float64 `csv:"Elapsed time" json:"elapsed_time,omitempty"`
	PosAlt            float64 `csv:"GPS Altitude" json:"pos_alt,omitempty"`
	PosLat            float64 `csv:"GPS Latitude" json:"pos_lat,omitempty"`
	PosLon            float64 `csv:"GPS Longitude" json:"pos_lon,omitempty"`
	Speed             float64 `csv:"Speed" json:"speed,omitempty"`
	FuelUsage         float64 `csv:"Consumed fuel" json:"fuel_usage,omitempty"`
	Rpm               int     `csv:"RPM" json:"rpm,omitempty"`
}

TripSampleRow single trip data sample

type TripSamplesFormat

type TripSamplesFormat int

TripSamplesFormat format for the trip samples

const (
	// TripSamplesCSV Get all trip samples for a trip group in CSV  ¶
	TripSamplesCSV TripSamplesFormat = iota
	// TripSamplesGPX  GPX tracks of trip samples for a given trip.
	// This can be used to replay trips in XCode and will be used most
	// likely for debugging purposes of the mobile development teams.
	TripSamplesGPX
)

type TripStats

type TripStats struct {
	AvgSpeedInKmPerH     float64 `json:"avg_speed_in_km_per_h,omitempty"`
	AvgRpm               float64 `json:"avg_rpm,omitempty"`
	MaxSpeedInKmPerH     float64 `json:"max_speed_in_km_per_h,omitempty"`
	MaxRpm               float64 `json:"max_rpm,omitempty"`
	DistanceInKm         float64 `json:"distance_in_km,omitempty"`
	DistanceInM          int     `json:"distance_in_m"`
	CostInCents          float64 `json:"cost_in_cents,omitempty"`
	DurationInS          float64 `json:"duration_in_s,omitempty"`
	AvgFuelUsagePer100Km float64 `json:"avg_fuel_usage_per_100_km,omitempty"`
}

TripStats of a trip

type TripStatus

type TripStatus int

TripStatus a trip has a status, reflecting its processing state

const (
	// Started trip has started and is still ongoing
	Started TripStatus = iota
	// Finished trip has ended; data processing pending
	Finished
	// Processing trip data is being processed; displayed data still may change
	Processing
	// Ready all data has been processed
	Ready
)

func (TripStatus) MarshalJSON

func (r TripStatus) MarshalJSON() ([]byte, error)

MarshalJSON is generated so TripStatus satisfies json.Marshaler.

func (TripStatus) String

func (r TripStatus) String() string

func (*TripStatus) UnmarshalJSON

func (r *TripStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON is generated so TripStatus satisfies json.Unmarshaler.

type TripType

type TripType string

TripType accepts the values business, work, personal, unset

Jump to

Keyboard shortcuts

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