-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclient.go
More file actions
45 lines (40 loc) · 1.18 KB
/
Copy pathclient.go
File metadata and controls
45 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package products
import (
"github.com/afosto/sendcloud-go"
"net/url"
)
type Client struct {
apiKey string
apiSecret string
}
func New(apiKey string, apiSecret string) *Client {
return &Client{
apiKey: apiKey,
apiSecret: apiSecret,
}
}
// get shipping products
func (c *Client) GetShippingProducts(fromCountry string) ([]*sendcloud.Product, error) {
smr := sendcloud.ProductListResponseContainer{}
values := url.Values{}
values.Set("from_country", fromCountry)
reqUrl := "/api/v2/shipping-products?" + values.Encode()
err := sendcloud.Request("GET", reqUrl, nil, c.apiKey, c.apiSecret, &smr)
if err != nil {
return nil, err
}
return smr.GetResponse().([]*sendcloud.Product), nil
}
// get return shipping products
func (c *Client) GetReturnShippingProducts(fromCountry string) ([]*sendcloud.Product, error) {
smr := sendcloud.ProductListResponseContainer{}
values := url.Values{}
values.Set("from_country", fromCountry)
values.Set("returns", "true")
reqUrl := "/api/v2/shipping-products?" + values.Encode()
err := sendcloud.Request("GET", reqUrl, nil, c.apiKey, c.apiSecret, &smr)
if err != nil {
return nil, err
}
return smr.GetResponse().([]*sendcloud.Product), nil
}