forked from blacklightcms/recurly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipping_methods.go
60 lines (51 loc) · 1.75 KB
/
shipping_methods.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package recurly
import (
"context"
"encoding/xml"
"fmt"
"net/http"
)
// ShippingMethodsService manages the interactions for shipping methods.
type ShippingMethodsService interface {
// ListAccount returns a pager to paginate available shipping methods.
// PagerOptions are used to optionally filter the results.
//
// https://dev.recurly.com/docs/list-shipping-methods
List(opts *PagerOptions) Pager
// Get retrieves a shipping method. If the shipping method does not exist,
// a nil shipping method and nil error are returned.
//
// https://dev.recurly.com/docs/lookup-shipping-method
Get(ctx context.Context, code string) (*ShippingMethod, error)
}
// ShippingMethod holds a shipping method.
type ShippingMethod struct {
XMLName xml.Name `xml:"shipping_method"`
Code string `xml:"code"`
Name string `xml:"name"`
AccountingCode string `xml:"accounting_code"`
TaxCode string `xml:"tax_code"`
CreatedAt NullTime `xml:"created_at"`
UpdatedAt NullTime `xml:"updated_at"`
}
var _ ShippingMethodsService = &shippingMethodsImpl{}
// shippingMethodssImpl implements ShippingMethodsService.
type shippingMethodsImpl serviceImpl
func (s *shippingMethodsImpl) List(opts *PagerOptions) Pager {
return s.client.newPager("GET", "/shipping_methods", opts)
}
func (s *shippingMethodsImpl) Get(ctx context.Context, code string) (*ShippingMethod, error) {
path := fmt.Sprintf("/shipping_methods/%s", code)
req, err := s.client.newRequest("GET", path, nil)
if err != nil {
return nil, err
}
var dst ShippingMethod
if _, err := s.client.do(ctx, req, &dst); err != nil {
if e, ok := err.(*ClientError); ok && e.Response.StatusCode == http.StatusNotFound {
return nil, nil
}
return nil, err
}
return &dst, nil
}