diff --git a/zendesk/group.go b/zendesk/group.go index 93629c2..fb544af 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -20,9 +20,16 @@ type Group struct { UpdatedAt time.Time `json:"updated_at,omitempty"` } +// GroupListOptions is options for GetGroups +// +// ref: https://developer.zendesk.com/rest_api/docs/support/groups#list-groups +type GroupListOptions struct { + PageOptions +} + // GroupAPI an interface containing all methods associated with zendesk groups type GroupAPI interface { - GetGroups(ctx context.Context) ([]Group, Page, error) + GetGroups(ctx context.Context, opts *GroupListOptions) ([]Group, Page, error) GetGroup(ctx context.Context, groupID int64) (Group, error) CreateGroup(ctx context.Context, group Group) (Group, error) UpdateGroup(ctx context.Context, groupID int64, group Group) (Group, error) @@ -31,13 +38,23 @@ type GroupAPI interface { // GetGroups fetches group list // https://developer.zendesk.com/rest_api/docs/support/groups#list-groups -func (z *Client) GetGroups(ctx context.Context) ([]Group, Page, error) { +func (z *Client) GetGroups(ctx context.Context, opts *GroupListOptions) ([]Group, Page, error) { var data struct { Groups []Group `json:"groups"` Page } - body, err := z.get(ctx, "/groups.json") + tmp := opts + if tmp == nil { + tmp = &GroupListOptions{} + } + + u, err := addOptions("/groups.json", tmp) + if err != nil { + return []Group{}, Page{}, err + } + + body, err := z.get(ctx, u) if err != nil { return []Group{}, Page{}, err } diff --git a/zendesk/group_test.go b/zendesk/group_test.go index b0956e5..c707dc0 100644 --- a/zendesk/group_test.go +++ b/zendesk/group_test.go @@ -11,7 +11,7 @@ func TestGetGroups(t *testing.T) { client := newTestClient(mockAPI) defer mockAPI.Close() - groups, _, err := client.GetGroups(ctx) + groups, _, err := client.GetGroups(ctx, nil) if err != nil { t.Fatalf("Failed to get groups: %s", err) } diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index b7e9e2d..571177b 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -700,9 +700,9 @@ func (mr *ClientMockRecorder) GetGroupMemberships(arg0, arg1 interface{}) *gomoc } // GetGroups mocks base method. -func (m *Client) GetGroups(arg0 context.Context) ([]zendesk.Group, zendesk.Page, error) { +func (m *Client) GetGroups(arg0 context.Context, arg1 *zendesk.GroupListOptions) ([]zendesk.Group, zendesk.Page, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetGroups", arg0) + ret := m.ctrl.Call(m, "GetGroups", arg0, arg1) ret0, _ := ret[0].([]zendesk.Group) ret1, _ := ret[1].(zendesk.Page) ret2, _ := ret[2].(error) @@ -710,9 +710,9 @@ func (m *Client) GetGroups(arg0 context.Context) ([]zendesk.Group, zendesk.Page, } // GetGroups indicates an expected call of GetGroups. -func (mr *ClientMockRecorder) GetGroups(arg0 interface{}) *gomock.Call { +func (mr *ClientMockRecorder) GetGroups(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*Client)(nil).GetGroups), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*Client)(nil).GetGroups), arg0, arg1) } // GetLocales mocks base method.