-
Notifications
You must be signed in to change notification settings - Fork 18
/
address.go
64 lines (51 loc) · 1.65 KB
/
address.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
61
62
63
64
package proton
import (
"context"
"github.com/go-resty/resty/v2"
"golang.org/x/exp/slices"
)
func (c *Client) GetAddresses(ctx context.Context) ([]Address, error) {
var res struct {
Addresses []Address
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/core/v4/addresses")
}); err != nil {
return nil, err
}
slices.SortFunc(res.Addresses, func(a, b Address) bool {
return a.Order < b.Order
})
return res.Addresses, nil
}
func (c *Client) GetAddress(ctx context.Context, addressID string) (Address, error) {
var res struct {
Address Address
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/core/v4/addresses/" + addressID)
}); err != nil {
return Address{}, err
}
return res.Address, nil
}
func (c *Client) OrderAddresses(ctx context.Context, req OrderAddressesReq) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetBody(req).Put("/core/v4/addresses/order")
})
}
func (c *Client) EnableAddress(ctx context.Context, addressID string) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.Put("/core/v4/addresses/" + addressID + "/enable")
})
}
func (c *Client) DisableAddress(ctx context.Context, addressID string) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.Put("/core/v4/addresses/" + addressID + "/disable")
})
}
func (c *Client) DeleteAddress(ctx context.Context, addressID string) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.Delete("/core/v4/addresses/" + addressID)
})
}