upsfreight

package module
v0.0.0-...-2ba3359 Latest Latest
Warning

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

Go to latest
Published: May 24, 2018 License: MIT Imports: 7 Imported by: 0

README

upsfreight

A Package for Connecting to the UPS Freight API.

This is used for scheduling pickups (pickup request) using the UPS Freight API. This is used so you don't have to call or use the UPS website to schedule these pickups.

See the code for usage instructions.

Documentation

Overview

Package upsfreight provides tooling to connect to the UPS Freight API. This is for truck shipments, not small parcels. Think LTL (less than truckload) shipments. This code was created off the UPS API documentation. This uses UPS's JSON API.

You will need to have a UPS account and register for API access to use this code.

Currently this package can perform: - pickup requests

To create a pickup request: - Set your UPS credentials (SetCredentials()). - Set test or production mode (SetProductionMode()). - Set the packaging type (PackagingType{}). - Set the weight of the goods (Weight{}). - Create the shipment details (ShipmentDetail{}). - Create the pickup details (PickupRequestDetails{}). - Set a unique identifier for the pickup request (SetCustomerContext()). - Set the timeframe for the pickup (SetPickupSchedule()). - Request the pickup (RequestPickup()). - Check for any errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCredentials

func SetCredentials(username, password, accessKey string)

SetCredentials saves the login credentials for the UPS website and API so we can make requests

func SetProductionMode

func SetProductionMode(yes bool)

SetProductionMode chooses the production url for use

func SetTimeout

func SetTimeout(seconds time.Duration)

SetTimeout updates the timeout value to something the user sets use this to increase the timeout if connecting to UPS is really slow

Types

type Address

type Address struct {
	AddressLine       string //street
	City              string
	StateProvinceCode string //two characters
	PostalCode        string
	CountryCode       string //two characters
}

Address is the container for an address

type PackagingType

type PackagingType struct {
	Code        string
	Description string
}

PackagingType holds data on what format a shipment is in Skid, boxes, etc. Code is a three character code. This can be found in the UPS API documentation. Description is the maching text description to the Code. Ex: Shipping a skid would be Code: SKD, Description: Skid

type PhoneNum

type PhoneNum struct {
	Number string
}

PhoneNum is the container for a phone number

type PickupRequest

type PickupRequest struct {
	Security             security
	FreightPickupRequest PickupRequestDetails
}

PickupRequest is the main container struct for data sent to UPS to request a pickup This format, and children types, was determined from UPS API documentation.

type PickupRequestDetails

type PickupRequestDetails struct {
	Request struct {
		TransactionReference struct {
			CustomerContext string //some unique identifier, time stamp or somethine else unique
		}
	}

	AdditionalComments     string
	DestinationPostalCode  string          //the ship to location
	DestinationCountryCode string          //the ship to location
	Requester              Requester       //who is scheduling the pickup
	ShipFrom               ShipFromAddress //the ship from location
	ShipmentDetail         ShipmentDetail  //what is shipping
	PickupDate             string          //YYYYMMDD; cannot be in the past
	EarliestTimeReady      string          //24 hour time, HHMM; cannot be in the past
	LatestTimeReady        string          //24 hour time, HHMM; cannot be in the past
}

PickupRequestDetails is the container around the actual pickup request This holds the ship to location, who is making the pickup request, the ship from location, the shipment details, and other pickup information

func (*PickupRequestDetails) RequestPickup

func (prd *PickupRequestDetails) RequestPickup() (responseData PickupRequestResponse, err error)

RequestPickup performs the call the the UPS API to schedule a pickup

func (*PickupRequestDetails) SetCustomerContext

func (prd *PickupRequestDetails) SetCustomerContext(c string)

SetCustomerContext saves the unique identifier for this request to the request details

func (*PickupRequestDetails) SetPickupSchedule

func (prd *PickupRequestDetails) SetPickupSchedule(startTime, endTime time.Time) error

SetPickupSchedule sets the date and time range for a pickup This is the time UPS will attempt to perform the pickup Times should be in the future and be on the same date.

type PickupRequestError

type PickupRequestError struct {
	Fault struct {
		FaultCode   string `json:"faultcode"`
		FaultString string `json:"faultstring"`
		Detail      struct {
			Errors struct {
				ErrorDetail errorDetail
			}
		} `json:"detail"`
	}
}

PickupRequestError is the data we get back from a pickup request when there is an error

type PickupRequestResponse

type PickupRequestResponse struct {
	FreightPickupResponse struct {
		Response struct {
			ResponseStatus struct {
				Code        string
				Description string
			}
			TransactionReference struct {
				CustomerContext string
			}
		}
		PickupRequestConfirmationNumber string
	}
}

PickupRequestResponse is the data we get back when a pickup is scheduled successfully

type Requester

type Requester struct {
	AttentionName string //a person's name or department name
	EMailAddress  string //for sending pickup request confirmation
	Name          string //company name where pickup is being made
	Phone         PhoneNum
}

Requester is data on who is scheduling the pickup

type ShipFromAddress

type ShipFromAddress struct {
	AttentionName string  //a person's name or department name
	Name          string  //company name where pickup is being made
	Address       Address //the address where the pickup will be made
	Phone         PhoneNum
}

ShipFromAddress is the info on where the shipment is shipping from

type ShipmentDetail

type ShipmentDetail struct {
	HazMatIndicator        string //usually blank
	PackagingType          PackagingType
	NumberOfPieces         string //must be a string for api to work
	DescriptionOfCommodity string
	Weight                 Weight
}

ShipmentDetail holds data on the shipment

type Weight

type Weight struct {
	UnitOfMeasurement struct {
		Code        string //LBS
		Description string //Pounds
	}
	Value string //must be a string for api to work; the actual weight, up to two decimal places
}

Weight holds data on the weight of the shipment

Jump to

Keyboard shortcuts

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