account_warning.go raw
1 package rest
2
3 import (
4 "net/http"
5
6 "gopkg.in/ns1/ns1-go.v2/rest/model/account"
7 )
8
9 // WarningsService handles 'account/usagewarnings' endpoint.
10 type WarningsService service
11
12 // Get returns toggles and thresholds used when sending overage warning
13 // alert messages to users with billing notifications enabled.
14 //
15 // NS1 API docs: https://ns1.com/api/#usagewarnings-get
16 func (s *WarningsService) Get() (*account.UsageWarning, *http.Response, error) {
17 req, err := s.client.NewRequest("GET", "account/usagewarnings", nil)
18 if err != nil {
19 return nil, nil, err
20 }
21
22 var uw account.UsageWarning
23 resp, err := s.client.Do(req, &uw)
24 if err != nil {
25 return nil, resp, err
26 }
27
28 return &uw, resp, nil
29 }
30
31 // Update changes alerting toggles and thresholds for overage warning alert messages.
32 //
33 // NS1 API docs: https://ns1.com/api/#usagewarnings-post
34 func (s *WarningsService) Update(uw *account.UsageWarning) (*http.Response, error) {
35 req, err := s.client.NewRequest("POST", "account/usagewarnings", &uw)
36 if err != nil {
37 return nil, err
38 }
39
40 // Update usagewarnings fields with data from api(ensure consistent)
41 resp, err := s.client.Do(req, &uw)
42 if err != nil {
43 return resp, err
44 }
45
46 return resp, nil
47 }
48