forked from pasali/go-tableau
/
data_sources.go
77 lines (67 loc) · 2.24 KB
/
data_sources.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
package tableau
import (
"context"
"fmt"
"github.com/pkg/errors"
"net/http"
"time"
)
// DeleteDataSourceRequest encapsulates the request for deleting a single DataSource.
type DeleteDataSourceRequest struct {
ID string
}
// GetDataSourceRequest encapsulates the request for getting a single DataSource.
type GetDataSourceRequest struct {
ID string
}
type dataSourcesResponse struct {
DataSource *DataSource `json:"dataSource"`
}
// DataSource represents a Tableau data source
type DataSource struct {
ID string `json:"id"`
Name string `json:"name"`
CertificationNote string `json:"CertificationNote"`
ContentUrl string `json:"contentUrl"`
EncryptExtracts string `json:"encryptExtracts"`
Description string `json:"description"`
WebpageUrl string `json:"webpageUrl"`
IsCertified bool `json:"isCertified"`
UseRemoteQueryAgent bool `json:"useRemoteQueryAgent"`
Type string `json:"type"`
Tags map[string]string `json:"tags"`
Owner struct {
ID string `json:"id"`
}
Project struct {
ID string `json:"id"`
Name string `json:"name"`
}
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
type dataSourcesService struct {
client *Client
}
func (dss *dataSourcesService) Get(ctx context.Context, getReq *GetDataSourceRequest) (*DataSource, error) {
path := fmt.Sprintf("sites/%s/datasources/%s", dss.client.SiteID, getReq.ID)
req, err := dss.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, errors.Wrap(err, "error creating request for get datasource")
}
ds := &dataSourcesResponse{}
err = dss.client.do(ctx, req, &ds)
if err != nil {
return nil, err
}
return ds.DataSource, nil
}
func (dss *dataSourcesService) Delete(ctx context.Context, delReq *DeleteDataSourceRequest) error {
path := fmt.Sprintf("sites/%s/datasources/%s", dss.client.SiteID, delReq.ID)
req, err := dss.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return errors.Wrap(err, "error creating request for deleting datasource")
}
err = dss.client.do(ctx, req, nil)
return err
}