1 | <?php |
||
5 | class Client |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var string |
||
10 | */ |
||
11 | private $teamName; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $username; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $passwordOrApiToken; |
||
22 | |||
23 | /** |
||
24 | * @var \GuzzleHttp\Client |
||
25 | */ |
||
26 | private $guzzleClient; |
||
27 | |||
28 | /** |
||
29 | * @param string $teamName |
||
30 | * @param string $username |
||
31 | * @param string $passwordOrApiToken |
||
32 | */ |
||
33 | 108 | public function __construct($teamName, $username, $passwordOrApiToken) |
|
34 | { |
||
35 | 108 | $this->teamName = $teamName; |
|
36 | 108 | $this->username = $username; |
|
37 | 108 | $this->passwordOrApiToken = $passwordOrApiToken; |
|
38 | |||
39 | 108 | $this->setClient(new \GuzzleHttp\Client([ |
|
40 | 'defaults' => [ |
||
41 | 108 | 'auth' => [$username, $passwordOrApiToken] |
|
42 | 108 | ] |
|
43 | 108 | ])); |
|
44 | 108 | } |
|
45 | |||
46 | /** |
||
47 | * Get a list of all priority levels |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | 3 | public function priorityLevels() |
|
55 | |||
56 | /** |
||
57 | * Get a list of all projects |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | 3 | public function projects() |
|
65 | |||
66 | /** |
||
67 | * Get a list of all companies |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 3 | public function companies() |
|
75 | |||
76 | /** |
||
77 | * Get all the issues |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | 3 | public function issues() |
|
85 | |||
86 | /** |
||
87 | * Get all the active issues |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 3 | public function activeIssues() |
|
95 | |||
96 | /** |
||
97 | * Get all the closed and fixed issues |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 3 | public function closedAndFixedIssues() |
|
105 | |||
106 | /** |
||
107 | * Get all the issues by a filter |
||
108 | * |
||
109 | * @param int $filter |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 3 | public function issuesByFilter($filter) |
|
117 | |||
118 | /** |
||
119 | * Get all the issues which are waiting on you |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | 3 | public function issuesWaitingOnYou() |
|
127 | |||
128 | /** |
||
129 | * Get all the issues which are waiting on them |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 3 | public function issuesWaitingOnThem() |
|
137 | |||
138 | /** |
||
139 | * Get a list of all global filters |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | 3 | public function globalFilters() |
|
147 | |||
148 | /** |
||
149 | * Get a list of all issue creation types |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | 3 | public function issueCreationTypes() |
|
157 | |||
158 | /** |
||
159 | * Get a list of all issue sort types |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | 3 | public function issueSortTypes() |
|
167 | |||
168 | /** |
||
169 | * @param int $id |
||
170 | * |
||
171 | * @return Project |
||
172 | */ |
||
173 | 60 | public function project($id) |
|
177 | |||
178 | /** |
||
179 | * @param int $id |
||
180 | * |
||
181 | * @return Company |
||
182 | */ |
||
183 | 6 | public function company($id) |
|
187 | |||
188 | /** |
||
189 | * Create a new company |
||
190 | * |
||
191 | * @param Company $company |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | 3 | public function createCompany($company) |
|
199 | |||
200 | /** |
||
201 | * Override the default Guzzle client |
||
202 | * |
||
203 | * @param \GuzzleHttp\Client $client |
||
204 | */ |
||
205 | 108 | public function setClient($client) |
|
209 | |||
210 | /** |
||
211 | * Generate the full URL from the specified endpoint |
||
212 | * |
||
213 | * @param string $endpoint |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | 99 | private function getUrl($endpoint) |
|
225 | |||
226 | /** |
||
227 | * @param string $endpoint |
||
228 | * @param array $data |
||
229 | * |
||
230 | * @return array |
||
231 | */ |
||
232 | 69 | public function get($endpoint, $data = []) |
|
242 | |||
243 | /** |
||
244 | * @param string $endpoint |
||
245 | * @param array $data |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | 12 | public function post($endpoint, $data = []) |
|
259 | |||
260 | /** |
||
261 | * @param string $endpoint |
||
262 | * @param array $data |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | 18 | public function put($endpoint, $data = []) |
|
276 | |||
277 | } |
||
278 |