forked from nukosuke/go-zendesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_content.go
74 lines (65 loc) · 2.48 KB
/
dynamic_content.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
package zendesk
import (
"encoding/json"
"time"
)
// DynamicContentItem is zendesk dynamic content item JSON payload format
// https://developer.zendesk.com/rest_api/docs/support/users
type DynamicContentItem struct {
ID int64 `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Name string `json:"name"`
Placeholder string `json:"placeholder,omitempty"`
DefaultLocaleID int64 `json:"default_locale_id"`
Outdated bool `json:"outdated,omitempty"`
Variants []DynamicContentVariant `json:"variants"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
// DynamicContentVariant is zendesk dynamic content variant JSON payload format
// https://developer.zendesk.com/rest_api/docs/support/dynamic_content#json-format-for-variants
type DynamicContentVariant struct {
ID int64 `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Content string `json:"content"`
LocaleID int64 `json:"locale_id"`
Outdated bool `json:"outdated,omitempty"`
Active bool `json:"active,omitempty"`
Default bool `json:"default,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
// GetDynamicContentItems fetches dynamic content item list
// https://developer.zendesk.com/rest_api/docs/support/dynamic_content#list-items
func (z *Client) GetDynamicContentItems() ([]DynamicContentItem, Page, error) {
var data struct {
Items []DynamicContentItem `json:"items"`
Page
}
body, err := z.Get("/dynamic_content/items.json")
if err != nil {
return []DynamicContentItem{}, Page{}, err
}
err = json.Unmarshal(body, &data)
if err != nil {
return []DynamicContentItem{}, Page{}, err
}
return data.Items, data.Page, nil
}
// CreateDynamicContentItem creates new dynamic content item
// https://developer.zendesk.com/rest_api/docs/support/dynamic_content#create-item
func (z *Client) CreateDynamicContentItem(item DynamicContentItem) (DynamicContentItem, error) {
var data, result struct {
Item DynamicContentItem `json:"item"`
}
data.Item = item
body, err := z.Post("/groups.json", data)
if err != nil {
return DynamicContentItem{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return DynamicContentItem{}, err
}
return result.Item, nil
}