Skip to content

Commit

Permalink
add custom statuses API
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Romolini <paolo.romolini@enterprisedb.com>
  • Loading branch information
paoloromolini committed Feb 13, 2024
1 parent bed9f71 commit 508aacb
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 21 deletions.
1 change: 1 addition & 0 deletions zendesk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type API interface {
ViewAPI
WebhookAPI
CustomObjectAPI
CustomStatusAPI
}

var _ API = (*Client)(nil)
82 changes: 82 additions & 0 deletions zendesk/custom_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package zendesk

import (
"context"
"encoding/json"
"fmt"
"time"
)

type CustomStatus struct {
Active bool `json:"active"`
AgentLabel string `json:"agent_label"`
CreatedAt time.Time `json:"created_at"`
Default bool `json:"default"`
Description string `json:"description"`
EndUserDescription string `json:"end_user_description"`
EndUserLabel string `json:"end_user_label"`
ID int64 `json:"id"`
RawAgentLabel string `json:"raw_agent_label"`
RawDescription string `json:"raw_description"`
RawEndUserDescription string `json:"raw_end_user_description"`
RawEndUserLabel string `json:"raw_end_user_label"`
StatusCategory string `json:"status_category"`
UpdatedAt time.Time `json:"updated_at"`
}

// CustomStatusAPI an interface containing all custom status related methods
type CustomStatusAPI interface {
ListCustomTicketStatuses(ctx context.Context, opts *CustomTicketStatusOptions) ([]CustomStatus, error)
ShowCustomTicketStatus(ctx context.Context, customStatusID int64) (*CustomStatus, error)
}

// CustomTicketStatusOptions list custom status options
type CustomTicketStatusOptions struct {
Active bool `url:"active,omitempty"`
Default bool `url:"default,omitempty"`
StatusCategories string `url:"status_categories,omitempty"`
}

// ListCustomTicketStatuses mocks base method.
// https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/#list-custom-ticket-statuses
func (z *Client) ListCustomTicketStatuses(
ctx context.Context, opts *CustomTicketStatusOptions,
) ([]CustomStatus, error) {
var data struct {
CustomStatuses []CustomStatus `json:"custom_statuses"`
}
tmp := opts
if tmp == nil {
tmp = &CustomTicketStatusOptions{}
}
u, err := addOptions("/custom_statuses.json", tmp)
body, err := z.get(ctx, u)
if err != nil {
return []CustomStatus{}, err
}

err = json.Unmarshal(body, &data)
if err != nil {
return []CustomStatus{}, err
}
return data.CustomStatuses, nil
}

// ShowCustomTicketStatus returns the custom ticket status object
func (z *Client) ShowCustomTicketStatus(ctx context.Context, customStatusID int64) (*CustomStatus, error) {
var result struct {
CustomStatus CustomStatus `json:"custom_status"`
}
url := fmt.Sprintf("/custom_statuses/%d", customStatusID)
body, err := z.get(ctx, url)

if err != nil {
return nil, err
}
err = json.Unmarshal(body, &result)

if err != nil {
return nil, err
}
return &result.CustomStatus, nil
}
148 changes: 127 additions & 21 deletions zendesk/mock/client.go

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

0 comments on commit 508aacb

Please sign in to comment.