-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhooks.go
79 lines (66 loc) · 1.53 KB
/
webhooks.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package openpay
import (
"encoding/json"
"net/http"
"path"
)
// Defines the public interface required to access available 'webhooks' methods
type WebhooksAPI interface {
// https://www.openpay.mx/docs/api/#crear-un-webhook
Create(wh *Webhook) error
// https://www.openpay.mx/docs/api/#obtener-un-webhook
Get(whID string) (*Webhook, error)
// https://www.openpay.mx/docs/api/#listado-de-webhook
List() ([]Webhook, error)
// https://www.openpay.mx/docs/api/#eliminar-un-webhook
Delete(whID string) error
}
type webhooksClient struct {
c *Client
}
func (wc *webhooksClient) Create(wh *Webhook) error {
b, err := wc.c.request(&requestOptions{
endpoint: "webhooks",
method: http.MethodPost,
data: wh,
})
if err != nil {
return err
}
json.Unmarshal(b, wh)
return nil
}
func (wc *webhooksClient) Get(whID string) (*Webhook, error) {
b, err := wc.c.request(&requestOptions{
endpoint: path.Join("webhooks", whID),
method: http.MethodGet,
data: nil,
})
if err != nil {
return nil, err
}
w := &Webhook{}
json.Unmarshal(b, w)
return w, nil
}
func (wc *webhooksClient) List() ([]Webhook, error) {
b, err := wc.c.request(&requestOptions{
endpoint: "webhooks",
method: http.MethodGet,
data: nil,
})
if err != nil {
return nil, err
}
var list []Webhook
json.Unmarshal(b, &list)
return list, nil
}
func (wc *webhooksClient) Delete(whID string) error {
_, err := wc.c.request(&requestOptions{
endpoint: path.Join("webhooks", whID),
method: http.MethodDelete,
data: nil,
})
return err
}