-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathbrand.go
112 lines (92 loc) · 3.12 KB
/
brand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package zendesk
import (
"context"
"encoding/json"
"fmt"
"time"
)
// Brand is struct for brand payload
// https://developer.zendesk.com/rest_api/docs/support/brands
type Brand struct {
ID int64 `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Name string `json:"name"`
BrandURL string `json:"brand_url,omitempty"`
HasHelpCenter bool `json:"has_help_center,omitempty"`
HelpCenterState string `json:"help_center_state,omitempty"`
Active bool `json:"active,omitempty"`
Default bool `json:"default,omitempty"`
Logo Attachment `json:"logo,omitempty"`
TicketFormIDs []int64 `json:"ticket_form_ids,omitempty"`
Subdomain string `json:"subdomain"`
HostMapping string `json:"host_mapping,omitempty"`
SignatureTemplate string `json:"signature_template"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
// BrandAPI an interface containing all methods associated with zendesk brands
type BrandAPI interface {
CreateBrand(ctx context.Context, brand Brand) (Brand, error)
GetBrand(ctx context.Context, brandID int64) (Brand, error)
UpdateBrand(ctx context.Context, brandID int64, brand Brand) (Brand, error)
DeleteBrand(ctx context.Context, brandID int64) error
}
// CreateBrand creates new brand
// https://developer.zendesk.com/rest_api/docs/support/brands#create-brand
func (z *Client) CreateBrand(ctx context.Context, brand Brand) (Brand, error) {
var data, result struct {
Brand Brand `json:"brand"`
}
data.Brand = brand
body, err := z.post(ctx, "/brands.json", data)
if err != nil {
return Brand{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return Brand{}, err
}
return result.Brand, nil
}
// GetBrand gets a specified brand
// ref: https://developer.zendesk.com/rest_api/docs/support/brands#show-brand
func (z *Client) GetBrand(ctx context.Context, brandID int64) (Brand, error) {
var result struct {
Brand Brand `json:"brand"`
}
body, err := z.get(ctx, fmt.Sprintf("/brands/%d.json", brandID))
if err != nil {
return Brand{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return Brand{}, err
}
return result.Brand, err
}
// UpdateBrand updates a brand with the specified brand
// ref: https://developer.zendesk.com/rest_api/docs/support/brands#update-brand
func (z *Client) UpdateBrand(ctx context.Context, brandID int64, brand Brand) (Brand, error) {
var result, data struct {
Brand Brand `json:"brand"`
}
data.Brand = brand
body, err := z.put(ctx, fmt.Sprintf("/brands/%d.json", brandID), data)
if err != nil {
return Brand{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return Brand{}, err
}
return result.Brand, err
}
// 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))
if err != nil {
return err
}
return nil
}