-
Notifications
You must be signed in to change notification settings - Fork 2
/
tables.go
78 lines (65 loc) · 2 KB
/
tables.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
package coda
import (
"fmt"
"log"
)
type TableFilter struct {
Valid bool `json:"valid"`
IsVolatile bool `json:"isVolatile"`
HasUserFormula bool `json:"hasUserFormula"`
HasTodayFormula bool `json:"hasTodayFormula"`
HasNowFormula bool `json:"hasNowFormula"`
}
type Table struct {
TableReference
DisplayColumn Column `json:"displayColumn"`
RowCount int `json:"rowCount"`
Sorts []struct {
Column Column `json:"column"`
Direction string `json:"direction"`
} `json:"sorts"`
Layout string `json:"layout"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
ParentTable TableReference `json:"parentTable"`
Filter TableFilter `json:"filter"`
}
type TableReference struct {
Id string `json:"id"`
Type string `json:"type"`
TableType string `json:"tableType"`
BrowserLink string `json:"browserLink"`
Href string `json:"href"`
Name string `json:"name"`
Parent PageReference `json:"parent"`
}
type ListTablesResponse struct {
Tables []TableReference `json:"items"`
PaginationResponse
}
type ListTablesPayload struct {
SortBy string `url:"sortBy,omitempty"`
TableTypes string `url:"tableTypes,omitempty"`
PaginationPayload
}
type GetTableResponse struct {
Table
}
func (c *Client) ListTables(docId string, payload ListTablesPayload) (ListTablesResponse, error) {
docPath := fmt.Sprintf("docs/%s/tables", docId)
var tablesResp ListTablesResponse
err := c.apiCall("GET", docPath, payload, &tablesResp)
if err != nil {
log.Print("Unable to list tables with error.")
}
return tablesResp, err
}
func (c *Client) GetTable(docId string, tableIdOrName string) (GetTableResponse, error) {
docPath := fmt.Sprintf("docs/%s/tables/%s", docId, tableIdOrName)
var tableResp GetTableResponse
err := c.apiCall("GET", docPath, nil, &tableResp)
if err != nil {
log.Print("Unable to get table with error.")
}
return tableResp, err
}