-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifications.go
52 lines (43 loc) · 1.29 KB
/
notifications.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
package vscale
type NotificationsService interface {
Get() (*NotificationsSettings, *Response, error)
SetNotifyBalance(int) (*NotificationsSettings, *Response, error)
}
type NotificationsServiceOp struct {
client *Client
}
var _ NotificationsService = &NotificationsServiceOp{}
type NotificationsRequest struct {
NotifyBalance int `json:"notify_balance"`
}
type NotificationsSettings struct {
NotifyBalance int `json:"notify_balance"`
Status string `json:"status,omitempty"`
}
func (s *NotificationsServiceOp) Get() (*NotificationsSettings, *Response, error) {
path := "/v1/billing/notify"
req, err := s.client.NewRequest("GET", path, nil)
if err != nil {
return nil, nil, err
}
notifSett := new(NotificationsSettings)
resp, err := s.client.Do(req, notifSett)
if err != nil {
return nil, nil, err
}
return notifSett, resp, err
}
func (s *NotificationsServiceOp) SetNotifyBalance(num int) (*NotificationsSettings, *Response, error) {
path := "/v1/billing/notify"
notifyRequest := &NotificationsRequest{NotifyBalance: num}
req, err := s.client.NewRequest("PUT", path, notifyRequest)
if err != nil {
return nil, nil, err
}
notifSett := new(NotificationsSettings)
resp, err := s.client.Do(req, notifSett)
if err != nil {
return nil, nil, err
}
return notifSett, resp, err
}