grabexpress

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 12 Imported by: 0

README

grabexpress-go

Unofficial Go Client SDK for the GrabExpress APIs

Installation

To install, please execute the following go get command.

go get github.com/rgaquino/grabexpress-go

Sample Usage

package main

import (
    "context"
    "fmt"
    "log"
)

func main() {
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCredentialsMissing  = errors.New("API Key credentials missing")
	ErrAuthenticationError = errors.New("authentication error")
	ErrBaseURLMissing      = errors.New("base URL missing")
	ErrTokenURLMissing     = errors.New("token URL missing")
)
View Source
var (
	CountryUnknown = Country{
		Name: "Unknown",
	}
	CountryBrasil = Country{
		Name:       "Brasil",
		Code:       CountryCodeBrasil,
		Cities:     []CityCode{CityCodeBrasilSaoPaulo, CityCodeBrasilRioDeJaneiro},
		PhoneRegex: "^[0-9]{2}[9]{1}[0-9]{8}$",
		Locales:    []Locale{LocaleBrasilEN, LocaleBrasilPT},
	}
	CountryHongKong = Country{
		Name:       "Hong Kong",
		Code:       CountryCodeHongKong,
		Cities:     []CityCode{CityCodeHongKongHongKong},
		PhoneRegex: "^((?!999)([2-9][0-9]{7}))$",
		Locales:    []Locale{LocaleHongKongEN, LocaleHongKongZH},
	}
	CountryIndia = Country{
		Name:       "India",
		Code:       CountryCodeIndia,
		Cities:     []CityCode{CityCodeIndiaBengaluru, CityCodeIndiaMumbai, CityCodeIndiaDelhi},
		PhoneRegex: "^([6-9][0-9]{9}|22[0-9]{8})$",
		Locales:    []Locale{LocaleIndiaEN, LocaleIndiaHI, LocaleIndiaKN, LocaleIndiaMR},
	}
	CountryIndonesia = Country{
		Name:       "Indonesia",
		Code:       CountryCodeIndonesia,
		Cities:     []CityCode{CityCodeIndonesiaJakarata},
		PhoneRegex: "^0(8\\d{8,11}|21\\d{7,8})$",
		Locales:    []Locale{LocaleIndonesiaEN, LocaleIndonesiaID},
	}
	CountryMalaysia = Country{
		Name:       "Malaysia",
		Code:       CountryCodeMalaysia,
		Cities:     []CityCode{CityCodeMalaysiaKualaLumpur},
		PhoneRegex: "^0(1[1,5]?\\d{8}|[4-7,9]\\d{7}|8[2-9]\\d{6}|3\\d{8})$",
		Locales:    []Locale{LocaleMalaysiaEN, LocaleMalaysiaMS},
	}
	CountryMexico = Country{
		Name:       "Mexico",
		Code:       CountryCodeMexico,
		Cities:     []CityCode{CityCodeMexicoMexico},
		PhoneRegex: "^([+]+52?)?(\\d{3}?){2}\\d{4}$",
		Locales:    []Locale{LocaleMexicoEN, LocaleMexicoMX},
	}
	CountryPhilippines = Country{
		Name:       "Philippines",
		Code:       CountryCodePhilippines,
		Cities:     []CityCode{CityCodePhilippinesManila, CityCodePhilippinesCebu},
		PhoneRegex: "^09[0-9]{9}$|^0?2[0-9]{7}$|^0?32[0-9]{7}$",
		Locales:    []Locale{LocalePhilippinesEN},
	}
	CountrySingapore = Country{
		Name:       "Singapore",
		Code:       CountryCodeSingapore,
		Cities:     []CityCode{CityCodeSingaporeSingapore},
		PhoneRegex: "^[689]{1}[0-9]{7}$",
		Locales:    []Locale{LocaleSingaporeEN},
	}
	CountryTaiwan = Country{
		Name:       "Taiwan",
		Code:       CountryCodeTaiwan,
		Cities:     []CityCode{CityCodeTaiwanTaipei},
		PhoneRegex: "^0([1-8]{1}[0-9]{7,8}|9[0-9]{8})$",
		Locales:    []Locale{LocaleTaiwanZH},
	}
	CountryThailand = Country{
		Name:       "Thailand",
		Code:       CountryCodeThailand,
		Cities:     []CityCode{CityCodeThailandBangkok, CityCodeThailandPattaya},
		PhoneRegex: "^(0[0-9]{8,9}|[0-9]{4})$",
		Locales:    []Locale{LocaleThailandEN, LocaleThailandTH},
	}
	CountryVietnam = Country{
		Name:       "Vietnam",
		Code:       CountryCodeVietnam,
		Cities:     []CityCode{CityCodeVietnamHoChiMinh, CityCodeVietnamHanoi},
		PhoneRegex: "^0?(2|[35789])[0-9]{8}$|^02[48][0-9]{8}$",
		Locales:    []Locale{LocaleVietnamEN, LocaleVietnamVI},
	}
)

