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 9, 2024
1 parent bed9f71 commit 10d0659
Show file tree
Hide file tree
Showing 3 changed files with 197 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)
69 changes: 69 additions & 0 deletions zendesk/custom_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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 int `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) ([]CustomStatus, error)
ShowCustomTicketStatus(ctx context.Context, customStatusID int64) (*CustomStatus, error)
}

// ListCustomTicketStatuses mocks base method.
func (z *Client) ListCustomTicketStatuses(ctx context.Context) ([]CustomStatus, error) {
var data struct {
CustomStatuses []CustomStatus `json:"custom_statuses"`
}

body, err := z.get(ctx, "custom_statuses.json")
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_status/%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 10d0659

Please sign in to comment.