Completed
Push — master ( 7f6918...fb7822 )
by Matthew
02:21
created

Ticket::endpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 * Date: 20/04/2016
6
 * Time: 2:32 PM
7
 */
8
9
namespace Freshdesk\Resources;
10
11
use Freshdesk\Api;
12
use Freshdesk\Exceptions\AccessDeniedException;
13
use Freshdesk\Exceptions\ApiException;
14
use Freshdesk\Exceptions\AuthenticationException;
15
use Freshdesk\Exceptions\ConflictingStateException;
16
use Freshdesk\Exceptions\MethodNotAllowedException;
17
use Freshdesk\Exceptions\NotFoundException;
18
use Freshdesk\Exceptions\RateLimitExceededException;
19
use Freshdesk\Exceptions\UnsupportedAcceptHeaderException;
20
use Freshdesk\Exceptions\UnsupportedContentTypeException;
21
use Freshdesk\Exceptions\ValidationException;
22
23
/**
24
 * Class TicketApi
25
 * @internal
26
 * @package Freshdesk
27
 */
28
class Ticket extends AbstractResource
29
{
30
31
    /**
32
     * The resource endpoint
33
     *
34
     * @var string
35
     */
36
    protected $endpoint = '/tickets';
37
    
38
    /**
39
     *
40
     * Create a ticket
41
     *
42
     * @param array|null $data
43
     * @return mixed|null
44
     * @throws ApiException
45
     * @throws ConflictingStateException
46
     * @throws RateLimitExceededException
47
     * @throws UnsupportedContentTypeException
48
     */
49
    public function create(array $data)
50
    {
51
        $this->api->request('POST', $this->endpoint(), $data);
52
    }
53
54
    /**
55
     *
56
     * Get a list of tickets
57
     *
58
     * @param array|null $query
59
     * @return mixed|null
60
     * @throws ApiException
61
     * @throws ConflictingStateException
62
     * @throws RateLimitExceededException
63
     * @throws UnsupportedContentTypeException
64
     */
65
    public function all(array $query = null)
66
    {
67
        $this->api->request('GET', $this->endpoint(), null, $query);
68
    }
69
70
    /**
71
     *
72
     * Get a ticket by id
73
     *
74
     * @param int $id
75
     * @param array|null $query
76
     * @return array|null
77
     * @throws AccessDeniedException
78
     * @throws ApiException
79
     * @throws ConflictingStateException
80
     * @throws MethodNotAllowedException
81
     * @throws NotFoundException
82
     * @throws RateLimitExceededException
83
     * @throws UnsupportedAcceptHeaderException
84
     * @throws UnsupportedContentTypeException
85
     * @throws ValidationException
86
     */
87
    public function view($id, array $query = null)
88
    {
89
        $this->api->request('GET', $this->endpoint($id), null, $query);
90
    }
91
92
    /**
93
     * Update a ticket
94
     *
95
     * @param $id
96
     * @param array|null $data
97
     * @return mixed|null
98
     * @throws ApiException
99
     * @throws ConflictingStateException
100
     * @throws RateLimitExceededException
101
     * @throws UnsupportedContentTypeException
102
     */
103
    public function update($id, array $data = null)
104
    {
105
        $this->api->request('PUT', $this->endpoint($id), $data);
106
    }
107
108
    /**
109
     * Delete a ticket
110
     *
111
     * @param $id
112
     * @return mixed|null
113
     * @throws ApiException
114
     * @throws ConflictingStateException
115
     * @throws RateLimitExceededException
116
     * @throws UnsupportedContentTypeException
117
     */
118
    public function delete($id)
119
    {
120
        $this->api->request('DELETE', $this->endpoint($id));
121
    }
122
123
    /**
124
     * Restore a ticket
125
     *
126
     * @param $id
127
     * @return mixed|null
128
     * @throws ApiException
129
     * @throws ConflictingStateException
130
     * @throws RateLimitExceededException
131
     * @throws UnsupportedContentTypeException
132
     */
133
    public function restore($id)
134
    {
135
        $end = $id . '/restore';
136
137
        $this->api->request('PUT', $this->endpoint($end));
138
    }
139
140
    /**
141
     * List ticket fields
142
     *
143
     * @param array|null $query
144
     * @return mixed|null
145
     * @throws AccessDeniedException
146
     * @throws ApiException
147
     * @throws ConflictingStateException
148
     * @throws Exceptions\AuthenticationException
149
     * @throws NotFoundException
150
     */
151
    public function fields(array $query = null)
152
    {
153
        $this->api->request('GET', 'ticket_fields', null, $query);
154
    }
155
156
    /**
157
     * List conversations associated with a ticket
158
     *
159
     * @param array|null $query
160
     * @return mixed|null
161
     * @throws AccessDeniedException
162
     * @throws ApiException
163
     * @throws ConflictingStateException
164
     * @throws AuthenticationException
165
     * @throws NotFoundException
166
     */
167
    public function conversations($id, array $query = null)
168
    {
169
        $end = $id . '/conversations';
170
171
        $this->api->request('GET', $this->endpoint($end), null, $query);
172
    }
173
174
    /**
175
     * List time entries associated with a ticket
176
     *
177
     * @param array|null $query
178
     * @return mixed|null
179
     * @throws AccessDeniedException
180
     * @throws ApiException
181
     * @throws ConflictingStateException
182
     * @throws AuthenticationException
183
     * @throws NotFoundException
184
     */
185
    public function timeEntries($id, array $query = null)
186
    {
187
        $end = $id . '/time_entries';
188
189
        $this->api->request('GET', $this->endpoint($end), null, $query);
190
    }
191
192
}