zipcode

package
v1.14.11 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const MaxBatchSize = 100

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

Batch stores input records and settings related to a group of addresses to be verified in a batch.

func NewBatch

func NewBatch() *Batch

NewBatch creates a new, empty batch.

func (*Batch) Append

func (b *Batch) Append(record *Lookup) bool

Append includes the record in the collection to be sent if there is still room (max: 100).

func (*Batch) Clear

func (b *Batch) Clear()

Clear clears the internal collection.

func (*Batch) IsFull

func (b *Batch) IsFull() bool

IsFull returns true when the batch has 100 lookups, false in every other case.

func (*Batch) Length

func (b *Batch) Length() int

Length returns

func (*Batch) Records

func (b *Batch) Records() []*Lookup

Records returns the internal records collection.

type CityState

type CityState struct {
	City              string `json:"city"`
	MailableCity      bool   `json:"mailable_city"`
	StateAbbreviation string `json:"state_abbreviation"`
	State             string `json:"state"`
}

CityState contains all output fields defined here: https://smartystreets.com/docs/us-zipcode-api#cities

type Client

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

Client is responsible for sending batches of addresses to the us-zipcode-api.

func NewClient

func NewClient(sender sdk.RequestSender) *Client

NewClient creates a client with the provided sender.

func (*Client) SendBatch

func (c *Client) SendBatch(batch *Batch) error

SendBatch sends the batch of inputs, populating the output for each input if the batch was successful.

func (*Client) SendBatchWithContext added in v1.5.0

func (c *Client) SendBatchWithContext(ctx context.Context, batch *Batch) error

func (*Client) SendFromChannel

func (c *Client) SendFromChannel(input, output chan *Lookup) error

SendFromChannel is a high-level convenience function that leverages an internal reusable Batch to send everything received from the provided input channel in serial, blocking fashion. The same lookups are sent on the output channel as they are processed. Whereas it is the caller's job to close the input channel when all inputs have been sent, the output channel will be closed for the caller.

func (*Client) SendLookups

func (c *Client) SendLookups(lookups ...*Lookup) error

SendLookups is a high-level convenience function that leverages an internal reusable Batch to send all lookups provided in serial, blocking fashion.

type County

type County struct {
	CountyFIPS        string `json:"county_fips"`
	CountyName        string `json:"county_name"`
	StateAbbreviation string `json:"state_abbreviation"`
	State             string `json:"state"`
}

type Lookup

type Lookup struct {
	City    string `json:"city,omitempty"`
	State   string `json:"state,omitempty"`
	ZIPCode string `json:"zipcode,omitempty"`
	InputID string `json:"input_id,omitempty"`

	Result *Result `json:"-"`
}

Lookup contains all input fields defined here: https://smartystreets.com/docs/us-zipcode-api#input-fields

type Result

type Result struct {
	InputID    string `json:"input_id,omitempty"`
	InputIndex int    `json:"input_index"`

	Status     string      `json:"status"`
	Reason     string      `json:"reason"`
	CityStates []CityState `json:"city_states"`
	ZIPCodes   []ZIPCode   `json:"zipcodes"`
}

Result contains all output fields defined here: https://smartystreets.com/docs/us-zipcode-api#http-response-output

type ZIPCode

type ZIPCode struct {
	County
	ZIPCode           string   `json:"zipcode"`
	ZIPCodeType       string   `json:"zipcode_type"`
	DefaultCity       string   `json:"default_city"`
	Latitude          float64  `json:"latitude"`
	Longitude         float64  `json:"longitude"`
	Precision         string   `json:"precision"`
	AlternateCounties []County `json:"alternate_counties"`
}

ZIPCode contains all output fields defined here: https://smartystreets.com/docs/us-zipcode-api#zipcodes

Jump to

Keyboard shortcuts

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