Skip to content

Commit c8e95c7

Browse files
docs: add more examples
1 parent d2a63a5 commit c8e95c7

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,34 @@ This library provides some conveniences for working with paginated list endpoint
165165

166166
You can use `.ListAutoPaging()` methods to iterate through items across all pages:
167167

168+
```go
169+
iter := client.Admin.UserConnections.ListAutoPaging(context.TODO(), arcadego.AdminUserConnectionListParams{})
170+
// Automatically fetches more pages as needed.
171+
for iter.Next() {
172+
userConnectionResponse := iter.Current()
173+
fmt.Printf("%+v\n", userConnectionResponse)
174+
}
175+
if err := iter.Err(); err != nil {
176+
panic(err.Error())
177+
}
178+
```
179+
168180
Or you can use simple `.List()` methods to fetch a single page and receive a standard response object
169181
with additional helper methods like `.GetNextPage()`, e.g.:
170182

183+
```go
184+
page, err := client.Admin.UserConnections.List(context.TODO(), arcadego.AdminUserConnectionListParams{})
185+
for page != nil {
186+
for _, userConnection := range page.Items {
187+
fmt.Printf("%+v\n", userConnection)
188+
}
189+
page, err = page.GetNextPage()
190+
}
191+
if err != nil {
192+
panic(err.Error())
193+
}
194+
```
195+
171196
### Errors
172197

173198
When the API returns a non-success status code, we return an error with type

paginationauto_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package arcadego_test
4+
5+
import (
6+
"context"
7+
"os"
8+
"testing"
9+
10+
"github.com/ArcadeAI/arcade-go"
11+
"github.com/ArcadeAI/arcade-go/internal/testutil"
12+
"github.com/ArcadeAI/arcade-go/option"
13+
)
14+
15+
func TestAutoPagination(t *testing.T) {
16+
baseURL := "http://localhost:4010"
17+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
18+
baseURL = envURL
19+
}
20+
if !testutil.CheckTestServer(t, baseURL) {
21+
return
22+
}
23+
client := arcadego.NewClient(
24+
option.WithBaseURL(baseURL),
25+
option.WithAPIKey("My API Key"),
26+
)
27+
iter := client.Admin.UserConnections.ListAutoPaging(context.TODO(), arcadego.AdminUserConnectionListParams{})
28+
// Prism mock isn't going to give us real pagination
29+
for i := 0; i < 3 && iter.Next(); i++ {
30+
userConnection := iter.Current()
31+
t.Logf("%+v\n", userConnection.ID)
32+
}
33+
if err := iter.Err(); err != nil {
34+
t.Fatalf("err should be nil: %s", err.Error())
35+
}
36+
}

paginationmanual_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package arcadego_test
4+
5+
import (
6+
"context"
7+
"os"
8+
"testing"
9+
10+
"github.com/ArcadeAI/arcade-go"
11+
"github.com/ArcadeAI/arcade-go/internal/testutil"
12+
"github.com/ArcadeAI/arcade-go/option"
13+
)
14+
15+
func TestManualPagination(t *testing.T) {
16+
baseURL := "http://localhost:4010"
17+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
18+
baseURL = envURL
19+
}
20+
if !testutil.CheckTestServer(t, baseURL) {
21+
return
22+
}
23+
client := arcadego.NewClient(
24+
option.WithBaseURL(baseURL),
25+
option.WithAPIKey("My API Key"),
26+
)
27+
page, err := client.Admin.UserConnections.List(context.TODO(), arcadego.AdminUserConnectionListParams{})
28+
if err != nil {
29+
t.Fatalf("err should be nil: %s", err.Error())
30+
}
31+
for _, userConnection := range page.Items {
32+
t.Logf("%+v\n", userConnection.ID)
33+
}
34+
// Prism mock isn't going to give us real pagination
35+
page, err = page.GetNextPage()
36+
if err != nil {
37+
t.Fatalf("err should be nil: %s", err.Error())
38+
}
39+
if page != nil {
40+
for _, userConnection := range page.Items {
41+
t.Logf("%+v\n", userConnection.ID)
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)