-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathexample_test.go
143 lines (114 loc) · 2.75 KB
/
example_test.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
package airtable_test
import (
"fmt"
"os"
airtable "github.com/fabioberger/airtable-go"
)
func ExampleNew() {
airtableAPIKey := os.Getenv("AIRTABLE_API_KEY")
baseID := "apphllLCpWnySSF7q"
client, err := airtable.New(airtableAPIKey, baseID)
if err != nil {
panic(err)
}
fmt.Println(client)
}
func ExampleClient_CreateRecord() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
type task struct {
AirtableID string
Fields struct {
Name string
Notes string
}
}
aTask := task{}
aTask.Fields.Name = "Contact suppliers"
aTask.Fields.Notes = "Get pricing on both the blue and green variants"
client.CreateRecord("TABLE_NAME", &aTask)
// aTask.AirtableID is now set to the newly created Airtable recordID
}
func ExampleClient_DestroyRecord() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
if err := client.DestroyRecord("TABLE_NAME", "RECORD_ID"); err != nil {
panic(err)
}
}
func ExampleClient_ListRecords() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
type task struct {
AirtableID string
Fields struct {
Name string
Notes string
}
}
tasks := []task{}
if err := client.ListRecords("TABLE_NAME", &tasks); err != nil {
panic(err)
}
fmt.Println(tasks)
}
func ExampleClient_RetrieveRecord() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
type task struct {
AirtableID string
Fields struct {
Name string
Notes string
}
}
retrievedTask := task{}
if err := client.RetrieveRecord("TABLE_NAME", "RECORD_ID", &retrievedTask); err != nil {
panic(err)
}
fmt.Println(retrievedTask)
}
func ExampleClient_UpdateRecord() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
type task struct {
AirtableID string
Fields struct {
Name string
Notes string
}
}
aTask := task{}
aTask.Fields.Name = "Clean kitchen"
aTask.Fields.Notes = "Make sure to clean all the counter tops"
UpdatedFields := map[string]interface{}{
"Name": "Clean entire kitchen",
}
if err := client.UpdateRecord("TABLE_NAME", "RECORD_ID", UpdatedFields, &aTask); err != nil {
panic(err)
}
fmt.Println(aTask)
}
func ExampleListParameters() {
client, _ := airtable.New("AIRTABLE_API_KEY", "BASE_ID")
type task struct {
AirtableID string
Fields struct {
Name string
Notes string
Priority int
}
}
listParams := airtable.ListParameters{
Fields: []string{"Name", "Notes", "Priority"},
FilterByFormula: "{Priority} < 2",
MaxRecords: 50,
Sort: []airtable.SortParameter{
airtable.SortParameter{
Field: "Priority",
ShouldSortDesc: true,
},
},
View: "Main View",
}
tasks := []task{}
if err := client.ListRecords("TABLE_NAME", &tasks, listParams); err != nil {
panic(err)
}
fmt.Println(tasks)
}