Skip to content

Commit b971c8b

Browse files
author
nukosuke
authored
Merge branch 'master' into count_tickets_in_views
2 parents ad51ebd + 76a5fe4 commit b971c8b

Some content is hidden

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

57 files changed

+4170
-736
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ jobs:
77
strategy:
88
matrix:
99
go-version:
10-
- 1.17.x
1110
- 1.18.x
1211
- 1.19.x
1312
- 1.20.x
@@ -43,7 +42,7 @@ jobs:
4342
path-to-profile: profile.cov
4443
flag-name: Go-${{ matrix.go-version }}
4544
parallel: true
46-
ignore: zendesk/mock/client.go
45+
ignore: zendesk/mock/client.go, zendesk/*_generated.go
4746

4847
finalize:
4948
needs: test

CBPMigration.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# OBP to CBP migration
2+
3+
Zendesk is [obsoleting](https://support.zendesk.com/hc/en-us/articles/4408846180634-Introducing-Pagination-Changes-Zendesk-API#h_01F7Y57A0G5M3R8JXGCQTBKVWA) Offset Based Pagination (OBP), it's recomended to start adopting Cursor Based Pagination (CBP). This SDK have created pagination Iterators to help facilite the change.
4+
5+
To use the pagination iterator, start with `NewPaginationOptions()` function, it will return a `PaginationOptions` object, you can specify the default page size in `PageSize` variable. By default, `PageSize` is 100. Then you can call the `client.GetXXXXXIterator(ctx, ops)` to return an object pagination iterator, with the iterator, you can iterator through the objects with `HasMore()` and `GetNext()` until `HasMore` return `false`.
6+
7+
```go
8+
ops := NewPaginationOptions()
9+
// ops.PageSize = 50 // PageSize can be set to 50
10+
it := client.GetTicketsIterator(ctx, ops)
11+
for it.HasMore() {
12+
tickets, err := it.GetNext()
13+
if err == nil {
14+
for _, ticket := range tickets {
15+
println(ticket.Subject)
16+
}
17+
}
18+
}
19+
```
20+
21+
If the API endpoint requires more options like organization ID, it can be set into the `Id` attribute like below example:
22+
23+
```go
24+
ops := NewPaginationOptions()
25+
ops.Sort = "updated_at"
26+
ops.PageSize = 10
27+
ops.Id = 360363695492
28+
it := client.GetOrganizationTicketsIterator(ctx, ops)
29+
30+
for it.HasMore() {
31+
tickets, err := it.GetNext()
32+
if err == nil {
33+
for _, ticket := range tickets {
34+
println(ticket.Subject)
35+
}
36+
}
37+
}
38+
```
39+
40+
For any API specific parameters, they are predefined in the `CommonOptions` struct, we can set these attributes in the `PaginationOptions` object.
41+
If new attributes are introduced to any existing or new API endpoints, it can be added into this struct.
42+
43+
```go
44+
type CommonOptions struct {
45+
Active bool `url:"active,omitempty"`
46+
Role string `url:"role,omitempty"`
47+
Roles []string `url:"role[],omitempty"`
48+
PermissionSet int64 `url:"permission_set,omitempty"`
49+
50+
// SortBy can take "assignee", "assignee.name", "created_at", "group", "id",
51+
// "locale", "requester", "requester.name", "status", "subject", "updated_at"
52+
SortBy string `url:"sort_by,omitempty"`
53+
54+
// SortOrder can take "asc" or "desc"
55+
SortOrder string `url:"sort_order,omitempty"`
56+
Sort string `url:"sort,omitempty"`
57+
Id int64
58+
GroupID int64 `json:"group_id,omitempty" url:"group_id,omitempty"`
59+
UserID int64 `json:"user_id,omitempty" url:"user_id,omitempty"`
60+
OrganizationID int64 `json:"organization_id,omitempty" url:"organization_id,omitempty"`
61+
62+
Access string `json:"access"`
63+
Category int `json:"category"`
64+
Include string `json:"include" url:"include,omitempty"`
65+
OnlyViewable bool `json:"only_viewable"`
66+
Query string `url:"query"`
67+
EndUserVisible bool `url:"end_user_visible,omitempty"`
68+
FallbackToDefault bool `url:"fallback_to_default,omitempty"`
69+
AssociatedToBrand bool `url:"associated_to_brand,omitempty"`
70+
CategoryID string `url:"category_id,omitempty"`
71+
72+
IncludeInlineImages string `url:"include_inline_images,omitempty"`
73+
}
74+
```
75+
76+
## To regenerate CBP(Cursor Based Pagination), OBP(Offset Based Pagination) helper function and Iterators
77+
78+
If a new API endpoint supports CBP, add a new element to the funcData in script/codegen/main.go file like this:
79+
80+
```go
81+
{
82+
FuncName: "Automations",
83+
ObjectName: "Automation",
84+
ApiEndpoint: "/automation.json",
85+
JsonName: "automations",
86+
FileName: "automation",
87+
},
88+
```
89+
90+
should use the script to generate the helper functions and the iterator
91+
`go run script/codegen/main.go`
92+

README.md

Lines changed: 6 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,18 @@ 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+
## Zendesk [OBP(Offset Based Pagination) to CBP(Cursor Based Pagination) migration guide](CBPMigration.md)
61+
5862
## Maintainer
63+
5964
- [nukosuke](https://github.com/nukosuke)
6065

6166
## License
@@ -64,5 +69,4 @@ MIT License.
6469

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

67-
6872
[![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)

go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ module github.com/nukosuke/go-zendesk
33
go 1.19
44

55
require (
6-
github.com/golang/mock v1.6.0
76
github.com/google/go-querystring v1.1.0
7+
go.uber.org/mock v0.3.0
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/google/go-cmp v0.5.9 // indirect
13+
github.com/pmezard/go-difflib v1.0.0 // indirect
14+
github.com/stretchr/testify v1.8.4 // indirect
15+
gopkg.in/yaml.v3 v3.0.1 // indirect
816
)

go.sum

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
2-
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
3-
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
5+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
56
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
67
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
7-
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
8-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
9-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
10-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
11-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
12-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
14-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
17-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19-
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
20-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
22-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
23-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
24-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
25-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
26-
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
27-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
28-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
11+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
12+
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
13+
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
2914
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
30-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
15+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
16+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
17+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)