Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zendesk/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (z *Client) UploadAttachment(ctx context.Context, filename string, token st
// DeleteUpload deletes a previously uploaded file
// ref: https://developer.zendesk.com/rest_api/docs/support/attachments#delete-upload
func (z *Client) DeleteUpload(ctx context.Context, token string) error {
return z.delete(ctx, fmt.Sprintf("/uploads/%s.json", token))
return z.delete(ctx, fmt.Sprintf("/uploads/%s.json", token), nil)
}

// GetAttachment returns the current state of an uploaded attachment
Expand Down
2 changes: 1 addition & 1 deletion zendesk/automation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (z *Client) UpdateAutomation(ctx context.Context, id int64, automation Auto
//
// ref: https://developer.zendesk.com/rest_api/docs/support/automations#delete-automation
func (z *Client) DeleteAutomation(ctx context.Context, id int64) error {
err := z.delete(ctx, fmt.Sprintf("/automations/%d.json", id))
err := z.delete(ctx, fmt.Sprintf("/automations/%d.json", id), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion zendesk/brand.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (z *Client) UpdateBrand(ctx context.Context, brandID int64, brand Brand) (B
// DeleteBrand deletes the specified brand
// ref: https://developer.zendesk.com/rest_api/docs/support/brands#delete-brand
func (z *Client) DeleteBrand(ctx context.Context, brandID int64) error {
err := z.delete(ctx, fmt.Sprintf("/brands/%d.json", brandID))
err := z.delete(ctx, fmt.Sprintf("/brands/%d.json", brandID), nil)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion zendesk/dynamic_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (z *Client) UpdateDynamicContentItem(ctx context.Context, id int64, item Dy
//
// ref: https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#delete-item
func (z *Client) DeleteDynamicContentItem(ctx context.Context, id int64) error {
err := z.delete(ctx, fmt.Sprintf("/dynamic_content/items/%d.json", id))
err := z.delete(ctx, fmt.Sprintf("/dynamic_content/items/%d.json", id), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion zendesk/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (z *Client) UpdateGroup(ctx context.Context, groupID int64, group Group) (G
// DeleteGroup deletes the specified group
// ref: https://developer.zendesk.com/rest_api/docs/support/groups#delete-group
func (z *Client) DeleteGroup(ctx context.Context, groupID int64) error {
err := z.delete(ctx, fmt.Sprintf("/groups/%d.json", groupID))
err := z.delete(ctx, fmt.Sprintf("/groups/%d.json", groupID), nil)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion zendesk/macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (z *Client) UpdateMacro(ctx context.Context, macroID int64, macro Macro) (M
// DeleteMacro deletes the specified macro
// ref: https://developer.zendesk.com/rest_api/docs/support/macros#delete-macro
func (z *Client) DeleteMacro(ctx context.Context, macroID int64) error {
err := z.delete(ctx, fmt.Sprintf("/macros/%d.json", macroID))
err := z.delete(ctx, fmt.Sprintf("/macros/%d.json", macroID), nil)

if err != nil {
return err
Expand Down
32 changes: 24 additions & 8 deletions zendesk/mock/client.go

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

2 changes: 1 addition & 1 deletion zendesk/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (z *Client) UpdateOrganization(ctx context.Context, orgID int64, org Organi
// DeleteOrganization deletes the specified organization
// ref: https://developer.zendesk.com/rest_api/docs/support/organizations#delete-organization
func (z *Client) DeleteOrganization(ctx context.Context, orgID int64) error {
err := z.delete(ctx, fmt.Sprintf("/organizations/%d.json", orgID))
err := z.delete(ctx, fmt.Sprintf("/organizations/%d.json", orgID), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion zendesk/sla_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (z *Client) UpdateSLAPolicy(ctx context.Context, id int64, slaPolicy SLAPol
//
// ref: https://developer.zendesk.com/rest_api/docs/support/slas/policies#delete-slaPolicy
func (z *Client) DeleteSLAPolicy(ctx context.Context, id int64) error {
err := z.delete(ctx, fmt.Sprintf("/slas/policies/%d.json", id))
err := z.delete(ctx, fmt.Sprintf("/slas/policies/%d.json", id), nil)
if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions zendesk/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type TagAPI interface {
AddTicketTags(ctx context.Context, ticketID int64, tags []Tag) ([]Tag, error)
AddOrganizationTags(ctx context.Context, organizationID int64, tags []Tag) ([]Tag, error)
AddUserTags(ctx context.Context, userID int64, tags []Tag) ([]Tag, error)
RemoveTicketTags(ctx context.Context, ticketID int64, tags []Tag) error
}

// GetTicketTags get ticket tag list
Expand Down Expand Up @@ -144,3 +145,15 @@ func (z *Client) AddUserTags(ctx context.Context, userID int64, tags []Tag) ([]T
}
return result.Tags, nil
}

// RemoveTicketTags remove tags from ticket
//
// ref: https://developer.zendesk.com/rest_api/docs/support/tags#remove-tags
func (z *Client) RemoveTicketTags(ctx context.Context, ticketID int64, tags []Tag) error {
var data struct {
Tags []Tag `json:"tags"`
}
data.Tags = tags
err := z.delete(ctx, fmt.Sprintf("/tickets/%d/tags", ticketID), data)
return err
}
2 changes: 1 addition & 1 deletion zendesk/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (z *Client) UpdateTarget(ctx context.Context, targetID int64, field Target)
// DeleteTarget deletes the specified target
// ref: https://developer.zendesk.com/rest_api/docs/support/targets#delete-target
func (z *Client) DeleteTarget(ctx context.Context, targetID int64) error {
err := z.delete(ctx, fmt.Sprintf("/targets/%d.json", targetID))
err := z.delete(ctx, fmt.Sprintf("/targets/%d.json", targetID), nil)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion zendesk/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (z *Client) UpdateTicket(ctx context.Context, ticketID int64, ticket Ticket
// DeleteTicket deletes the specified ticket
// ref: https://developer.zendesk.com/rest_api/docs/support/tickets#delete-ticket
func (z *Client) DeleteTicket(ctx context.Context, ticketID int64) error {
err := z.delete(ctx, fmt.Sprintf("/tickets/%d.json", ticketID))
err := z.delete(ctx, fmt.Sprintf("/tickets/%d.json", ticketID), nil)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion zendesk/ticket_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (z *Client) UpdateTicketField(ctx context.Context, ticketID int64, field Ti
// DeleteTicketField deletes the specified ticket field
// ref: https://developer.zendesk.com/rest_api/docs/support/ticket_fields#delete-ticket-field
func (z *Client) DeleteTicketField(ctx context.Context, ticketID int64) error {
err := z.delete(ctx, fmt.Sprintf("/ticket_fields/%d.json", ticketID))
err := z.delete(ctx, fmt.Sprintf("/ticket_fields/%d.json", ticketID), nil)

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion zendesk/ticket_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (z *Client) UpdateTicketForm(ctx context.Context, id int64, form TicketForm
// DeleteTicketForm deletes the specified ticket form
// ref: https://developer.zendesk.com/rest_api/docs/support/ticket_forms#delete-ticket-form
func (z *Client) DeleteTicketForm(ctx context.Context, id int64) error {
err := z.delete(ctx, fmt.Sprintf("/ticket_forms/%d.json", id))
err := z.delete(ctx, fmt.Sprintf("/ticket_forms/%d.json", id), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion zendesk/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (z *Client) UpdateTrigger(ctx context.Context, id int64, trigger Trigger) (
//
// ref: https://developer.zendesk.com/rest_api/docs/support/triggers#delete-trigger
func (z *Client) DeleteTrigger(ctx context.Context, id int64) error {
err := z.delete(ctx, fmt.Sprintf("/triggers/%d.json", id))
err := z.delete(ctx, fmt.Sprintf("/triggers/%d.json", id), nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion zendesk/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (z *Client) UpdateWebhook(ctx context.Context, webhookID string, hook *Webh
//
// https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#delete-webhook
func (z *Client) DeleteWebhook(ctx context.Context, webhookID string) error {
err := z.delete(ctx, fmt.Sprintf("/webhooks/%s", webhookID))
err := z.delete(ctx, fmt.Sprintf("/webhooks/%s", webhookID), nil)
if err != nil {
return err
}
Expand Down
20 changes: 15 additions & 5 deletions zendesk/zendesk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -38,7 +39,7 @@ type (
Get(ctx context.Context, path string) ([]byte, error)
Post(ctx context.Context, path string, data interface{}) ([]byte, error)
Put(ctx context.Context, path string, data interface{}) ([]byte, error)
Delete(ctx context.Context, path string) error
Delete(ctx context.Context, path string, data interface{}) error
}

// CursorPagination contains options for using cursor pagination.
Expand Down Expand Up @@ -257,8 +258,17 @@ func (z *Client) patch(ctx context.Context, path string, data interface{}) ([]by
}

// delete sends data to API and returns an error if unsuccessful
func (z *Client) delete(ctx context.Context, path string) error {
req, err := http.NewRequest(http.MethodDelete, z.baseURL.String()+path, nil)
func (z *Client) delete(ctx context.Context, path string, data interface{}) error {
var b io.Reader
if data != nil {
bytes, err := json.Marshal(data)
if err != nil {
return err
}
b = strings.NewReader(string(bytes))
}

req, err := http.NewRequest(http.MethodDelete, z.baseURL.String()+path, b)
if err != nil {
return err
}
Expand Down Expand Up @@ -362,6 +372,6 @@ func (z *Client) Put(ctx context.Context, path string, data interface{}) ([]byte
}

// Delete allows users to send requests not yet implemented
func (z *Client) Delete(ctx context.Context, path string) error {
return z.delete(ctx, path)
func (z *Client) Delete(ctx context.Context, path string, data interface{}) error {
return z.delete(ctx, path, data)
}
4 changes: 2 additions & 2 deletions zendesk/zendesk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestDelete(t *testing.T) {
}))

c := newTestClient(mockAPI)
err := c.delete(ctx, "/foo/id")
err := c.delete(ctx, "/foo/id", nil)
if err != nil {
t.Fatalf("Failed to send request: %s", err)
}
Expand All @@ -289,7 +289,7 @@ func TestDeleteFailure(t *testing.T) {
}))

c := newTestClient(mockAPI)
err := c.delete(ctx, "/foo/id")
err := c.delete(ctx, "/foo/id", nil)
if err == nil {
t.Fatalf("Failed to recieve error from Delete")
}
Expand Down