diff --git a/lob/cmd/address-list/main.go b/lob/cmd/address-list/main.go new file mode 100644 index 00000000..56938b5c --- /dev/null +++ b/lob/cmd/address-list/main.go @@ -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) + } + +} diff --git a/lob/lob.go b/lob/lob.go new file mode 100644 index 00000000..46c4a7df --- /dev/null +++ b/lob/lob.go @@ -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 +}