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 ContactApi |
25
|
|
|
* @internal |
26
|
|
|
* @package Freshdesk |
27
|
|
|
*/ |
28
|
|
|
class Contact extends AbstractResource |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* The resource endpoint |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $endpoint = '/contacts'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
* Create a contact |
40
|
|
|
* |
41
|
|
|
* @param array|null $data |
42
|
|
|
* @return mixed|null |
43
|
|
|
* @throws ApiException |
44
|
|
|
* @throws ConflictingStateException |
45
|
|
|
* @throws RateLimitExceededException |
46
|
|
|
* @throws UnsupportedContentTypeException |
47
|
|
|
*/ |
48
|
|
|
public function create(array $data) |
49
|
|
|
{ |
50
|
|
|
$this->api->request('POST', $this->endpoint(), $data); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
* Get a list of contacts |
56
|
|
|
* |
57
|
|
|
* @param array|null $query |
58
|
|
|
* @return mixed|null |
59
|
|
|
* @throws ApiException |
60
|
|
|
* @throws ConflictingStateException |
61
|
|
|
* @throws RateLimitExceededException |
62
|
|
|
* @throws UnsupportedContentTypeException |
63
|
|
|
*/ |
64
|
|
|
public function all(array $query = null) |
65
|
|
|
{ |
66
|
|
|
$this->api->request('GET', $this->endpoint(), null, $query); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* |
71
|
|
|
* Get a contact by id |
72
|
|
|
* |
73
|
|
|
* @param int $id |
74
|
|
|
* @param array|null $query |
75
|
|
|
* @return array|null |
76
|
|
|
* @throws AccessDeniedException |
77
|
|
|
* @throws ApiException |
78
|
|
|
* @throws ConflictingStateException |
79
|
|
|
* @throws MethodNotAllowedException |
80
|
|
|
* @throws NotFoundException |
81
|
|
|
* @throws RateLimitExceededException |
82
|
|
|
* @throws UnsupportedAcceptHeaderException |
83
|
|
|
* @throws UnsupportedContentTypeException |
84
|
|
|
* @throws ValidationException |
85
|
|
|
*/ |
86
|
|
|
public function view($id, array $query = null) |
87
|
|
|
{ |
88
|
|
|
$this->api->request('GET', $this->endpoint($id), null, $query); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Update a contact |
93
|
|
|
* |
94
|
|
|
* @param $id |
95
|
|
|
* @param array|null $data |
96
|
|
|
* @return mixed|null |
97
|
|
|
* @throws ApiException |
98
|
|
|
* @throws ConflictingStateException |
99
|
|
|
* @throws RateLimitExceededException |
100
|
|
|
* @throws UnsupportedContentTypeException |
101
|
|
|
*/ |
102
|
|
|
public function update($id, array $data = null) |
103
|
|
|
{ |
104
|
|
|
$this->api->request('PUT', $this->endpoint($id), $data); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Delete a contact |
109
|
|
|
* |
110
|
|
|
* @param $id |
111
|
|
|
* @return mixed|null |
112
|
|
|
* @throws ApiException |
113
|
|
|
* @throws ConflictingStateException |
114
|
|
|
* @throws RateLimitExceededException |
115
|
|
|
* @throws UnsupportedContentTypeException |
116
|
|
|
*/ |
117
|
|
|
public function delete($id) |
118
|
|
|
{ |
119
|
|
|
$this->api->request('DELETE', $this->endpoint($id)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* List contact fields |
124
|
|
|
* |
125
|
|
|
* @param array|null $query |
126
|
|
|
* @return mixed|null |
127
|
|
|
* @throws AccessDeniedException |
128
|
|
|
* @throws ApiException |
129
|
|
|
* @throws ConflictingStateException |
130
|
|
|
* @throws AuthenticationException |
131
|
|
|
* @throws NotFoundException |
132
|
|
|
*/ |
133
|
|
|
public function fields(array $query = null) |
134
|
|
|
{ |
135
|
|
|
$this->api->request('GET', 'contact_fields', null, $query); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Convert a contact into an agent |
140
|
|
|
* |
141
|
|
|
* @param array|null $query |
142
|
|
|
* @return mixed|null |
143
|
|
|
* @throws AccessDeniedException |
144
|
|
|
* @throws ApiException |
145
|
|
|
* @throws ConflictingStateException |
146
|
|
|
* @throws AuthenticationException |
147
|
|
|
* @throws NotFoundException |
148
|
|
|
*/ |
149
|
|
|
public function makeAgent($id, array $query = null) |
150
|
|
|
{ |
151
|
|
|
$end = $id . '/make_agent'; |
152
|
|
|
|
153
|
|
|
$this->api->request('GET', $this->endpoint($end), null, $query); |
154
|
|
|
} |
155
|
|
|
} |