-
Notifications
You must be signed in to change notification settings - Fork 3
/
datasources.go
104 lines (91 loc) · 3.49 KB
/
datasources.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package chartmogul
// DataSource represents API data source in ChartMogul.
// See https://dev.chartmogul.com/v1.0/reference#list-data-sources
type DataSource struct {
UUID string `json:"uuid"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
Status string `json:"status"`
System string `json:"system"`
Errors Errors `json:"errors,omitempty"`
}
// DataSources is the result of listing data sources, but doesn't contain any paging.
type DataSources struct {
DataSources []*DataSource `json:"data_sources"`
}
// ListDataSourcesParams are optional parameters for listing data sources.
type ListDataSourcesParams struct {
Name string `json:"name,omitempty"`
System string `json:"system,omitempty"`
}
// createDataSourceCall represents arguments to be marshalled into JSON.
type createDataSourceCall struct {
Name string `json:"name"`
}
const (
dataSourcesEndpoint = "data_sources"
singleDataSourceEndpoint = "data_sources/:uuid"
purgeDataSourceEndpoint = "data_sources/:uuid/dependent"
emptyDataSourceEndpoint = "data_sources/:uuid/all"
)
// CreateDataSource creates an API Data Source in ChartMogul.
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) CreateDataSource(name string) (*DataSource, error) {
ds := &DataSource{}
err := api.create(dataSourcesEndpoint, createDataSourceCall{Name: name}, ds)
return ds, err
}
// CreateDataSourceWithSystem creates an API Data Source in ChartMogul.
// * Allows other parameters than just the name.
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) CreateDataSourceWithSystem(dataSource *DataSource) (*DataSource, error) {
ds := &DataSource{}
err := api.create(dataSourcesEndpoint, dataSource, ds)
return ds, err
}
// RetrieveDataSource returns one Data Source by UUID.
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) RetrieveDataSource(dataSourceUUID string) (*DataSource, error) {
result := &DataSource{}
return result, api.retrieve(singleDataSourceEndpoint, dataSourceUUID, result)
}
// ListDataSources lists all available Data Sources (no paging).
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) ListDataSources() (*DataSources, error) {
ds := &DataSources{}
err := api.list(dataSourcesEndpoint, ds)
return ds, err
}
// ListDataSourcesWithFilters lists all available Data Sources (no paging).
// * Allows filtering.
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) ListDataSourcesWithFilters(listDataSourcesParams *ListDataSourcesParams) (*DataSources, error) {
ds := &DataSources{}
query := make([]interface{}, 0, 1)
if listDataSourcesParams != nil {
query = append(query, *listDataSourcesParams)
}
err := api.list(dataSourcesEndpoint, ds, query...)
return ds, err
}
// DeleteDataSource deletes the data source identified by its UUID.
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) DeleteDataSource(uuid string) error {
return api.delete(singleDataSourceEndpoint, uuid)
}
// PurgeDataSource deletes all the data except the data source itself and the customers
//
// See https://dev.chartmogul.com/v1.0/reference#data-sources
func (api API) PurgeDataSource(dataSourceUUID string) error {
return api.delete(purgeDataSourceEndpoint, dataSourceUUID)
}
// EmptyDataSource deletes all the data in the data source, but keeps the UUID.
func (api API) EmptyDataSource(dataSourceUUID string) error {
return api.delete(emptyDataSourceEndpoint, dataSourceUUID)
}