Skip to content

Commit

Permalink
1. Create a code template to generate OBP/CBP functions and iterator
Browse files Browse the repository at this point in the history
2. Generated OBP/CBP functions and iterator to all supported API endpoints
3. Updated Readme with examples
  • Loading branch information
JinHuangAtZen committed Oct 9, 2023
1 parent 762f6d1 commit 8586c00
Show file tree
Hide file tree
Showing 47 changed files with 2,993 additions and 210 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# go-zendesk

[![Actions Status](https://github.com/nukosuke/go-zendesk/workflows/CI/badge.svg)](https://github.com/nukosuke/go-zendesk/actions)
[![Build status](https://ci.appveyor.com/api/projects/status/ce4p1mswjkdftv6o/branch/master?svg=true)](https://ci.appveyor.com/project/nukosuke/go-zendesk/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/nukosuke/go-zendesk/badge.svg?branch=master)](https://coveralls.io/github/nukosuke/go-zendesk?branch=master)
Expand All @@ -12,7 +13,7 @@ Zendesk API client library for Go

## Installation

``` shell
```shell
$ go get github.com/nukosuke/go-zendesk
```

Expand Down Expand Up @@ -48,14 +49,48 @@ func main() {
```

## Want to mock API?

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).
You can simulate the response from Zendesk API with it.

## To regenerate the mock client

`go generate ./...`

## To regenerate CBP(Cursor Based Pagination), OBP(Offset Based Pagination) helper function and Iterators

If a new API endpoint supports CBP, add a new element to the funcData in script/codegen/main.go file like this:

```go
{
FuncName: "Automations",
ObjectName: "Automation",
ApiEndpoint: "/automation.json",
JsonName: "automations",
FileName: "automation",
},
```
should use the script to generate the helper functions and the iterator
`go run script/codegen/main.go`

## Example for using the CBP/OBP iterator

```go
ops := NewPaginationOptions()
it := client.GetTicketsIterator(ctx, ops)
for it.HasMore() {
tickets, err := it.GetNext()
if err == nil {
for _, ticket := range tickets {
println(ticket.Subject)
}
}
}
```


## Maintainer

- [nukosuke](https://github.com/nukosuke)

## License
Expand All @@ -64,5 +99,4 @@ MIT License.

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


[![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)
285 changes: 285 additions & 0 deletions script/codegen/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8586c00

Please sign in to comment.