Skip to content

Commit b3e2843

Browse files
improve documentation
1 parent 0db937f commit b3e2843

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,50 @@
44

55
# golark
66

7-
Golark is a go client for Skylark CMS APIs.
7+
Golark makes it easy to build Skylark API requests in golang.
8+
9+
```go
10+
package main
11+
12+
import (
13+
"github.com/SoMuchForSubtlety/golark"
14+
)
15+
16+
type episode struct {
17+
Title string `json:"title"`
18+
Subtitle string `json:"subtitle"`
19+
UID string `json:"uid"`
20+
DataSourceID string `json:"data_source_id"`
21+
Items []string `json:"items"`
22+
}
23+
24+
func main() {
25+
var ep episode
26+
27+
// request an object
28+
golark.NewRequest("https://test.com/api/", "episodes", "ep_123").
29+
Execute(&ep)
30+
31+
// request an object with only certain fields
32+
golark.NewRequest("https://test.com/api/", "episodes", "ep_123").
33+
AddField(golark.NewField("title")).
34+
AddField(golark.NewField("subtitle")).
35+
AddField(golark.NewField("uid")).
36+
Execute(&ep)
37+
38+
type container struct {
39+
Objects []episode `json:"objects"`
40+
}
41+
42+
var eps container
43+
44+
// request all members of a collection
45+
golark.NewRequest("https://test.com/api/", "episodes", "").
46+
Execute(&eps)
47+
48+
// request all members of a collection with certain properties
49+
golark.NewRequest("https://test.com/api/", "episodes", "").
50+
WithFilter("title", golark.NewFilter(golark.Equals, "test episode title")).
51+
Execute(&eps)
52+
}
53+
```

exaple_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,46 @@ func ExampleRequest_all() {
3939
log.Fatal(err)
4040
}
4141
}
42+
43+
// AddField lets you limit requests to certain fields, this can speed them up significanty.
44+
func ExampleRequest_AddField() {
45+
NewRequest("https://test.com/api/", "person", "pers_123").
46+
AddField(NewField("first_name")).
47+
AddField(NewField("last_name"))
48+
}
49+
50+
func ExampleRequest_Expand() {
51+
NewRequest("https://test.com/api/", "person", "pers_123").
52+
Expand(NewField("team_url"))
53+
}
54+
55+
func ExampleRequest_OrderBy() {
56+
NewRequest("https://test.com/api/", "person", "").
57+
OrderBy(NewField("first_name"))
58+
}
59+
60+
// Filters are helpful to search for onjects with knowing their ID
61+
func ExampleRequest_WithFilter() {
62+
NewRequest("https://test.com/api/", "person", "").
63+
WithFilter("first_name", NewFilter(Equals, "Bob"))
64+
}
65+
66+
func ExampleRequest_WithFilter_greater_than() {
67+
NewRequest("https://test.com/api/", "person", "").
68+
WithFilter("salary", NewFilter(GreaterThan, "10000"))
69+
}
70+
71+
// You can use comma separated lists to query multiple objects at once.
72+
func ExampleRequest_WithFilter_multiple() {
73+
NewRequest("https://test.com/api/", "person", "").
74+
WithFilter("first_name", NewFilter(Equals, "Bob,Lucas,Sue"))
75+
}
76+
77+
func ExampleField_WithSubField() {
78+
NewRequest("https://test.com/api/", "person", "").
79+
AddField(NewField("first_name")).
80+
AddField(NewField("team_url").
81+
WithSubField(NewField("name")).
82+
WithSubField(NewField("nation_url").
83+
WithSubField(NewField("name"))))
84+
}

0 commit comments

Comments
 (0)