From 6869945e8d7d34f9dc1ddee62d2dd86046e9692b Mon Sep 17 00:00:00 2001 From: Paolo Romolini Date: Tue, 13 Aug 2024 13:41:25 +0200 Subject: [PATCH] add filter custom objects function Signed-off-by: Paolo Romolini --- zendesk/custom_object.go | 31 ++++++++++++++ zendesk/mock/client.go | 92 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/zendesk/custom_object.go b/zendesk/custom_object.go index 259d6ac..9940436 100644 --- a/zendesk/custom_object.go +++ b/zendesk/custom_object.go @@ -73,6 +73,9 @@ type CustomObjectAPI interface { ctx context.Context, customObjectKey string, ) ([]CustomObjectField, error) + FilterCustomObjectRecords( + ctx context.Context, customObjectKey string, filterBody interface{}, opts *CursorPagination, + ) ([]CustomObjectRecord, CursorPaginationMeta, error) } // CreateCustomObjectRecord CreateCustomObject create a custom object record @@ -319,3 +322,31 @@ func (z *Client) ListCustomObjectFields( } return result.CustomObjectFields, nil } + +// FilterCustomObjectRecords +// https://developer.zendesk.com/api-reference/custom-data/custom-objects/ +// custom_object_records/#filtered-search-of-custom-object-records +func (z *Client) FilterCustomObjectRecords( + ctx context.Context, customObjectKey string, filterBody interface{}, opts *CursorPagination, +) ([]CustomObjectRecord, CursorPaginationMeta, error) { + var data struct { + FilterBody interface{} `json:"filter"` + } + + var result struct { + CustomObjectRecords []CustomObjectRecord `json:"custom_object_records"` + Meta CursorPaginationMeta `json:"meta"` + } + tmp := opts + if tmp == nil { + tmp = &CursorPagination{} + } + url := fmt.Sprintf("/custom_objects/%s/records/search", customObjectKey) + urlWithOptions, err := addOptions(url, tmp) + body, err := z.post(ctx, urlWithOptions, data) + if err != nil { + return nil, CursorPaginationMeta{}, err + } + err = json.Unmarshal(body, &result) + return result.CustomObjectRecords, result.Meta, nil +} diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index 99703e4..8f2ec37 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -283,6 +283,21 @@ func (mr *ClientMockRecorder) CreateOrganizationMembership(arg0, arg1 any) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrganizationMembership", reflect.TypeOf((*Client)(nil).CreateOrganizationMembership), arg0, arg1) } +// CreateOrganizationSubscription mocks base method. +func (m *Client) CreateOrganizationSubscription(ctx context.Context, sub zendesk.OrganizationSubscription) (zendesk.OrganizationSubscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateOrganizationSubscription", ctx, sub) + ret0, _ := ret[0].(zendesk.OrganizationSubscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateOrganizationSubscription indicates an expected call of CreateOrganizationSubscription. +func (mr *ClientMockRecorder) CreateOrganizationSubscription(ctx, sub any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrganizationSubscription", reflect.TypeOf((*Client)(nil).CreateOrganizationSubscription), ctx, sub) +} + // CreateSLAPolicy mocks base method. func (m *Client) CreateSLAPolicy(ctx context.Context, slaPolicy zendesk.SLAPolicy) (zendesk.SLAPolicy, error) { m.ctrl.T.Helper() @@ -545,6 +560,20 @@ func (mr *ClientMockRecorder) DeleteOrganization(ctx, orgID any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrganization", reflect.TypeOf((*Client)(nil).DeleteOrganization), ctx, orgID) } +// DeleteOrganizationSubscription mocks base method. +func (m *Client) DeleteOrganizationSubscription(ctx context.Context, subID int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOrganizationSubscription", ctx, subID) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOrganizationSubscription indicates an expected call of DeleteOrganizationSubscription. +func (mr *ClientMockRecorder) DeleteOrganizationSubscription(ctx, subID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrganizationSubscription", reflect.TypeOf((*Client)(nil).DeleteOrganizationSubscription), ctx, subID) +} + // DeleteSLAPolicy mocks base method. func (m *Client) DeleteSLAPolicy(ctx context.Context, id int64) error { m.ctrl.T.Helper() @@ -657,6 +686,22 @@ func (mr *ClientMockRecorder) DeleteWebhook(ctx, webhookID any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteWebhook", reflect.TypeOf((*Client)(nil).DeleteWebhook), ctx, webhookID) } +// FilterCustomObjectRecords mocks base method. +func (m *Client) FilterCustomObjectRecords(ctx context.Context, customObjectKey string, filterBody any, opts *zendesk.CursorPagination) ([]zendesk.CustomObjectRecord, zendesk.CursorPaginationMeta, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FilterCustomObjectRecords", ctx, customObjectKey, filterBody, opts) + ret0, _ := ret[0].([]zendesk.CustomObjectRecord) + ret1, _ := ret[1].(zendesk.CursorPaginationMeta) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// FilterCustomObjectRecords indicates an expected call of FilterCustomObjectRecords. +func (mr *ClientMockRecorder) FilterCustomObjectRecords(ctx, customObjectKey, filterBody, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterCustomObjectRecords", reflect.TypeOf((*Client)(nil).FilterCustomObjectRecords), ctx, customObjectKey, filterBody, opts) +} + // Get mocks base method. func (m *Client) Get(ctx context.Context, path string) ([]byte, error) { m.ctrl.T.Helper() @@ -1043,6 +1088,22 @@ func (mr *ClientMockRecorder) GetOrganizationMemberships(arg0, arg1 any) *gomock return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrganizationMemberships", reflect.TypeOf((*Client)(nil).GetOrganizationMemberships), arg0, arg1) } +// GetOrganizationSubscriptions mocks base method. +func (m *Client) GetOrganizationSubscriptions(ctx context.Context, orgID int64, opts *zendesk.OrganizationListOptions) ([]zendesk.OrganizationSubscription, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrganizationSubscriptions", ctx, orgID, opts) + ret0, _ := ret[0].([]zendesk.OrganizationSubscription) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetOrganizationSubscriptions indicates an expected call of GetOrganizationSubscriptions. +func (mr *ClientMockRecorder) GetOrganizationSubscriptions(ctx, orgID, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrganizationSubscriptions", reflect.TypeOf((*Client)(nil).GetOrganizationSubscriptions), ctx, orgID, opts) +} + // GetOrganizationTags mocks base method. func (m *Client) GetOrganizationTags(ctx context.Context, organizationID int64) ([]zendesk.Tag, error) { m.ctrl.T.Helper() @@ -1338,6 +1399,21 @@ func (mr *ClientMockRecorder) GetTicketForms(ctx, options any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketForms", reflect.TypeOf((*Client)(nil).GetTicketForms), ctx, options) } +// GetTicketOPT mocks base method. +func (m *Client) GetTicketOPT(ctx context.Context, opts *zendesk.TicketOptions) (zendesk.Ticket, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTicketOPT", ctx, opts) + ret0, _ := ret[0].(zendesk.Ticket) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTicketOPT indicates an expected call of GetTicketOPT. +func (mr *ClientMockRecorder) GetTicketOPT(ctx, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketOPT", reflect.TypeOf((*Client)(nil).GetTicketOPT), ctx, opts) +} + // GetTicketTags mocks base method. func (m *Client) GetTicketTags(ctx context.Context, ticketID int64) ([]zendesk.Tag, error) { m.ctrl.T.Helper() @@ -1353,6 +1429,22 @@ func (mr *ClientMockRecorder) GetTicketTags(ctx, ticketID any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketTags", reflect.TypeOf((*Client)(nil).GetTicketTags), ctx, ticketID) } +// GetTicketUsersCC mocks base method. +func (m *Client) GetTicketUsersCC(ctx context.Context, opts *zendesk.OBPOptions) ([]zendesk.User, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTicketUsersCC", ctx, opts) + ret0, _ := ret[0].([]zendesk.User) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetTicketUsersCC indicates an expected call of GetTicketUsersCC. +func (mr *ClientMockRecorder) GetTicketUsersCC(ctx, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketUsersCC", reflect.TypeOf((*Client)(nil).GetTicketUsersCC), ctx, opts) +} + // GetTickets mocks base method. func (m *Client) GetTickets(ctx context.Context, opts *zendesk.TicketListOptions) ([]zendesk.Ticket, zendesk.Page, error) { m.ctrl.T.Helper()