Skip to content

Commit f25352b

Browse files
feat: add optional sender address filter to GetMethod
1 parent f2dbf26 commit f25352b

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

method/client.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,25 @@ func (c *Client) GetReturnMethods() ([]*sendcloud.Method, error) {
6666
return smr.GetResponse().([]*sendcloud.Method), nil
6767
}
6868

69-
// Get a single method
70-
func (c *Client) GetMethod(id int64) (*sendcloud.Method, error) {
69+
// Get a single method with optional sender_address filter
70+
func (c *Client) GetMethod(id int64, opts ...MethodOption) (*sendcloud.Method, error) {
71+
options := &methodOptions{}
72+
for _, opt := range opts {
73+
opt(options)
74+
}
75+
76+
values := url.Values{}
77+
if options.senderAddressID != nil {
78+
values.Set("sender_address", strconv.FormatInt(*options.senderAddressID, 10))
79+
}
80+
81+
reqURL := "/api/v2/shipping_methods/" + strconv.Itoa(int(id))
82+
if len(values) > 0 {
83+
reqURL += "?" + values.Encode()
84+
}
85+
7186
mr := sendcloud.MethodResponseContainer{}
72-
err := sendcloud.Request("GET", "/api/v2/shipping_methods/"+strconv.Itoa(int(id)), nil, c.apiKey, c.apiSecret, &mr)
87+
err := sendcloud.Request("GET", reqURL, nil, c.apiKey, c.apiSecret, &mr)
7388
if err != nil {
7489
return nil, err
7590
}

0 commit comments

Comments
 (0)