Initial success talking to lob directly with my own client

This commit is contained in:
Eli Ribble 2026-04-16 22:41:43 +00:00
parent c0935c848b
commit 97ec0667a5
No known key found for this signature in database
2 changed files with 86 additions and 0 deletions

View file

@ -0,0 +1,26 @@
package main
import (
"context"
"log"
"os"
"github.com/Gleipnir-Technology/nidus-sync/lob"
)
func main() {
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()
_, err := client.AddressList(ctx)
if err != nil {
log.Printf("err: %v", err)
os.Exit(2)
}
}

60
lob/lob.go Normal file
View file

@ -0,0 +1,60 @@
package lob
import (
"context"
"crypto/tls"
"fmt"
"os"
"github.com/rs/zerolog/log"
"resty.dev/v3"
)
type Lob struct {
APIKey string
client *resty.Client
urlBaseApi string
}
func NewLob(api_key string) *Lob {
r := resty.New()
if os.Getenv("LOB_INSECURE_SKIP_VERIFY") != "" {
log.Warn().Msg("Using insecure TLS verification settings")
r.SetTLSClientConfig(&tls.Config{
InsecureSkipVerify: true,
})
}
r.SetBasicAuth(api_key, "")
l := &Lob{
APIKey: api_key,
client: r,
urlBaseApi: "api.lob.com",
}
return l
}
type Address struct{}
type ResponseAddressList struct {
Addresses []Address `json:"data"`
Count int `json:"count"`
CountTotal int `json:"total_count"`
}
func (l *Lob) AddressList(ctx context.Context) ([]*Address, error) {
var result ResponseAddressList
resp, err := l.client.R().
//SetQueryParamsFromValues(query).
SetContext(ctx).
SetResult(&result).
SetPathParam("urlBase", l.urlBaseApi).
Get("https://{urlBase}/v1/addresses")
if err != nil {
return nil, fmt.Errorf("address list get: %w", err)
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("not successful")
}
return []*Address{}, nil
}