forked from whitepages/go-stingray
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrate.go
60 lines (49 loc) · 1.12 KB
/
rate.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
package stingray
import (
"encoding/json"
"net/http"
)
// A Rate is a Stingray rate shaping class.
type Rate struct {
jsonResource `json:"-"`
RateProperties `json:"properties"`
}
type RateProperties struct {
Basic struct {
MaxRatePerMinute *int `json:"max_rate_per_minute,omitempty"`
MaxRatePerSecond *int `json:"max_rate_per_second,omitempty"`
Note *string `json:"note,omitempty"`
} `json:"basic"`
}
func (r *Rate) endpoint() string {
return "rate"
}
//String will return back the json as a string
func (r *Rate) String() string {
b := r.Bytes()
return string(b)
}
//Bytes will return back just the bytes
func (r *Rate) Bytes() []byte {
b, _ := jsonMarshal(r)
return b
}
func (r *Rate) decode(data []byte) error {
return json.Unmarshal(data, &r)
}
func NewRate(name string) *Rate {
r := new(Rate)
r.setName(name)
return r
}
func (c *Client) GetRate(name string) (*Rate, *http.Response, error) {
r := NewRate(name)
resp, err := c.Get(r)
if err != nil {
return nil, resp, err
}
return r, resp, nil
}
func (c *Client) ListRates() ([]string, *http.Response, error) {
return c.List(&Rate{})
}