wappa

package module
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RideStatusSearchingForDriver = "searching-for-driver"
	RideStatusDriverNotFound     = "driver-not-found"
	RideStatusCancelled          = "ride-cancelled"
	RideStatusDriverFound        = "driver-found"
	RideStatusWaitingForDriver   = "waiting-for-driver"
	RideStatusInProgress         = "on-ride"
	RideStatusPaid               = "ride-paid"
	RideStatusCompleted          = "ride-completed"
)

Ride statuses.

View Source
const (
	RideCancelledByUser   = "1"
	RideCancelledByDriver = "2"
	RideCancelledBySystem = "3"
)

Cancelled By

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	City     string   `json:"city"`
	State    string   `json:"state"`
	Country  string   `json:"country"`
	Address  string   `json:"address"`
	Location Location `json:"location"`
}

type ApiError

type ApiError struct {
	// contains filtered or unexported fields
}

ApiError implements the error interface and returns infos from the request.

func (*ApiError) Error

func (e *ApiError) Error() string

type Base

type Base struct {
	ID          int    `json:"id"`
	Description string `json:"description"`
}

Base represents a generic type for describing a resource with an ID an Description attributes.

type CancellationReasonResult

type CancellationReasonResult struct {
	Reasons []Base `json:"reasons"`
}

CancellationReasonResult represents the response of listing the cancellation reason of rides.

type Category

type Category struct {
	ID            int           `json:"id"`
	Description   string        `json:"description"`
	SubCategories []SubCategory `json:"subcategories"`
}

The categories available for the region requested.

type Client

type Client struct {

	// Services implemented
	Driver   *DriverService
	Employee *EmployeeService
	Quote    *QuoteService
	Ride     *RideService
	Webhook  *WebhookService
	// contains filtered or unexported fields
}

Client is responsible for handling requests to the Wappa API.

func NewClient added in v2.0.1

func NewClient(host *url.URL, client *http.Client) *Client

NewClient returns a new Wappa API client with provided host URL and HTTP client.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method string, path endpoint, body, output interface{}) error

Request created an API request. A relative path can be providaded in which case it is resolved relative to the host of the Client.

func (*Client) Status

func (c *Client) Status(ctx context.Context) (ok bool, err error)

Status returns the API status.

type Driver

type Driver struct {
	Name    string `json:"name"`
	DDD     string `json:"ddd"`
	Phone   string `json:"phone"`
	Vehicle Vehicle
}

type DriverLocation

type DriverLocation struct {
	Location

	Bearing float64 `json:"bearing,omitempty"`
	Type    int     `json:"typeId,omitempty"`
}

DriverLocation is the struct representing the driver location entity in the API.

type DriverResult

type DriverResult struct {
	Result

	Drivers []*DriverLocation `json:"drivers"`
}

DriverResult is the API response payload.

type DriverService

type DriverService service

DriverService is responsible for handling the requests to the driver resource.

func (*DriverService) Nearby

func (ds *DriverService) Nearby(ctx context.Context, f Filter) (*DriverResult, error)

Nearby returns the driver of a given type that are closest to the given coordinates.

type Duration added in v2.1.1

type Duration struct {
	time.Duration
}

Duration is a time duration represented as hh:mm:ss.

func (*Duration) UnmarshalJSON added in v2.1.1

func (d *Duration) UnmarshalJSON(b []byte) (err error)

type DurationMin added in v2.1.0

type DurationMin struct {
	time.Duration
}

DurationMin is a custom minutes duration type for unmashaling data from the API.

func (*DurationMin) UnmarshalJSON added in v2.1.0

func (d *DurationMin) UnmarshalJSON(b []byte) (err error)

type DurationSec added in v2.1.0

type DurationSec struct {
	time.Duration
}

DurationSec is a custom seconds duration type for unmashaling data from the API.

func (*DurationSec) UnmarshalJSON added in v2.1.0

func (d *DurationSec) UnmarshalJSON(b []byte) (err error)

type Employee