Country enum

AllCountriesByISOCode ...

Functions

This section is empty.

Types

type AdvanceInfo

type AdvanceInfo struct {
	FailedReason string `json:"failedReason"`
}

AdvanceInfo ...

type BaseDTO added in v0.1.2

type BaseDTO struct {
	RequestID string `json:"requestID,omitempty"`
}

BaseDTO ...

func (*BaseDTO) SetRequestID added in v0.1.2

func (b *BaseDTO) SetRequestID(id string)

SetRequestID ...

type CancelDeliveryResponse added in v0.1.2

type CancelDeliveryResponse struct {
	BaseDTO
}

CancelDeliveryResponse ...

type CashOnDelivery

type CashOnDelivery struct {
	Amount float64 `json:"amount"`
}

CashOnDelivery ...

type CityCode

type CityCode string

CityCode is the UN/LOCODE of supported cities.

const (
	CityCodeBrasilSaoPaulo      CityCode = "BR_SAO"
	CityCodeBrasilRioDeJaneiro  CityCode = "BR_RIO"
	CityCodeHongKongHongKong    CityCode = "HK_HKG"
	CityCodeIndiaBengaluru      CityCode = "IN_BLR"
	CityCodeIndiaMumbai         CityCode = "IN_BOM"
	CityCodeIndiaDelhi          CityCode = "IN_DEL"
	CityCodeIndonesiaJakarata   CityCode = "ID_JKT"
	CityCodeMalaysiaKualaLumpur CityCode = "MY_KUL"
	CityCodeMexicoMexico        CityCode = "MX_MEX"
	CityCodePhilippinesManila   CityCode = "PH_MNL"
	CityCodePhilippinesCebu     CityCode = "PH_CEB"
	CityCodeSingaporeSingapore  CityCode = "SG_SIN"
	CityCodeTaiwanTaipei        CityCode = "TW_TPE"
	CityCodeThailandBangkok     CityCode = "TH_BKK"
	CityCodeThailandPattaya     CityCode = "TH_PYX"
	CityCodeVietnamHoChiMinh    CityCode = "VN_SGN"
	CityCodeVietnamHanoi        CityCode = "VN_HAN"
)

CityCode enum

func (CityCode) GetCountry

func (c CityCode) GetCountry() Country

GetCountry ...

type Client

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

Client may be used to make requests to the GrabExpress APIs

func NewClient

func NewClient(options ...ClientOption) (*Client, error)

NewClient constructs a new Client which can make requests to the GrabExpress APIs.

func (*Client) CancelDelivery

func (c *Client) CancelDelivery(ctx context.Context, deliveryID string) (*CancelDeliveryResponse, error)

CancelDelivery ...

func (*Client) CreateDelivery

func (c *Client) CreateDelivery(ctx context.Context, req *CreateDeliveryRequest) (*CreateDeliveryResponse, error)

CreateDelivery ...

