|
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\ConflictingStateException; |
|
15
|
|
|
use Freshdesk\Exceptions\MethodNotAllowedException; |
|
16
|
|
|
use Freshdesk\Exceptions\NotFoundException; |
|
17
|
|
|
use Freshdesk\Exceptions\RateLimitExceededException; |
|
18
|
|
|
use Freshdesk\Exceptions\UnsupportedAcceptHeaderException; |
|
19
|
|
|
use Freshdesk\Exceptions\UnsupportedContentTypeException; |
|
20
|
|
|
use Freshdesk\Exceptions\ValidationException; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class CompanyApi |
|
24
|
|
|
* @internal |
|
25
|
|
|
* @package Freshdesk |
|
26
|
|
|
*/ |
|
27
|
|
|
class Company extends AbstractResource |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* The resource endpoint |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $endpoint = '/companies'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* |
|
38
|
|
|
* Create a company |
|
39
|
|
|
* |
|
40
|
|
|
* @param array|null $data |
|
41
|
|
|
* @return mixed|null |
|
42
|
|
|
* @throws ApiException |
|
43
|
|
|
* @throws ConflictingStateException |
|
44
|
|
|
* @throws RateLimitExceededException |
|
45
|
|
|
* @throws UnsupportedContentTypeException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function create(array $data) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->api->request('POST', $this->endpoint(), $data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* |
|
54
|
|
|
* Get a list of companies |
|
55
|
|
|
* |
|
56
|
|
|
* @param array|null $query |
|
57
|
|
|
* @return mixed|null |
|
58
|
|
|
* @throws ApiException |
|
59
|
|
|
* @throws ConflictingStateException |
|
60
|
|
|
* @throws RateLimitExceededException |
|
61
|
|
|
* @throws UnsupportedContentTypeException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function all(array $query = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->api->request('GET', $this->endpoint(), null, $query); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* |
|
70
|
|
|
* Get a company by id |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @param array|null $query |
|
74
|
|
|
* @return array|null |
|
75
|
|
|
* @throws AccessDeniedException |
|
76
|
|
|
* @throws ApiException |
|
77
|
|
|
* @throws ConflictingStateException |
|
78
|
|
|
* @throws MethodNotAllowedException |
|
79
|
|
|
* @throws NotFoundException |
|
80
|
|
|
* @throws RateLimitExceededException |
|
81
|
|
|
* @throws UnsupportedAcceptHeaderException |
|
82
|
|
|
* @throws UnsupportedContentTypeException |
|
83
|
|
|
* @throws ValidationException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function view($id, array $query = null) |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->api->request('GET', $this->endpoint($id), null, $query); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Update a company |
|
92
|
|
|
* |
|
93
|
|
|
* @param $id |
|
94
|
|
|
* @param array|null $data |
|
95
|
|
|
* @return mixed|null |
|
96
|
|
|
* @throws ApiException |
|
97
|
|
|
* @throws ConflictingStateException |
|
98
|
|
|
* @throws RateLimitExceededException |
|
99
|
|
|
* @throws UnsupportedContentTypeException |
|
100
|
|
|
*/ |
|
101
|
|
|
public function update($id, array $data = null) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->api->request('PUT', $this->endpoint($id), $data); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Delete a company |
|
108
|
|
|
* |
|
109
|
|
|
* @param $id |
|
110
|
|
|
* @return mixed|null |
|
111
|
|
|
* @throws ApiException |
|
112
|
|
|
* @throws ConflictingStateException |
|
113
|
|
|
* @throws RateLimitExceededException |
|
114
|
|
|
* @throws UnsupportedContentTypeException |
|
115
|
|
|
*/ |
|
116
|
|
|
public function delete($id) |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->api->request('DELETE', $this->endpoint($id)); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* List company fields |
|
123
|
|
|
* |
|
124
|
|
|
* @param array|null $query |
|
125
|
|
|
* @return mixed|null |
|
126
|
|
|
* @throws AccessDeniedException |
|
127
|
|
|
* @throws ApiException |
|
128
|
|
|
* @throws ConflictingStateException |
|
129
|
|
|
* @throws NotFoundException |
|
130
|
|
|
* @throws \Freshdesk\Exceptions\AuthenticationException |
|
131
|
|
|
*/ |
|
132
|
|
|
public function fields(array $query = null) |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->api->request('GET', '/company_fields', null, $query); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |