-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodel.go
237 lines (196 loc) · 7.8 KB
/
model.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright 2013 Matthew Baird
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tableau4go
import (
"encoding/xml"
"fmt"
"strings"
)
const API_VERSION = "2.0"
const DEFAULT_SERVER = "http://localhost:8000"
const BOUNDARY_STRING = "813e3160-3c95-11e5-a151-feff819cdc9f"
const CRLF = "\r\n"
type API struct {
Server string
Version string
Boundary string
AuthToken string
OmitDefaultSiteName bool
DefaultSiteName string
}
func DefaultApi() API {
api := NewAPI(DEFAULT_SERVER, API_VERSION, BOUNDARY_STRING, "Default", true)
return api
}
func NewAPI(server string, version string, boundary string, defaultSiteName string, omitDefaultSiteName bool) API {
fixedUpServer := server
if strings.HasSuffix(server, "/") {
fixedUpServer = server[0 : len(server)-1]
}
return API{Server: fixedUpServer, Version: version, Boundary: boundary, DefaultSiteName: defaultSiteName, OmitDefaultSiteName: omitDefaultSiteName}
}
type Project struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
Description string `json:"description,omitempty" xml:"description,attr,omitempty"`
}
type Projects struct {
Projects []Project `json:"project,omitempty" xml:"project,omitempty"`
}
func NewProject(id string, name string, description string) Project {
return Project{ID: id, Name: name, Description: description}
}
type CreateProjectResponse struct {
Project Project `json:"project,omitempty" xml:"project,omitempty"`
}
type CreateProjectRequest struct {
Request Project `json:"project,omitempty" xml:"project,omitempty"`
}
func (req CreateProjectRequest) XML() ([]byte, error) {
tmp := struct {
CreateProjectRequest
XMLName struct{} `xml:"tsRequest"`
}{CreateProjectRequest: req}
return xml.MarshalIndent(tmp, "", " ")
}
func (p Project) XML() ([]byte, error) {
return xml.MarshalIndent(p, "", " ")
}
type DatasourceCreateRequest struct {
Request Datasource `json:"datasource,omitempty" xml:"datasource,omitempty"`
}
func (req DatasourceCreateRequest) XML() ([]byte, error) {
tmp := struct {
DatasourceCreateRequest
XMLName struct{} `xml:"tsRequest"`
}{DatasourceCreateRequest: req}
return xml.MarshalIndent(tmp, "", " ")
}
type Datasource struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
Type string `json:"type,omitempty" xml:"type,attr,omitempty"`
ConnectionCredentials *ConnectionCredentials `json:"connectionCredentials,omitempty" xml:"connectionCredentials,omitempty"`
Project *Project `json:"project,omitempty" xml:"project,omitempty"`
Owner *User `json:"owner,omitempty" xml:"owner,omitempty"`
}
type Datasources struct {
Datasources []Datasource `json:"datasource,omitempty" xml:"datasource,omitempty"`
}
type QueryDatasourcesResponse struct {
Datasources Datasources `json:"datasources,omitempty" xml:"datasources,omitempty"`
}
func (ds *Datasource) XML() ([]byte, error) {
return xml.MarshalIndent(ds, "", " ")
}
type SigninRequest struct {
Request Credentials `json:"credentials,omitempty" xml:"credentials,omitempty"`
}
func (req SigninRequest) XML() ([]byte, error) {
tmp := struct {
SigninRequest
XMLName struct{} `xml:"tsRequest"`
}{SigninRequest: req}
return xml.MarshalIndent(tmp, "", " ")
}
type AuthResponse struct {
Credentials *Credentials `json:"credentials,omitempty" xml:"credentials,omitempty"`
}
type ServerInfoResponse struct {
ServerInfo ServerInfo `json:"serverInfo,omitempty" xml:"serverInfo,omitempty"`
}
type ServerInfo struct {
ProductVersion string `json:"productVersion,omitempty" xml:"productVersion,omitempty"`
RestApiVersion string `json:"restApiVersion,omitempty" xml:"restApiVersion,omitempty"`
}
type QueryProjectsResponse struct {
Projects Projects `json:"projects,omitempty" xml:"projects,omitempty"`
}
type Credentials struct {
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
Password string `json:"password,omitempty" xml:"password,attr,omitempty"`
Token string `json:"token,omitempty" xml:"token,attr,omitempty"`
Site *Site `json:"site,omitempty" xml:"site,omitempty"`
Impersonate *User `json:"user,omitempty" xml:"user,omitempty"`
}
type User struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
SiteRole string `json:"siteRole,omitempty" xml:"siteRole,attr,omitempty"`
FullName string `json:"fullName,omitempty" xml:"fullName,attr,omitempty"`
}
type QuerySitesResponse struct {
Sites Sites `json:"sites,omitempty" xml:"sites,omitempty"`
}
func (req QuerySitesResponse) XML() ([]byte, error) {
tmp := struct {
QuerySitesResponse
XMLName struct{} `xml:"tsRequest"`
}{QuerySitesResponse: req}
return xml.MarshalIndent(tmp, "", " ")
}
type Sites struct {
Sites []Site `json:"sites" xml:"sites,attr"`
}
type QuerySiteResponse struct {
Site Site `json:"site,omitempty" xml:"site,omitempty"`
}
func (req QuerySiteResponse) XML() ([]byte, error) {
tmp := struct {
QuerySiteResponse
XMLName struct{} `xml:"tsRequest"`
}{QuerySiteResponse: req}
return xml.MarshalIndent(tmp, "", " ")
}
type QueryUserOnSiteResponse struct {
User User `json:"user,omitempty" xml:"user,omitempty"`
}
func (req QueryUserOnSiteResponse) XML() ([]byte, error) {
tmp := struct {
QueryUserOnSiteResponse
XMLName struct{} `xml:"tsRequest"`
}{QueryUserOnSiteResponse: req}
return xml.MarshalIndent(tmp, "", " ")
}
type Site struct {
ID string `json:"id,omitempty" xml:"id,attr,omitempty"`
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
ContentUrl string `json:"contentUrl,omitempty" xml:"contentUrl,attr,omitempty"`
AdminMode string `json:"adminMode,omitempty" xml:"adminMode,attr,omitempty"`
UserQuota string `json:"userQuota,omitempty" xml:"userQuota,attr,omitempty"`
StorageQuota int `json:"storageQuota,omitempty" xml:"storageQuota,attr,omitempty"`
State string `json:"state,omitempty" xml:"state,attr,omitempty"`
StatusReason string `json:"statusReason,omitempty" xml:"statusReason,attr,omitempty"`
Usage *SiteUsage `json:"usage,omitempty" xml:"usage,omitempty"`
}
type SiteUsage struct {
NumberOfUsers int `json:"number-of-users" xml:"number-of-users,attr"`
Storage int `json:"storage" xml:"storage,attr"`
}
type ConnectionCredentials struct {
Name string `json:"name,omitempty" xml:"name,attr,omitempty"`
Password string `json:"password,omitempty" xml:"password,attr,omitempty"`
Embed bool `json:"embed" xml:"embed,attr"`
}
func NewConnectionCredentials(name, password string, embed bool) ConnectionCredentials {
return ConnectionCredentials{Name: name, Password: password, Embed: embed}
}
type ErrorResponse struct {
Error Terror `json:"error,omitempty" xml:"error,omitempty"`
}
type Terror struct {
Code string `json:"code,omitempty" xml:"code,attr,omitempty"`
Summary string `json:"summary,omitempty" xml:"summary,omitempty"`
Detail string `json:"detail,omitempty" xml:"detail,omitempty"`
}
func (t Terror) Error() string {
return fmt.Sprintf("Code:%s, Summary:%s, Detail:%s", t.Code, t.Summary, t.Detail)
}