From de64965a553767edb077adfbbe01fc8d920870c2 Mon Sep 17 00:00:00 2001 From: Paolo Romolini Date: Thu, 5 Oct 2023 15:38:31 +0200 Subject: [PATCH] add CBP get users by group Signed-off-by: Paolo Romolini --- script/codegen/main.go | 8 ++++ zendesk/group_users_generated.go | 79 ++++++++++++++++++++++++++++++++ zendesk/user.go | 5 +- 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 zendesk/group_users_generated.go diff --git a/script/codegen/main.go b/script/codegen/main.go index 56cff823..c0635d0c 100644 --- a/script/codegen/main.go +++ b/script/codegen/main.go @@ -217,6 +217,14 @@ var funcData []FuncTemplateData = []FuncTemplateData{ FileName: "organization_users", ExtraParam: true, }, + { + FuncName: "GroupUsers", + ObjectName: "User", + ApiEndpoint: "/groups/%d/users.json", + JsonName: "users", + FileName: "group_users", + ExtraParam: true, + }, { FuncName: "Views", ObjectName: "View", diff --git a/zendesk/group_users_generated.go b/zendesk/group_users_generated.go new file mode 100644 index 00000000..47ad61b0 --- /dev/null +++ b/zendesk/group_users_generated.go @@ -0,0 +1,79 @@ + +// Code generated by Script. DO NOT EDIT. +// Source: script/codegen/main.go +// +// Generated by this command: +// +// go run script/codegen/main.go + +package zendesk + +import ( + "context" + "fmt" +) + +func (z *Client) GetGroupUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] { + return &Iterator[User]{ + CommonOptions: opts.CommonOptions, + pageSize: opts.PageSize, + hasMore: true, + isCBP: opts.IsCBP, + pageAfter: "", + pageIndex: 1, + ctx: ctx, + obpFunc: z.GetGroupUsersOBP, + cbpFunc: z.GetGroupUsersCBP, + } +} + +func (z *Client) GetGroupUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) { + var data struct { + Users []User `json:"users"` + Page + } + + tmp := opts + if tmp == nil { + tmp = &OBPOptions{} + } + + path := fmt.Sprintf("/groups/%d/users.json", tmp.Id) + u, err := addOptions(path, tmp) + + if err != nil { + return nil, Page{}, err + } + + err = getData(z, ctx, u, &data) + if err != nil { + return nil, Page{}, err + } + return data.Users, data.Page, nil +} + +func (z *Client) GetGroupUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) { + var data struct { + Users []User `json:"users"` + Meta CursorPaginationMeta `json:"meta"` + } + + tmp := opts + if tmp == nil { + tmp = &CBPOptions{} + } + + path := fmt.Sprintf("/groups/%d/users.json", tmp.Id) + u, err := addOptions(path, tmp) + + if err != nil { + return nil, data.Meta, err + } + + err = getData(z, ctx, u, &data) + if err != nil { + return nil, data.Meta, err + } + return data.Users, data.Meta, nil +} + diff --git a/zendesk/user.go b/zendesk/user.go index 7dacf0e8..91940572 100644 --- a/zendesk/user.go +++ b/zendesk/user.go @@ -128,6 +128,9 @@ type UserAPI interface { GetOrganizationUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] GetOrganizationUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) GetOrganizationUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) + GetGroupUsersIterator(ctx context.Context, opts *PaginationOptions) *Iterator[User] + GetGroupUsersOBP(ctx context.Context, opts *OBPOptions) ([]User, Page, error) + GetGroupUsersCBP(ctx context.Context, opts *CBPOptions) ([]User, CursorPaginationMeta, error) } // GetUsers fetch user list @@ -256,8 +259,6 @@ func (z *Client) GetManyUsers(ctx context.Context, opts *GetManyUsersOptions) ([ return data.Users, data.Page, nil } -//TODO: GetUsersByGroupID, GetUsersByOrganizationID - // CreateUser creates new user // ref: https://developer.zendesk.com/api-reference/ticketing/users/users/#create-user func (z *Client) CreateUser(ctx context.Context, user User) (User, error) {