-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
53 lines (42 loc) · 1.07 KB
/
client.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
package rc
import (
"context"
"github.com/go-resty/resty/v2"
)
type Client struct {
Auth
ClientID string
}
func NewFromKeySecret(clientID, appKey, appSecret string) (*Client, error) {
return &Client{
ClientID: clientID,
Auth: &BasicAuth{
Key: appKey,
Secret: appSecret,
},
}, nil
}
func (c *Client) Request(ctx context.Context) *resty.Request {
ctx = WithAuth(ctx, c.Auth)
return Request(ctx)
}
func (c *Client) Get(ctx context.Context, uri string, params map[string]string, resp interface{}) error {
r, err := c.Request(ctx).SetQueryParams(params).Get(uri)
if err != nil {
if requestID := extractRequestID(r); requestID != "" {
return WrapErrWithRequestID(err, requestID)
}
return err
}
return UnmarshalResponse(r, resp)
}
func (c *Client) Post(ctx context.Context, uri string, body interface{}, resp interface{}) error {
r, err := c.Request(ctx).SetBody(body).Post(uri)
if err != nil {
if requestID := extractRequestID(r); requestID != "" {
return WrapErrWithRequestID(err, requestID)
}
return err
}
return UnmarshalResponse(r, resp)
}