Help us shape the future of Go! Take the 2026 Go Developer Survey

myflyingbox

package module
v0.0.0-...-14ee712 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: MIT Imports: 11 Imported by: 0

README

GoDoc Build Status codecov

A MyFlyingBox API client for Go

Documentation

Overview

Package myflyingbox implements a Go REST client for the MyFlyingBox API

Index

Constants

View Source
const (
	// ProductionURL is the production API base endpoint
	ProductionURL = "https://api.myflyingbox.com/v2"
	// TestURL is the production API base endpoint
	TestURL = "https://test.myflyingbox.com/v2"
)

Variables

View Source
var (
	// ErrInvalidArgumentType is returns when a argument which has an interface
	// type does not recieve a value it can use
	ErrInvalidArgumentType = errors.New("invalid argument type")

	ErrNoOrderID = errors.New("no order id")
	ErrNoQuoteID = errors.New("no quote id")
)

Error messages

Functions

This section is empty.

Types

type API

type API struct {

	// Client is the http client used for requests. If nil, an appropriate default is used
	Client *http.Client
	// contains filtered or unexported fields
}

API is a myflyingbox.com API client for Go

func New

func New(login, pwd string) *API

New creates a new API client. If in Google App Engine development envirnonment, it will automatically be set to test mode

func (*API) CancelOrder

func (a *API) CancelOrder(ctx context.Context, o interface{}) (*Order, error)

CancelOrder cancels the given order.

func (*API) Do

func (a *API) Do(ctx context.Context, req *http.Request, result interface{}) error

Do sends the request and marshals the response into result

func (*API) Get

func (a *API) Get(ctx context.Context, urlStr string, result interface{}) error

Get sends a GET request to the urlStr and marshals response into result

func (*API) GetOrder

func (a *API) GetOrder(ctx context.Context, o interface{}) (*Order, error)

GetOrder returns order info for the given order

func (*API) LabelPDF

func (a *API) LabelPDF(ctx context.Context, o interface{}) ([]byte, error)

LabelPDF returns the label PDF as a byte slice

func (*API) PlaceOrder

func (a *API) PlaceOrder(ctx context.Context, o *Order) (*Order, error)

PlaceOrder creates an order and returns the results

func (*API) Post

func (a *API) Post(ctx context.Context, urlStr string, data, result interface{}) error

Post sends a POST request with the JSON encoded data to the urlStr and marshals response into result

func (*API) Put

func (a *API) Put(ctx context.Context, urlStr string, result interface{}) error

Put is for delete requests, so only the urlStr is implemented

func (*API) RequestQuote

func (a *API) RequestQuote(ctx context.Context, q *Quote) (*Quote, error)

RequestQuote places a quote request and returns the result

func (*API) RetrieveQuote

func (a *API) RetrieveQuote(ctx context.Context, q interface{}) (*Quote, error)

RetrieveQuote retrieves details for an existing quote.

func (*API) SetTestMode

func (a *API) SetTestMode(test bool) *API

SetTestMode toggles mode to test

func (*API) SetURL

func (a *API) SetURL(urlStr string) *API

SetURL sets the API base url

func (*API) Track

func (a *API) Track(ctx context.Context, o interface{}) (list []Tracking, err error)

Track returns tracking information about the given order

type CollectionDate

type CollectionDate struct {
	Date   string `json:"date"`
	Cutoff string `json:"cutoff"`
}

CollectionDate is a sub-element

type DeliveryLocation

type DeliveryLocation struct {
	Company      string   `json:"company"`
	Street       []string `json:"street"`
	PostalCode   string   `json:"postal_code"`
	City         string   `json:"city"`
	OpeningHours []OpeningTime
}

DeliveryLocation is a MyFlyingBox delivery location

type Details

type Details struct {
	Code  string `json:"code"`
	Label Label  `json:"label"`
}

Details is a details sub-element

type ErrorInfo

type ErrorInfo struct {
	Type    string   `json:"type"`
	Message string   `json:"message"`
	Details []string `json:"details"`
}

ErrorInfo is an upstream error

func (ErrorInfo) Error

func (e ErrorInfo) Error() error

type Event

type Event struct {
	Code      string    `json:"code"`
	HappendAt time.Time `json:"happened_at"`
	Label     Label     `json:"label"`
	Location  Location  `json:"location"`
	Details   Details   `json:"details"`
}

Event is a tracking event

type Label

type Label map[string]string

Label is a hash of language => label string

type Location

type Location struct {
	Name   string   `json:"name"`
	Street []string `json:"street"`
	City   string   `json:"city"`

	PostalCode string `json:"postal_code,omitempty"`
	Country    string `json:"country,omitempty"`
}

Location is a location

func (Location) String

func (l Location) String() string

type Offer

type Offer struct {
	ID              string           `json:"id"`
	QuoteID         string           `json:"quote_id"`
	ProductID       string           `json:"product_id"`
	Product         Product          `json:"product"`
	Price           *Price           `json:"price,omitempty"`
	PriceVAT        *Price           `json:"price_vat,omitempty"`
	TotalPrice      *Price           `json:"total_price,omitempty"`
	InsurancePrice  *Price           `json:"insurance_price,omitempty"`
	CollectionDates []CollectionDate `json:"collection_dates,omitempty"`

	// Response data.
	Insurable bool `json:"insurable"`
	Orderable bool `json:"orderable"`
}