type Employee struct {
	ID           int    `json:"employeeId"`
	Email        string `json:"email"`
	DDD          string `json:"ddd"`
	Phone        string `json:"phone"`
	Registration string `json:"registration"`
}

Employe is the struct representing the employee entity in the API.

type EmployeeLastRidesResult

type EmployeeLastRidesResult struct {
	Result

	History []*RideHistory `json:"history"`
}

EmployeeLastRidesResult represents the up to 100 last employee last rides.

type EmployeeResult

type EmployeeResult struct {
	Employees []*Employee `json:"employees"`
}

WebhookResult is the API response payload.

type EmployeeService

type EmployeeService service

EmployeeService is responsible for handling the requests to the webhook resource.

func (*EmployeeService) LastRides

LastRides returns up to 100 last rides of a given employee.

func (*EmployeeService) Read

Read returns the list of employees associated with the credentials.

func (*EmployeeService) Status

func (es *EmployeeService) Status(ctx context.Context, id int) (*EmployeeStatusResult, error)

Status returns the current status of employees in the API.

type EmployeeStatusResult

type EmployeeStatusResult struct {
	// The ride id if the current ride.
	RideID int `json:"rideId"`
	// Employee ride status.
	// Possible values: Free, AwaitingPickup, OnRide, RideCompleted or OnAuction.
	Status string `json:"status"`
}

EmployeeStatusResult represents the current status of the employee.

type Estimate

type Estimate struct {
	Minimum      float64     `json:"minimum"`
	Maximum      float64     `json:"maximum"`
	Distance     float64     `json:"distance"` // Measured in KM.
	Journey      DurationMin `json:"journey"`
	TimeToPickup DurationSec `json:"timeToPickupValue"`
}

type Filter

type Filter map[string][]string

Filter is used to filter the requests to the API.

func (Filter) Values

func (f Filter) Values(fields map[string]string) url.Values

Values returns a url.Values mapped between Filter and values.

type HistoricalCategory

type HistoricalCategory struct {
	Base

	Type        Base `json:"type"`
	SubCategory Base `json:"subcategory"`
}

type HistoricalDriver

type HistoricalDriver struct {
	Driver

	Category HistoricalCategory `json:"category"`
	Photo    string             `json:"photo"`
}

type HistoricalRideInfo

type HistoricalRideInfo struct {
	Status            string  `json:"status"`
	StartedAt         *Time   `json:"rideDate"`
	EndedAt           *Time   `json:"finishDate"`
	PaidAt            *Time   `json:"paymentDate"`
	MapURL            string  `json:"rideMapURL"`
	CancelledBy       string  `json:"cancelledBy"`
	CancelledReason   string  `json:"cancelledReason"`
	Value             float64 `json:"rideValue"`
	OriginalValue     float64 `json:"rideOriginalValue"`
	DIscount          float64 `json:"rideDiscount"`
	ExternalID        int     `json:"externalId"`
	DurationInSeconds int     `json:"durationInSeconds"`
	Distance          int     `json:"distance"`
}

HistoricalRideInfo represents a historical information about a ride made by the employee

type Icon

type Icon struct {
	Default string `json:"default"`
	OnFocus string `json:"onFocus"`
	Pin     string `json:"pin"`
}

type Location

type Location struct {
	Lat float64 `json:"latitude"`
	Lng float64 `json:"longitude"`
}

type Passenger

type Passenger struct {
	ID    int    `json:"employeeId"`
	Name  string `json:"name"`
	DDD   string `json:"ddd"`
	Phone string `json:"phone"`
}

type QRCodeResult

type QRCodeResult struct {
	Result

	QRCode string `json:"qrcode"`
}

QRCode represents a result payload when generating a QR code.

type QuoteResult

type QuoteResult struct {
	Categories  []*Category `json:"categories"`
	EstimatedAt *time.Time  `json:"date"`
}

DriverResult is the API response payload.

type QuoteService

type QuoteService service

QuoteService is responsible for handling the requests to the quote resource.