func (*Client) CreateQuotes

func (c *Client) CreateQuotes(ctx context.Context, req *CreateQuotesRequest) (*CreateQuotesResponse, error)

CreateQuotes requests for delivery service quotes. When packages details aren't provided, a single cheapest category package is assumed. Immediate dispatching is assumed. An array of delivery services with their respective quote is returned.

func (*Client) GetDelivery

func (c *Client) GetDelivery(ctx context.Context, deliveryID string) (*GetDeliveryResponse, error)

GetDelivery ...

type ClientOption

type ClientOption func(*Client) error

ClientOption is the type of constructor options for NewClient(...).

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey configures a GrabExpress API client with an API Key

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL configures a GrabExpress API client with a custom base url

func WithHTTPClient

func WithHTTPClient(c *http.Client) ClientOption

WithHTTPClient configures a GrabExpress API client with a http.Client to make requests over.

func WithSecret

func WithSecret(secret string) ClientOption

WithSecret configures a GrabExpress API client with a secret

func WithTokenURL

func WithTokenURL(tokenURL string) ClientOption

WithTokenURL configures a GrabExpress API client with an auth token url

type Contact

type Contact struct {
	FirstName    string  `json:"firstName"`
	LastName     *string `json:"lastName,omitempty"`
	Title        *string `json:"title,omitempty"`
	CompanyName  *string `json:"companyName,omitempty"`
	Email        string  `json:"email"`
	Phone        string  `json:"phone"`
	IsSmsEnabled bool    `json:"smsEnabled"`
	Instruction  *string `json:"instruction,omitempty"`
}

Contact ...

type Coordinates

type Coordinates struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Coordinates ...

type Country

type Country struct {
	Name       string
	Code       CountryCode
	Cities     []CityCode
	Locales    []Locale
	PhoneRegex string
}

Country ...

type CountryCode

type CountryCode string

CountryCode is the ISO 3166-1 alpha-2 of supported countries and regions.

const (
	CountryCodeBrasil      CountryCode = "BR"
	CountryCodeHongKong    CountryCode = "HK"
	CountryCodeIndia       CountryCode = "IN"
	CountryCodeIndonesia   CountryCode = "ID"
	CountryCodeMalaysia    CountryCode = "MY"
	CountryCodeMexico      CountryCode = "MX"
	CountryCodePhilippines CountryCode = "PH"
	CountryCodeSingapore   CountryCode = "SG"
	CountryCodeTaiwan      CountryCode = "TW"
	CountryCodeThailand    CountryCode = "TH"
	CountryCodeVietnam     CountryCode = "VN"
)

CountryCode enum

type Courier

type Courier struct {
	Name        string      `json:"name"`
	Phone       string      `json:"phone"`
	PictureURL  string      `json:"pictureURL"`
	Rating      float64     `json:"rating"`
	Coordinates Coordinates `json:"coordinates"`
	Vehicle     Vehicle     `json:"vehicle"`
}

Courier ...

type CreateDeliveryRequest

type CreateDeliveryRequest struct {
	MerchantOrderID string          `json:"merchantOrderID"`
	ServiceType     ServiceType     `json:"serviceType"`
	PaymentMethod   *PaymentMethod  `json:"paymentMethod,omitempty"`
	Packages        []Package       `json:"packages,omitempty"`
	CashOnDelivery  *CashOnDelivery `json:"cashOnDelivery,omitempty"`
	Sender          Contact         `json:"sender"`
	Recipient       Contact         `json:"recipient"`
	Origin          Waypoint        `json:"origin"`
	Destination     Waypoint        `json:"destination"`
	Schedule        *Schedule       `json:"schedule,omitempty"`
}

CreateDeliveryRequest ...

type CreateDeliveryResponse

type CreateDeliveryResponse struct {
	BaseDTO
	Delivery
}

CreateDeliveryResponse ...

type CreateQuotesRequest

