lob

package module
v0.0.0-...-12c19f6 Latest Latest
Warning

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

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

README

go-lob

Lob.com API client in Go.

Install

Install with

go get github.com/seedco/go-lob

Use

Use by creating a Lob struct with NewLob, and calling the methods it offers.

// fill in your API key and user agent here
l := lob.NewLob(lob.BaseAPI, apiKey, userAgent)

testAddress := &Address{
  Name:           "Lobster Test",
  Email:          "lobtest@example.com",
  Phone:          "5555555555",
  AddressLine1:   "1005 W Burnside St", // Powell's City of Books, the best book store in the world.
  AddressCity:    "Portland",
  AddressState:   "OR",
  AddressZip:     "97209",
  AddressCountry: "US",
}

verify, err := l.VerifyAddress(testAddress)
// ...

You can see the full docs here.

Test

You can run the tests if you set the TEST_LOB_API_KEY environment variable, i.e.,

TEST_LOB_API_KEY=test_yourtestkeyhere go test .

License

Licensed under the MIT license. See LICENSE for more details.

Documentation

Index

Constants

View Source
const (
	MailTypeUspsFirstClass = "usps_first_class"
	MailTypeUpsNextDayAir  = "ups_next_day_air"
)

Mail types that lob supports.

View Source
const (
	BaseAPI    = "https://api.lob.com/v1/"
	APIVersion = "2019-06-01"
)

Base URL and API version for Lob.

Variables

View Source
var Non200Error = errors.New("Non-200 Status code returned")

Functions

func NewFakeLob

func NewFakeLob() *fakeLob

func NewLob

func NewLob(baseAPI, apiKey, userAgent string) *lob

NewLob creates an object that can be used to connect to the lob.com API.

Types

type Address

type Address struct {
	Error          *Error            `json:"error"`
	AddressCity    *string           `json:"address_city"`
	AddressCountry *string           `json:"address_country"`
	AddressLine1   string            `json:"address_line1"`
	AddressLine2   *string           `json:"address_line2"`
	AddressState   *string           `json:"address_state"`
	AddressZip     *string           `json:"address_zip"`
	Company        *string           `json:"company"`
	DateCreated    string            `json:"date_created"`
	DateModified   string            `json:"date_modified"`
	Deleted        *bool             `json:"deleted"`
	Description    *string           `json:"description"`
	Email          *string           `json:"email"`
	ID             string            `json:"id"`
	Metadata       map[string]string `json:"metadata"`
	Name           *string           `json:"name"`
	Object         string            `json:"object"`
	Phone          *string           `json:"phone"`
}

Address represents an address stored in the Lob's system.

type BankAccount

type BankAccount struct {
	Error         *Error            `json:"error"`
	AccountNumber string            `json:"account_number"`
	BankName      string            `json:"bank_name"`
	DateCreated   string            `json:"date_created"`
	DateModified  string            `json:"date_modified"`
	Description   *string           `json:"description"`
	ID            string            `json:"id"`
	Metadata      map[string]string `json:"metadata"`
	Object        string            `json:"object"`
	RoutingNumber string            `json:"routing_number"`
	Signatory     string            `json:"signatory"`
	Verified      bool              `json:"verified"`
}

BankAccount represents a bank account in lob's system.

type CancelCheckResponse

type CancelCheckResponse struct {
	ID      string `json:"id"`
	Deleted bool   `json:"deleted"`
}

type Check

