-
Notifications
You must be signed in to change notification settings - Fork 2
/
views.go
70 lines (61 loc) · 1.69 KB
/
views.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
package coda
import (
"fmt"
"log"
)
type View struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Name string `json:"name"`
BrowserLink string `json:"browserLink"`
DisplayColumn Column `json:"displayColumn"`
RowCount int `json:"rowCount"`
Sorts []struct {
Column Column `json:"column"`
Direction string `json:"direction"`
}
Layout string `json:"layout"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type ListViewsParameters struct {
TableType string `url:"tableTypes"`
PaginationPayload
}
type ListViewsResponse struct {
Views []View `json:"items"`
PaginationResponse
}
type GetViewResponse struct {
View
}
func (c *Client) ListViews(docId string, paginationPayload PaginationPayload) (ListViewsResponse, error) {
docPath := fmt.Sprintf("docs/%s/tables", docId)
params := ListViewsParameters{
TableType: "view",
PaginationPayload: paginationPayload,
}
var viewsResponse ListViewsResponse
err := c.apiCall("GET", docPath, params, &viewsResponse)
if err != nil {
log.Print("Unable to make api call with error.")
return viewsResponse, err
}
return viewsResponse, err
}
func (c *Client) GetView(docId string, viewIdOrName string) (GetViewResponse, error) {
docPath := fmt.Sprintf("docs/%s/tables/%s", docId, viewIdOrName)
req, err := c.newRequest("GET", docPath, nil)
if err != nil {
log.Print("Unable to create new request.")
return GetViewResponse{}, err
}
var viewResponse GetViewResponse
_, err = c.do(req, &viewResponse)
if err != nil {
log.Print("Unable to make request.")
return GetViewResponse{}, err
}
return viewResponse, err
}