This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathticket.go
100 lines (72 loc) · 1.77 KB
/
ticket.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
package zendesk
import (
"fmt"
"gopkg.in/resty.v0"
)
type TicketApiHandler struct {
client Client
}
type SingleTicket struct {
Response Ticket `json:"ticket"`
}
type MultipleTicket struct {
Response []Ticket `json:"tickets"`
}
func (t TicketApiHandler) GetById(id int) (Ticket, error) {
response, err := t.client.get(
fmt.Sprintf("/tickets/%d.json", id),
nil,
)
if err != nil {
}
return t.parseSingleObject(response), err
}
func (t TicketApiHandler) GetAll() ([]Ticket, error) {
response, err := t.client.get(
"/tickets.json",
nil,
)
if err != nil {
}
return t.parseMultiObjects(response), err
}
func (t TicketApiHandler) Create(v Ticket) (Ticket, error) {
var object SingleTicket
_, err := t.client.post(
"/tickets.json",
map[string]Ticket{"ticket": v},
&object,
)
return object.Response, err
}
func (t TicketApiHandler) CreateOrUpdate(v Ticket) (Ticket, error) {
return v, nil
}
func (t TicketApiHandler) CreateOrUpdateMany(v []Ticket) (Ticket, error) {
return Ticket{}, nil
}
func (t TicketApiHandler) Update(v Ticket) (Ticket, error) {
var object SingleTicket
_, err := t.client.put(
fmt.Sprintf("/tickets/%d.json", v.Id),
map[string]Ticket{"ticket": v},
&object,
)
return object.Response, err
}
func (t TicketApiHandler) Delete(id int) (int, error) {
response, err := t.client.delete(
fmt.Sprintf("/tickets/%d.json", id),
)
return response.StatusCode(), err
}
func (t TicketApiHandler) parseMultiObjects(response *resty.Response) []Ticket {
var object MultipleTicket
t.client.parseResponseToInterface(response, &object)
return object.Response
}
func (t TicketApiHandler) parseSingleObject(response *resty.Response) Ticket {
var object SingleTicket
t.client.parseResponseToInterface(response, &object)
return object.Response
}