type Check struct {
	Error                *Error              `json:"error"`
	Amount               float64             `json:"amount"`
	BankAccount          *BankAccount        `json:"bank_account"`
	CheckBottom          *string             `json:"check_bottom"`
	CheckNumber          int                 `json:"check_number"`
	Data                 map[string]string   `json:"data"`
	DateCreated          string              `json:"date_created"`
	DateModified         string              `json:"date_modified"`
	Description          string              `json:"description"`
	ExpectedDeliveryDate string              `json:"expected_delivery_date"`
	SendDate             time.Time           `json:"send_date"`
	From                 *Address            `json:"from"`
	ID                   string              `json:"id"`
	MailType             *string             `json:"mail_type"`
	Memo                 string              `json:"memo"`
	Message              *string             `json:"message"`
	Metadata             map[string]string   `json:"metadata"`
	Name                 string              `json:"name"`
	Object               string              `json:"object"`
	Thumbnails           []map[string]string `json:"thumbnails"`
	To                   *Address            `json:"to"`
	Tracking             *Tracking           `json:"tracking"`
	URL                  string              `json:"url"`
}

Check represents a printed check in Lob's system.

type CreateBankAccountRequest

type CreateBankAccountRequest struct {
	Description   *string           `json:"description"`
	RoutingNumber string            `json:"routing_number"`
	AccountNumber string            `json:"account_number"`
	Signatory     string            `json:"signatory"`
	AccountType   string            `json:"account_type"`
	Metadata      map[string]string `json:"metadata"`
}

CreateBankAccountRequest request has the parameters needed to submit a bank account creation request to Lob.

type CreateCheckRequest

type CreateCheckRequest struct {
	Amount        float64           `json:"amount"`
	BankAccountID string            `json:"bank_account"`
	CheckBottom   *string           `json:"check_bottom"` // 400 chars, at bottom (cannot use with message)
	CheckNumber   *string           `json:"check_number"`
	Data          map[string]string `json:"data"`
	Description   *string           `json:"description"`
	FromAddressID string            `json:"from"`
	MailType      *string           `json:"mail_type"`
	Memo          *string           `json:"memo"`    // 40 chars in memo line
	Message       *string           `json:"message"` // 400 chars, at top (cannot use with check_bottom)
	ToAddressID   string            `json:"to"`
}

CreateCheckRequest specifies options for creating a check.

type Error

type Error struct {
	Message    string `json:"message,omitempty"`
	StatusCode int    `json:"status_code,omitempty"`
}

type ListAddressesResponse

type ListAddressesResponse struct {
	Data        []Address `json:"data"`
	Object      string    `json:"object"`
	NextURL     string    `json:"next_url"`
	PreviousURL string    `json:"previous_url"`
	Count       int       `json:"count"`
}

ListAddressesResponse gives the results for listing all addresses for our account.

type ListBankAccountsResponse

type ListBankAccountsResponse struct {
	Data        []BankAccount `json:"data"`
	Object      string        `json:"object"`
	NextURL     string        `json:"next_url"`
	PreviousURL string        `json:"previous_url"`
	Count       int           `json:"count"`
}

ListBankAccountsResponse gives the results for listing all addresses for our account.

type ListChecksResponse

type ListChecksResponse struct {
	Data        []Check `json:"data"`
	Object      string  `json:"object"`
	NextURL     string  `json:"next_url"`
	PreviousURL string  `json:"previous_url"`
	Count       int     `json:"count"`
}

ListChecksResponse details all of the checks we've ever mailed and printed.

type Lob

type Lob interface {
	// Checks
	CreateCheck(*CreateCheckRequest) (*Check, error)
	GetCheck(string) (*Check, error)
	CancelCheck(string) (*CancelCheckResponse, error)
	ListChecks(int) (*ListChecksResponse, error)
	// Addresses
	CreateAddress(*Address) (*Address, error)
	GetAddress(string) (*Address, error)
	DeleteAddress(string) error
	ListAddresses(int) (*ListAddressesResponse, error)
	VerifyUSAddress(*Address) (*USAddressVerificationResponse, error)
	// NamedObject
	GetStates() (*NamedObjectList, error)
	GetCountries() (*NamedObjectList, error)
	// Bank Accounts
	CreateBankAccount(*CreateBankAccountRequest) (*BankAccount, error)
	GetBankAccount(string) (*BankAccount, error)
	ListBankAccounts(int) (*ListBankAccountsResponse, error)
}

type NamedObject

type NamedObject struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
	Object    string `json:"object"`
}

