-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathlongview_subscriptions.go
76 lines (66 loc) · 2.2 KB
/
longview_subscriptions.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
package linodego
import (
"fmt"
"github.com/go-resty/resty"
)
// LongviewSubscription represents a LongviewSubscription object
type LongviewSubscription struct {
ID string
Label string
ClientsIncluded int `json:"clients_included"`
Price *LinodePrice
// UpdatedStr string `json:"updated"`
// Updated *time.Time `json:"-"`
}
// LongviewSubscriptionsPagedResponse represents a paginated LongviewSubscription API response
type LongviewSubscriptionsPagedResponse struct {
*PageOptions
Data []*LongviewSubscription
}
// endpoint gets the endpoint URL for LongviewSubscription
func (LongviewSubscriptionsPagedResponse) endpoint(c *Client) string {
endpoint, err := c.LongviewSubscriptions.Endpoint()
if err != nil {
panic(err)
}
return endpoint
}
// appendData appends LongviewSubscriptions when processing paginated LongviewSubscription responses
func (resp *LongviewSubscriptionsPagedResponse) appendData(r *LongviewSubscriptionsPagedResponse) {
(*resp).Data = append(resp.Data, r.Data...)
}
// setResult sets the Resty response type of LongviewSubscription
func (LongviewSubscriptionsPagedResponse) setResult(r *resty.Request) {
r.SetResult(LongviewSubscriptionsPagedResponse{})
}
// ListLongviewSubscriptions lists LongviewSubscriptions
func (c *Client) ListLongviewSubscriptions(opts *ListOptions) ([]*LongviewSubscription, error) {
response := LongviewSubscriptionsPagedResponse{}
err := c.listHelper(&response, opts)
for _, el := range response.Data {
el.fixDates()
}
if err != nil {
return nil, err
}
return response.Data, nil
}
// fixDates converts JSON timestamps to Go time.Time values
func (v *LongviewSubscription) fixDates() *LongviewSubscription {
// v.Created, _ = parseDates(v.CreatedStr)
// v.Updated, _ = parseDates(v.UpdatedStr)
return v
}
// GetLongviewSubscription gets the template with the provided ID
func (c *Client) GetLongviewSubscription(id string) (*LongviewSubscription, error) {
e, err := c.LongviewSubscriptions.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%s", e, id)
r, err := c.R().SetResult(&LongviewSubscription{}).Get(e)
if err != nil {
return nil, err
}
return r.Result().(*LongviewSubscription).fixDates(), nil
}