Offer is a offer struct

type OpeningTime

type OpeningTime struct {
	Day   int    `json:"day"` // 1-7 Mon-Sun
	Hours string `json:"hours"`
}

OpeningTime provides opening time details for a location

type Order

type Order struct {

	// Used in placing the order.
	OfferID        string  `json:"offer_id,omitempty"`
	ThermalLabels  bool    `json:"thermal_labels,omitempty"`
	InsureShipment bool    `json:"insure_shipment,omitempty"`
	Shipper        Shipper `json:"shipper"`

	Parcels []Parcel `json:"parcels,omitempty"`

	// Used when retrieving the order\
	ID        string    `json:"id,omitempty"`
	Recipient Recipient `json:"recipient,omitempty"`
}

Order is the struct used to place an order.

type Parcel

type Parcel struct {
	Weight float64 `json:"weight,omitempty"`
	Length float64 `json:"length,omitempty"`
	Width  float64 `json:"width,omitempty"`
	Height float64 `json:"height,omitempty"`

	Value              int64  `json:"value,string,omitempty"`
	Currency           string `json:"currency"`
	Description        string `json:"description"`
	ShipperReference   string `json:"shipper_reference"`
	RecipientReference string `json:"recipient_reference"`
	CustomerReference  string `json:"customer_reference"`
	CountryOfOrigin    string `json:"country_of_origin"`

	InsuredValue    float64 `json:"insured_value,omitempty"`
	InsuredCurrency string  `json:"insured_currency,omitempty"`
}

Parcel is a parcel

type Price

type Price struct {
	Formatted     string  `json:"formatted"`
	Currency      string  `json:"currency"`
	Amount        float64 `json:"amount,string"`
	AmountInCents int     `json:"amount_in_cents"`
}

Price is a price struct

type Product

type Product struct {
	ID                     string `json:"id"`
	Code                   string `json:"code"`
	Name                   string `json:"name"`
	Delay                  string `json:"delay"`
	Pickup                 bool   `json:"pick_up"`
	Dropoff                bool   `json:"drop_off"`
	PresetDeliveryLocation bool   `json:"preset_delivery_location"`

	ExportFrom             []string          `json:"export_from,omitempty"`
	CarrierCode            string            `json:"carrier_code,omitempty"`
	CollectionInformations map[string]string `json:"collection_informations,omitempty"`
	DeliveryInformations   map[string]string `json:"delivery_informations,omitempty"`
	Details                map[string]string `json:"details,comitempty"`
}

Product is a MyFlyingBox product

type Quote

type Quote struct {
	Shipper   Shipper   `json:"shipper"`
	Recipient Recipient `json:"recipient"`
	Parcels   []Parcel  `json:"parcels"`
	Offers    []Offer   `json:"offers"`

	ID string `json:"id,omitempty"`

	Ordered bool `json:"ordered"`
}

Quote is a MyFlyingBox quote

type Recipient

type Recipient struct {
	Name       string `json:"name"`
	Company    string `json:"company"`
	Street     string `json:"street"`
	City       string `json:"city"`
	State      string `json:"state"`
	PostalCode string `json:"postal_code"`
	Country    string `json:"country"`
	Phone      string `json:"phone"`
	Email      string `json:"email"`
	IsACompany bool   `json:"is_a_company,string"`

	LocationCode string `json:"location_code,omitempty"`
}

Recipient is a recipient

type Request

type Request struct {
	Quote *Quote `json:"quote,omitempty"`
	Order *Order `json:"order,omitempty"`
}

Request is a struct used for sending requests of all types since request elements need to be wrapped in a root element of the same name

type Response

type Response struct {
	Status    string      `json:"status"`
	Self      string      `json:"self"`
	Count     int         `json:"count"`
	Data      interface{} `json:"data"`
	ErrorInfo *ErrorInfo  `json:"error"`
}

Response is the base response type for all API responses.

func (Response) Error

func (r Response) Error() error

type Shipper

type Shipper struct {
	City       string `json:"city,omitempty"`
	Country    string `json:"country,omitempty"`
	PostalCode string `json:"postal_code,omitempty"`

	Name    string `json:"name,omitempty"`
	Company string `json:"company,omitempty"`
	Street  string `json:"street,omitempty"`
	State   string `json:"state,omitempty"`
	Phone   string `json:"phone,omitempty"`

	// CollectionDate is used to request collection date from a shipper when placing an order
	CollectionDate *time.Time `json:"collection_date,omitempty"`
	Email          string     `json:"email,omitempty"`
}

Shipper is a shipper

type Tracking

type Tracking struct {
	ParcelIndex int     `json:"parcel_index"`
	Events      []Event `json:"events"`
}

Tracking is a tracking response

Jump to

Keyboard shortcuts

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