type CreateQuotesRequest struct {
	ServiceType *ServiceType `json:"serviceType,omitempty"`
	Packages    []Package    `json:"packages,omitempty"`
	Origin      Waypoint     `json:"origin"`
	Destination Waypoint     `json:"destination"`
}

CreateQuotesRequest ...

type CreateQuotesResponse

type CreateQuotesResponse struct {
	BaseDTO
	Quotes      []QuoteBase `json:"quotes,omitempty"`
	Packages    []Package   `json:"packages,omitempty"`
	Origin      Waypoint    `json:"origin"`
	Destination Waypoint    `json:"destination"`
}

CreateQuotesResponse ...

type Currency

type Currency struct {
	Code     string `json:"code"`
	Symbol   string `json:"symbol"`
	Exponent int64  `json:"exponent"`
}

Currency ...

type DTO added in v0.1.2

type DTO interface {
	SetRequestID(id string)
}

DTO ...

type Delivery

type Delivery struct {
	DeliveryID      string          `json:"deliveryID"`
	MerchantOrderID string          `json:"merchantOrderID"`
	Quote           Quote           `json:"quote"`
	PaymentMethod   PaymentMethod   `json:"paymentMethod"`
	Status          OrderStatus     `json:"status"`
	TrackingURL     string          `json:"trackingURL"`
	Courier         *Courier        `json:"courier,omitempty"`
	Timeline        *Timeline       `json:"timeline,omitempty"`
	Schedule        *Schedule       `json:"schedule,omitempty"`
	CashOnDelivery  *CashOnDelivery `json:"cashOnDelivery,omitempty"`
	InvoiceNumber   string          `json:"invoiceNumber"`
	PickupPin       string          `json:"pickupPin"`
	AdvanceInfo     *AdvanceInfo    `json:"advanceInfo,omitempty"`
	Sender          Contact         `json:"sender"`
	Recipient       Contact         `json:"recipient"`
}

Delivery ...

type Dimensions

type Dimensions struct {
	Height int64 `json:"height"`
	Weight int64 `json:"weight"`
	Width  int64 `json:"width"`
	Depth  int64 `json:"depth"`
}

Dimensions ...

type Error added in v0.1.2

type Error struct {
	Status    int    `json:"status,omitempty"`
	Message   string `json:"message,omitempty"`
	RequestID string `json:"requestID,omitempty"`
}

Error is the conventional GrabExpress client error

func (*Error) Error added in v0.1.2

func (e *Error) Error() string

Error returns error message. This enables grabexpress.Error to comply with Go error interface

type GetDeliveryResponse

type GetDeliveryResponse struct {
	BaseDTO
	Delivery
}

GetDeliveryResponse ...

type Locale

type Locale string

Locale ...

const (
	LocaleBrasilEN      Locale = "en_BR"
	LocaleBrasilPT      Locale = "pt_BR"
	LocaleHongKongEN    Locale = "en_HK"
	LocaleHongKongZH    Locale = "zh_HK"
	LocaleIndiaEN       Locale = "en_IN"
	LocaleIndiaHI       Locale = "hi_IN"
	LocaleIndiaKN       Locale = "kn_IN"
	LocaleIndiaMR       Locale = "mr_IN"
	LocaleIndonesiaEN   Locale = "en_ID"
	LocaleIndonesiaID   Locale = "id_ID"
	LocaleMalaysiaEN    Locale = "en_MY"
	LocaleMalaysiaMS    Locale = "ms_MY"
	LocaleMexicoEN      Locale = "en_MX"
	LocaleMexicoMX      Locale = "es_MX"
	LocalePhilippinesEN Locale = "en_PH"
	LocaleSingaporeEN   Locale = "en_SG"
	LocaleTaiwanZH      Locale = "zh_TW"
	LocaleThailandEN    Locale = "en_TH"
	LocaleThailandTH    Locale = "th_TH"
	LocaleVietnamEN     Locale = "en_VN"
	LocaleVietnamVI     Locale = "vi_VN"
)

