Skip to content

Commit 8586c00

Browse files
author
Jin Huang
committed
1. Create a code template to generate OBP/CBP functions and iterator
2. Generated OBP/CBP functions and iterator to all supported API endpoints 3. Updated Readme with examples
1 parent 762f6d1 commit 8586c00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2993
-210
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# go-zendesk
2+
23
[![Actions Status](https://github.com/nukosuke/go-zendesk/workflows/CI/badge.svg)](https://github.com/nukosuke/go-zendesk/actions)
34
[![Build status](https://ci.appveyor.com/api/projects/status/ce4p1mswjkdftv6o/branch/master?svg=true)](https://ci.appveyor.com/project/nukosuke/go-zendesk/branch/master)
45
[![Coverage Status](https://coveralls.io/repos/github/nukosuke/go-zendesk/badge.svg?branch=master)](https://coveralls.io/github/nukosuke/go-zendesk?branch=master)
@@ -12,7 +13,7 @@ Zendesk API client library for Go
1213

1314
## Installation
1415

15-
``` shell
16+
```shell
1617
$ go get github.com/nukosuke/go-zendesk
1718
```
1819

@@ -48,14 +49,48 @@ func main() {
4849
```
4950

5051
## Want to mock API?
52+
5153
go-zendesk has a [mock package](https://pkg.go.dev/github.com/nukosuke/go-zendesk/zendesk/mock) generated by [golang/mock](https://github.com/golang/mock).
5254
You can simulate the response from Zendesk API with it.
5355

5456
## To regenerate the mock client
5557

5658
`go generate ./...`
5759

60+
## To regenerate CBP(Cursor Based Pagination), OBP(Offset Based Pagination) helper function and Iterators
61+
62+
If a new API endpoint supports CBP, add a new element to the funcData in script/codegen/main.go file like this:
63+
64+
```go
65+
{
66+
FuncName: "Automations",
67+
ObjectName: "Automation",
68+
ApiEndpoint: "/automation.json",
69+
JsonName: "automations",
70+
FileName: "automation",
71+
},
72+
```
73+
should use the script to generate the helper functions and the iterator
74+
`go run script/codegen/main.go`
75+
76+
## Example for using the CBP/OBP iterator
77+
78+
```go
79+
ops := NewPaginationOptions()
80+
it := client.GetTicketsIterator(ctx, ops)
81+
for it.HasMore() {
82+
tickets, err := it.GetNext()
83+
if err == nil {
84+
for _, ticket := range tickets {
85+
println(ticket.Subject)
86+
}
87+
}
88+
}
89+
```
90+
91+
5892
## Maintainer
93+
5994
- [nukosuke](https://github.com/nukosuke)
6095

6196
## License
@@ -64,5 +99,4 @@ MIT License.
6499

65100
See the file [LICENSE](./LICENSE).
66101

67-
68102
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fnukosuke%2Fgo-zendesk.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fnukosuke%2Fgo-zendesk?ref=badge_large)

script/codegen/main.go

Lines changed: 285 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)