yaddress

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 7 Imported by: 0

README

YAddress Web API Go Client

Makes calls into YAddress Web API for postal address correction, validation, standardization and geocoding.

Find more about YAddress Web API at http://www.yaddress.net/WebApi

Usage

Yaddress
func main() {
    logger := yaddress.DefaultLogger()
    yd := yaddress.NewClient("123", yaddress.WithLogger(logger))
	
    
    request := yaddress.Request{AddressLine1: "506 Fourth Avenue Unit 1", AddressLine2: "Asbury Prk, NJ"}

    resp, err := yd.ProcessAddress(request)
}

You are able to provide:logger, httpClient

Each one is called with following syntax:

With logger

    logger := yaddress.DefaultLogger()
    yd, err := yaddress.NewClient("123", yaddress.WithLogger(logger))

With client

	client := &http.Client{Timeout: time.Second * 10}
	
	yd, err := yaddress.NewClient("", yaddress.WithClient(client))

With both

	logger := yaddress.DefaultLogger()
	client := &http.Client{Timeout: time.Second * 10}
	
	yd, err := yaddress.NewClient("", yaddress.WithLogger(logger), yaddress.WithClient(client))

Warning Gives you first 1,000 transactions for free. You can find later pricing plans here

Tests

Tests are written using table driven technique

You can run tests:

go test -v -cover

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogger

func DefaultLogger() *zap.SugaredLogger

DefaultLogger creates the standard default logger to be used for the Client

func NewClient

func NewClient(userKey string, opts ...Option) *defaultClient

Types

type Address

type Address struct {
	ErrorCode            int     `json:"ErrorCode"`
	ErrorMessage         string  `json:"ErrorMessage"`
	AddressLine1         string  `json:"AddressLine1"`
	AddressLine2         string  `json:"AddressLine2"`
	Number               string  `json:"Number"`
	PreDir               string  `json:"PreDir"`
	Street               string  `json:"Street"`
	Suffix               string  `json:"Suffix"`
	PostDir              string  `json:"PostDir"`
	Sec                  string  `json:"Sec"`
	SecNumber            string  `json:"SecNumber"`
	SecValidated         bool    `json:"SecValidated"`
	City                 string  `json:"City"`
	State                string  `json:"State"`
	Zip                  string  `json:"Zip"`
	Zip4                 string  `json:"Zip4"`
	County               string  `json:"County"`
	UspsCarrierRoute     string  `json:"UspsCarrierRoute"`
	StateFP              string  `json:"StateFP"`
	CountyFP             string  `json:"CountyFP"`
	CensusTract          string  `json:"CensusTract"`
	CensusBlock          string  `json:"CensusBlock"`
	Latitude             float32 `json:"Latitude"`
	Longitude            float32 `json:"Longitude"`
	GeoPrecision         int     `json:"GeoPrecision"`
	TimeZoneOffset       int     `json:"TimeZoneOffset"`
	DstObserved          bool    `json:"DstObserved"`
	PlaceFP              int     `json:"PlaceFP"`
	CityMunicipality     string  `json:"CityMunicipality"`
	SalesTaxRate         float32 `json:"SalesTaxRate"`
	SalesTaxJurisdiction int     `json:"SalesTaxJurisdiction"`
}

type Option

type Option func(*defaultClient)

Option represents a Client option

func WithClient

func WithClient(httpClient *http.Client) Option

WithClient sets a custom client for making outgoing API calls

func WithLogger

func WithLogger(logger *zap.SugaredLogger) Option

WithLogger sets a logger for the client. Passing `nil` or not calling this Option will prevent the Client from logging anything

type Request

type Request struct {
	AddressLine1 string
	AddressLine2 string
}

type YaddressResult

type YaddressResult struct {
	Result Address
	Debug  struct {
		ErrorCode    int
		ErrorMessage string
	}
}

YaddressResponse

Jump to

Keyboard shortcuts

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