Locale enum

type OrderStatus

type OrderStatus string

OrderStatus ...

const (
	// OrderStatusQueueing -
	OrderStatusQueueing OrderStatus = "QUEUING"
	// OrderStatusAllocating -
	OrderStatusAllocating OrderStatus = "ALLOCATING"
	// OrderStatusPickingUp -
	OrderStatusPickingUp OrderStatus = "PICKING_UP"
	// OrderStatusInDelivery -
	OrderStatusInDelivery OrderStatus = "IN_DELIVERY"
	// OrderStatusInReturn -
	OrderStatusInReturn OrderStatus = "IN_RETURN"
	// OrderStatusCanceled -
	OrderStatusCanceled OrderStatus = "CANCELED"
	// OrderStatusReturned -
	OrderStatusReturned OrderStatus = "RETURNED"
	// OrderStatusFailed -
	OrderStatusFailed OrderStatus = "FAILED"
	// OrderStatusCompleted -
	OrderStatusCompleted OrderStatus = "COMPLETED"
)

OrderStatus enum

type Package

type Package struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Quantity    int64      `json:"quantity"`
	Price       float64    `json:"price"`
	Dimensions  Dimensions `json:"dimensions"`
}

Package ...

type PaymentMethod

type PaymentMethod string

PaymentMethod ...

const (
	PaymentMethodCashless PaymentMethod = "CASHLESS"
	PaymentMethodCash     PaymentMethod = "CASH"
)

PaymentMethod enum

type Quote

type Quote struct {
	QuoteBase
	Packages    []Package `json:"package,omitempty"`
	Origin      Waypoint  `json:"origin"`
	Destination Waypoint  `json:"destination"`
}

Quote ...

type QuoteBase

type QuoteBase struct {
	Service           Service   `json:"service"`
	Currency          Currency  `json:"currency"`
	Amount            float64   `json:"amount"`
	EstimatedTimeline *Timeline `json:"estimatedTimeline,omitempty"`
	Distance          int64     `json:"distance"`
}

QuoteBase ...

type Schedule

type Schedule struct {
	PickupTimeFrom *time.Time `json:"pickupTimeFrom,omitempty"`
	PickupTimeTo   *time.Time `json:"pickupTimeTo,omitempty"`
}

Schedule ...

type Service

type Service struct {
	ID   int64       `json:"id"`
	Type ServiceType `json:"type"`
	Name string      `json:"name"`
}

Service ...

type ServiceType

type ServiceType string

ServiceType ...

const (
	ServiceTypeInstant ServiceType = "INSTANT"
	ServiceTypeSameDay ServiceType = "SAME_DAY"
	ServiceTypeBulk    ServiceType = "BULK"
)

ServiceType enum

type Timeline

type Timeline struct {
	Create    *time.Time `json:"create,omitempty"`
	Allocate  *time.Time `json:"allocate,omitempty"`
	Pickup    *time.Time `json:"pickup,omitempty"`
	DropOff   *time.Time `json:"dropoff,omitempty"`
	Completed *time.Time `json:"completed,omitempty"`
	Cancel    *time.Time `json:"cancel,omitempty"`
	Return    *time.Time `json:"return,omitempty"`
	Fail      *time.Time `json:"fail,omitempty"`
}

Timeline ...

type Vehicle

type Vehicle struct {
	LicensePlate        string `json:"licensePlate"`
	Model               string `json:"model"`
	PhysicalVehicleType string `json:"physicalVehicleType"`
}

Vehicle ...

type Waypoint

type Waypoint struct {
	Address     string             `json:"address"`
	Keywords    *string            `json:"keywords,omitempty"`
	CityCode    *string            `json:"cityCode,omitempty"`
	Coordinates Coordinates        `json:"coordinates"`
	Extra       *map[string]string `json:"extra,omitempty"`
}

Waypoint ...

Jump to

Keyboard shortcuts

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