Working path to create addresses in lob

This commit is contained in:
Eli Ribble 2026-04-17 00:23:34 +00:00
parent 2ddf015a68
commit 3ab0a00959
No known key found for this signature in database
2 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,43 @@
package main
import (
"context"
"flag"
"log"
"os"
"github.com/Gleipnir-Technology/nidus-sync/lob"
)
func main() {
name := flag.String("name", "", "The name of the address")
line1 := flag.String("line1", "", "")
city := flag.String("city", "", "")
state := flag.String("state", "", "")
zip := flag.String("zip", "", "")
// Parse the flags
flag.Parse()
key := os.Getenv("LOB_API_KEY")
if key == "" {
log.Println("LOB_API_KEY is empty")
os.Exit(1)
}
client := lob.NewLob(key)
ctx := context.TODO()
req := lob.RequestAddressCreate{
AddressLine1: *line1,
AddressCity: *city,
AddressState: *state,
AddressZip: *zip,
Name: *name,
}
addr, err := client.AddressCreate(ctx, req)
if err != nil {
log.Printf("err: %v", err)
os.Exit(2)
}
log.Printf("done. Address: %s", addr.ID)
}

View file

@ -59,6 +59,31 @@ type ResponseAddressList struct {
CountTotal int `json:"total_count"`
}
type RequestAddressCreate struct {
AddressLine1 string `json:"address_line1"`
AddressCity string `json:"address_city"`
AddressState string `json:"address_state"`
AddressZip string `json:"address_zip"`
Name string `json:"name"`
}
func (l *Lob) AddressCreate(ctx context.Context, req RequestAddressCreate) (Address, error) {
var result Address
resp, err := l.client.R().
SetBody(req).
SetContext(ctx).
SetContentType("application/json").
SetResult(&result).
SetPathParam("urlBase", l.urlBaseApi).
Post("https://{urlBase}/v1/addresses")
if err != nil {
return result, fmt.Errorf("address list post: %w", err)
}
if !resp.IsSuccess() {
return result, fmt.Errorf("not successful")
}
return result, nil
}
func (l *Lob) AddressList(ctx context.Context) ([]Address, error) {
var result ResponseAddressList