func (*QuoteService) Estimate

func (qs *QuoteService) Estimate(ctx context.Context, f Filter) (*QuoteResult, error)

Estimate returns a quote for a ride with the given parameters.

type ResponseError

type ResponseError struct {
	Code    int
	Message int
}

ResponseError contains the default error porperties returnes by the API.

type Result

type Result struct {
	Success bool
	Error   ResponseError
	// Returned by the API when error occurs
	Message string
}

Result contains the base porperties all requests to the Wappa API returns.

type Ride

type Ride struct {
	EmployeeID             int     `json:"employeeId"`
	TaxiTypeID             int     `json:"taxiTypeId"`
	TaxiCategoryID         int     `json:"taxiCategoryId"`
	LatOrigin              float64 `json:"latitudeOrigin"`
	LngOrigin              float64 `json:"longitudeOrigin"`
	LatDestiny             float64 `json:"latitudeDestiny"`
	LngDestiny             float64 `json:"longitudeDestiny"`
	OriginRef              string  `json:"originReference,omitempty"`
	ExternalID             string  `json:"externalId,omitempty"`
	PassengerPhoneAreaCode string  `json:"passengerPhoneAreaCode,omitempty"`
	PassengerPhoneNumber   string  `json:"passengerPhoneNumber,omitempty"`
}

Ride is the struct representing the ride entity in the API.

type RideHistory

type RideHistory struct {
	ID        int                `json:"rideId"`
	CompanyID int                `json:"companyId"`
	Passenger Passenger          `json:"passenger"`
	Origin    Address            `json:"origin"`
	Destiny   Address            `json:"destiny"`
	Driver    HistoricalDriver   `json:"driver"`
	Info      HistoricalRideInfo `json:"rideInfo"`
}

RideHistory represents the historical information of a ride.

type RideInfo

type RideInfo struct {
	// Possible values of Status:
	//  - searching-for-driver
	//  - driver-not-found
	//  - ride-cancelled
	//  - driver-found
	//  - waiting-for-driver
	//  - on-ride
	//  - ride-paid
	//  - ride-completed
	Status         string     `json:"status"`
	DriverLocation Location   `json:"driverLocation"`
	ToOrigin       TravelInfo `json:"toOrigin"`
	ToDestiny      TravelInfo `json:"toDestiny"`
	// The agent that canceled the ride.
	// Passenger = 1, Driver = 2, System = 3
	CancelledBy string `json:"cancelledBy"`
	// The reason that the ride was canceled for.
	CancalledReason string `json:"cancelledReason"`
	// The ride value, if available.
	RideValue float64 `json:"rideValue"`
	// The external ID provided when the ride was requested.
	ExternalID string `json:"externalId"`
}

type RideResult

type RideResult struct {
	Result

	ID        int       `json:"rideID"`
	Passenger Passenger `json:"passenger"`
	Origin    Address   `json:"origin"`
	Destiny   Address   `json:"destiny"`
	Driver    Driver    `json:"driver"`
	Info      RideInfo  `json:"rideInfo"`
}

DriverResult is the API response payload.

type RideService

type RideService service

RideService is responsible for handling the requests to the ride resource.

func (*RideService) Cancel

func (rs *RideService) Cancel(ctx context.Context, ride int, reason int) (*Result, error)

Cancel cancels a ride request.

func (*RideService) CancellationReason

func (rs *RideService) CancellationReason(ctx context.Context) (*CancellationReasonResult, error)

CancellationReason returns the list of possible reasons a user can choose when cancelling a ride.

func (*RideService) Create

func (rs *RideService) Create(ctx context.Context, r *Ride) (*RideResult, error)

Create creates a new ride in the API.

func (*RideService) QRCode

func (rs *RideService) QRCode(ctx context.Context, f Filter) (*QRCodeResult, error)

QRCode returns a string that when displayed as a QR code can be used on the "Embarque Imediato" feature.

func (*RideService) Rate

func (rs *RideService) Rate(ctx context.Context, ride int, rating int) (*Result, error)

