Skip to content

Commit

Permalink
add support for platform accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Jul 30, 2024
1 parent 860d7e3 commit 0c7361f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 11 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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")
Expand Down
14 changes: 12 additions & 2 deletions shippo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0c7361f

Please sign in to comment.