From 0c7361f2c942cfa06d258f09e44ce4aeaebcfd48 Mon Sep 17 00:00:00 2001 From: Robert Trencheny Date: Tue, 30 Jul 2024 13:16:29 -0400 Subject: [PATCH] add support for platform accounts --- client/client.go | 17 +++++++++++------ shippo.go | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index 67b19f5..859daa1 100644 --- a/client/client.go +++ b/client/client.go @@ -18,18 +18,20 @@ const ( ) type Client struct { - privateToken string - apiVersion string - logger *log.Logger + privateToken string + apiVersion string + platformAccountID string + logger *log.Logger } type listOutputCallback func(v json.RawMessage) error // NewClient creates a new Shippo API client instance. -func NewClient(privateToken, apiVersion string) *Client { +func NewClient(privateToken, apiVersion, platformAccountID string) *Client { return &Client{ - privateToken: privateToken, - apiVersion: apiVersion, + privateToken: privateToken, + apiVersion: apiVersion, + platformAccountID: platformAccountID, } } @@ -145,6 +147,9 @@ func (c *Client) createRequest(method, url string, bodyObject interface{}) (req if c.apiVersion != "" { req.Header.Set("Shippo-API-Version", c.apiVersion) } + if c.platformAccountID != "" { + req.Header.Set("Shippo-Account-ID", c.platformAccountID) + } // no keep-alive req.Header.Set("Connection", "close") diff --git a/shippo.go b/shippo.go index 24f25de..9c9f093 100644 --- a/shippo.go +++ b/shippo.go @@ -11,10 +11,20 @@ const ( // NewClient creates a new Shippo client. func NewClient(privateToken string) *client.Client { - return client.NewClient(privateToken, "") + return client.NewClient(privateToken, "", "") } // NewClientWithVersion creates a new Shippo client with API version explicitly specified. func NewClientWithVersion(privateToken, apiVersion string) *client.Client { - return client.NewClient(privateToken, apiVersion) + return client.NewClient(privateToken, apiVersion, "") +} + +// NewClientWithPlatformAccountID creates a new Shippo client with platform account ID explicitly specified. +func NewClientWithPlatformAccountID(privateToken, platformAccountID string) *client.Client { + return client.NewClient(privateToken, "", platformAccountID) +} + +// NewClientWithVersionAndPlatformAccountID creates a new Shippo client with API version and platform account ID explicitly specified. +func NewClientWithVersionAndPlatformAccountID(privateToken, apiVersion, platformAccountID string) *client.Client { + return client.NewClient(privateToken, apiVersion, platformAccountID) }