NamedObject is a datum that contains a name and short name for a state or country.

type NamedObjectList

type NamedObjectList struct {
	Object string        `json:"object"`
	Data   []NamedObject `json:"data"`
}

NamedObjectList is used to return the list of countries and states.

type Tracking

type Tracking struct {
	Carrier        string        `json:"carrier"`
	Events         []interface{} `json:"events"`
	ID             string        `json:"id"`
	Link           *string       `json:"link"`
	Object         string        `json:"object"`
	TrackingNumber string        `json:"tracking_number"`
}

Tracking provides information on shipment tracking for a check.

type USAddressComponents

type USAddressComponents struct {
	PrimaryNumber             string  `json:"primary_number"`
	StreetPredirection        string  `json:"street_predirection"`
	StreetName                string  `json:"street_name"`
	StreetSuffix              string  `json:"street_suffix"`
	StreetPostdirection       string  `json:"street_postdirection"`
	SecondaryDesignator       string  `json:"secondary_designator"`
	SecondaryNumber           string  `json:"secondary_number"`
	PmbDesignator             string  `json:"pmb_designator"`
	PmbNumber                 string  `json:"pmb_number"`
	ExtraSecondary_designator string  `json:"extra_secondary_designator"`
	ExtraSecondary_number     string  `json:"extra_secondary_number"`
	City                      string  `json:"city"`
	State                     string  `json:"state"`
	ZipCode                   string  `json:"zip_code"`
	ZipCodePlus_4             string  `json:"zip_code_plus_4"`
	ZipCodeType               string  `json:"zip_code_type"`
	DeliveryPoint_barcode     string  `json:"delivery_point_barcode"`
	AddressType               string  `json:"address_type"`
	RecordType                string  `json:"record_type"`
	DefaultBuildingAddress    bool    `json:"default_building_address"`
	County                    string  `json:"county"`
	CountyFips                string  `json:"county_fips"`
	CarrierRoute              string  `json:"carrier_route"`
	CarrierRouteType          string  `json:"carrier_route_type"`
	Latitude                  float64 `json:"latitude"`
	Longitude                 float64 `json:"longitude"`
}

type USAddressDeliverabilityAnalysis

type USAddressDeliverabilityAnalysis struct {
	DpvConfirmation string   `json:"dpv_confirmation"`
	DpvCmra         string   `json:"dpv_cmra"`
	DpvVacant       string   `json:"dpv_vacant"`
	DpvFootnotes    []string `json:"dpv_footnotes"`
	EwsMatch        bool     `json:"ews_match"`
	LacsIndicator   string   `json:"lacs_indicator"`
	LacsReturnCode  string   `json:"lacs_return_code"`
	SuiteReturnCode string   `json:"suite_return_code"`
}

type USAddressVerificationRequest

type USAddressVerificationRequest struct {
	Recipient    *string `json:"recipient"`
	AddressLine1 *string `json:"primary_line"`
	AddressLine2 *string `json:"secondary_line"`
	AddressCity  *string `json:"city"`
	AddressState *string `json:"state"`
	AddressZip   *string `json:"zip_code"`
}

AddressVerificationRequest validates the given subset of info from an address.

type USAddressVerificationResponse

type USAddressVerificationResponse struct {
	Id                     string                          `json:"id"`
	Recipient              string                          `json:"recipient"`
	PrimaryLine            string                          `json:"primary_line"`
	SecondaryLine          string                          `json:"secondary_line"`
	Urbanization           string                          `json:"urbanization,omitempty"`
	LastLine               string                          `json:"last_line"`
	Deliverability         string                          `json:"deliverability"`
	Components             USAddressComponents             `json:"components"`
	DeliverabilityAnalysis USAddressDeliverabilityAnalysis `json:"deliverability_analysis"`
	Object                 string                          `json:"object"`
}

USAddressVerificationResponse gives the response from attempting to verify a US address.

Jump to

Keyboard shortcuts

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