Rate created an experience rating of a ride.

func (*RideService) Read

func (rs *RideService) Read(ctx context.Context, f Filter) (*RideResult, error)

Read returns the info of a ride.

type SubCategory

type SubCategory struct {
	ID          int      `json:"id"`
	TypeID      int      `json:"typeId"`
	Default     bool     `json:"default"`
	Description string   `json:"description"`
	Discount    float64  `json:"discount"`
	Estimate    Estimate `json:"estimate"`
	Observation string   `json:"observation"`
	Icon        Icon     `json:"icon"`
}

The available subcategories for this category.

type Time

type Time struct {
	time.Time
}

Time is a custom time type for unmashaling data from the API.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

type TokenSource

type TokenSource struct {
	// contains filtered or unexported fields
}

TokenSource implements the oauth2.TokenSource interface, in order to reuse the Wappa token.

func NewTokenSource

func NewTokenSource(ctx context.Context, host, username, password string) *TokenSource

NewTokenSource returns a oauth2.TokenSource for issuing a Wappa token.

The provided context optionally controls which HTTP client is used. See the oauth2.HTTPClient variable. host should be sufixed by '/'.

func (*TokenSource) Token

func (ts *TokenSource) Token() (*oauth2.Token, error)

Token returns a new oauth2.Token from a JWT or error.

type TravelInfo

type TravelInfo struct {
	Time       Duration `json:"time"`
	TimeSec    int      `json:"timeSec"`
	DistanceKM float64  `json:"distanceKm"`
}

type Vehicle

type Vehicle struct {
	Marker string `json:"marker"`
	Model  string `json:"model"`
	Plate  string `json:"plate"`
}

type Webhook

type Webhook struct {
	URL      string `json:"url"`
	Endpoint string `json:"endpoint"`
	AuthKey  string `json:"authKey"`
	Active   bool   `json:"active,omitempty"`
}

Webhook is the struct representing the Webhook entity in the API.

type WebhookResult

type WebhookResult struct {
	Result

	Listeners []*Webhook `json:"listeners"`
}

WebhookResult is the API response payload.

type WebhookRide

type WebhookRide struct {
	Code               int      `json:"code"`
	RideID             int      `json:"rideId"`
	CompanyID          int      `json:"companyId"`
	EmployeeID         int      `json:"employeeId"`
	Status             string   `json:"status"`
	TaxiLocation       Location `json:"taxiLocation"`
	OriginLocation     Location `json:"originLocation"`
	DestinyLocation    Location `json:"destinyLocation"`
	TimeToOriginSec    int      `json:"timeToOriginSec"`
	TimeToOrigin       Duration `json:"timeToOrigin"`
	DistanceToOriginKM int      `json:"destanceToOriginKm"`
	TimeToDestinySec   int      `json:"timeToDestinySec"`
	TimeToDestiny      Duration `json:"timeToDestiny"`
	RideValue          float64  `json:"rideValue"`
	ExternalID         string   `json:"externalId"`
}

WebhookRide is the payload sent by the Webhook.

type WebhookService

type WebhookService service

WebhookService is responsible for handling the requests to the webhook resource.

func (*WebhookService) Activate

func (ws *WebhookService) Activate(ctx context.Context) (*Result, error)

Activate activates the current webhook if it has been deactivated in the API.

func (*WebhookService) Create

func (ws *WebhookService) Create(ctx context.Context, w *Webhook) (*Result, error)

Create creates a webhook resource in the API.

func (*WebhookService) Deactivate

func (ws *WebhookService) Deactivate(ctx context.Context) (*Result, error)

Deactivate deactivates the current webhook in the API.

func (*WebhookService) Read

func (ws *WebhookService) Read(ctx context.Context) (*WebhookResult, error)

Read returns the webhooks created in the API.

func (*WebhookService) Update

func (ws *WebhookService) Update(ctx context.Context, w *Webhook) (*Result, error)

Updated edits the webhook information.

Jump to

Keyboard shortcuts

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