-
Notifications
You must be signed in to change notification settings - Fork 3
/
plans.go
74 lines (65 loc) · 2.19 KB
/
plans.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
package chartmogul
const (
plansEndpoint = "plans"
singlePlanEndpoint = "plans/:uuid"
)
// Plan represents ChartMogul categorization of subscriptions.
type Plan struct {
UUID string `json:"uuid,omitempty"`
DataSourceUUID string `json:"data_source_uuid,omitempty"`
ExternalID string `json:"external_id,omitempty"`
Name string `json:"name,omitempty"`
IntervalCount uint32 `json:"interval_count,omitempty"`
IntervalUnit string `json:"interval_unit,omitempty"`
Errors Errors `json:"errors,omitempty"`
}
// Plans is result of listing: plans + paging.
type Plans struct {
Plans []*Plan `json:"plans"`
Pagination
}
// ListPlansParams = optional parameters for listing plans.
type ListPlansParams struct {
DataSourceUUID string `json:"data_source_uuid"`
ExternalID string `json:"external_id,omitempty"`
System string `json:"system,omitempty"`
Cursor
}
// CreatePlan creates plan under given Data Source.
//
// See https://dev.chartmogul.com/v1.0/reference#plans
func (api API) CreatePlan(plan *Plan) (result *Plan, err error) {
result = &Plan{}
return result, api.create(plansEndpoint, plan, result)
}
// RetrievePlan returns one plan by UUID.
//
// See https://dev.chartmogul.com/v1.0/reference#plans
func (api API) RetrievePlan(planUUID string) (*Plan, error) {
result := &Plan{}
return result, api.retrieve(singlePlanEndpoint, planUUID, result)
}
// ListPlans returns list of plans.
//
// See https://dev.chartmogul.com/v1.0/reference#plans
func (api API) ListPlans(listPlansParams *ListPlansParams) (*Plans, error) {
result := &Plans{}
query := make([]interface{}, 0, 1)
if listPlansParams != nil {
query = append(query, *listPlansParams)
}
return result, api.list(plansEndpoint, result, query...)
}
// UpdatePlan returns list of plans.
//
// See https://dev.chartmogul.com/v1.0/reference#plans
func (api API) UpdatePlan(plan *Plan, planUUID string) (*Plan, error) {
result := &Plan{}
return result, api.update(singlePlanEndpoint, planUUID, plan, result)
}
// DeletePlan deletes one plan by UUID.
//
// See https://dev.chartmogul.com/v1.0/reference#plans
func (api API) DeletePlan(planUUID string) error {
return api.delete(singlePlanEndpoint, planUUID)
}