1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the zibios/wrike-php-library package. |
5
|
|
|
* |
6
|
|
|
* (c) Zbigniew Ślązak |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zibios\WrikePhpLibrary; |
13
|
|
|
|
14
|
|
|
use Zibios\WrikePhpLibrary\Client\ClientInterface; |
15
|
|
|
use Zibios\WrikePhpLibrary\Resource\AccountResource; |
16
|
|
|
use Zibios\WrikePhpLibrary\Resource\AttachmentResource; |
17
|
|
|
use Zibios\WrikePhpLibrary\Resource\ColorResource; |
18
|
|
|
use Zibios\WrikePhpLibrary\Resource\CommentResource; |
19
|
|
|
use Zibios\WrikePhpLibrary\Resource\ContactResource; |
20
|
|
|
use Zibios\WrikePhpLibrary\Resource\CustomFieldResource; |
21
|
|
|
use Zibios\WrikePhpLibrary\Resource\DependencyResource; |
22
|
|
|
use Zibios\WrikePhpLibrary\Resource\FolderResource; |
23
|
|
|
use Zibios\WrikePhpLibrary\Resource\GroupResource; |
24
|
|
|
use Zibios\WrikePhpLibrary\Resource\IdResource; |
25
|
|
|
use Zibios\WrikePhpLibrary\Resource\InvitationResource; |
26
|
|
|
use Zibios\WrikePhpLibrary\Resource\TaskResource; |
27
|
|
|
use Zibios\WrikePhpLibrary\Resource\TimelogResource; |
28
|
|
|
use Zibios\WrikePhpLibrary\Resource\UserResource; |
29
|
|
|
use Zibios\WrikePhpLibrary\Resource\VersionResource; |
30
|
|
|
use Zibios\WrikePhpLibrary\Resource\WorkflowResource; |
31
|
|
|
use Zibios\WrikePhpLibrary\Transformer\ResponseTransformerInterface; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* General Wrike Api. |
35
|
|
|
* |
36
|
|
|
* Entry point for all Wrike API operations. |
37
|
|
|
* |
38
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
39
|
|
|
* @SuppressWarnings(PHPMD.TooManyFields) |
40
|
|
|
*/ |
41
|
|
|
class Api implements ApiInterface |
42
|
|
|
{ |
43
|
|
|
const BASE_URI = 'https://www.wrike.com/api/v3/'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ClientInterface |
47
|
|
|
*/ |
48
|
|
|
protected $client; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var ResponseTransformerInterface |
52
|
|
|
*/ |
53
|
|
|
protected $responseTransformer; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var ContactResource |
57
|
|
|
*/ |
58
|
|
|
protected $contactResource; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var UserResource |
62
|
|
|
*/ |
63
|
|
|
protected $userResource; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var GroupResource |
67
|
|
|
*/ |
68
|
|
|
protected $groupResource; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var InvitationResource |
72
|
|
|
*/ |
73
|
|
|
protected $invitationResource; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var AccountResource |
77
|
|
|
*/ |
78
|
|
|
protected $accountResource; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var WorkflowResource |
82
|
|
|
*/ |
83
|
|
|
protected $workflowResource; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var CustomFieldResource |
87
|
|
|
*/ |
88
|
|
|
protected $customFieldResource; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var FolderResource |
92
|
|
|
*/ |
93
|
|
|
protected $folderResource; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var TaskResource |
97
|
|
|
*/ |
98
|
|
|
protected $taskResource; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var CommentResource |
102
|
|
|
*/ |
103
|
|
|
protected $commentResource; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var DependencyResource |
107
|
|
|
*/ |
108
|
|
|
protected $dependencyResource; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var TimelogResource |
112
|
|
|
*/ |
113
|
|
|
protected $timelogResource; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var AttachmentResource |
117
|
|
|
*/ |
118
|
|
|
protected $attachmentResource; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var VersionResource |
122
|
|
|
*/ |
123
|
|
|
protected $versionResource; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var IdResource |
127
|
|
|
*/ |
128
|
|
|
protected $idResource; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var ColorResource |
132
|
|
|
*/ |
133
|
|
|
protected $colorResource; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param ClientInterface $client |
137
|
|
|
* @param ResponseTransformerInterface $responseTransformer |
138
|
|
|
*/ |
139
|
171 |
|
public function __construct( |
140
|
|
|
ClientInterface $client, |
141
|
|
|
ResponseTransformerInterface $responseTransformer |
142
|
|
|
) { |
143
|
171 |
|
$this->client = $client; |
144
|
171 |
|
$this->responseTransformer = $responseTransformer; |
145
|
171 |
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
1 |
|
public function getBearerToken() |
151
|
|
|
{ |
152
|
1 |
|
return $this->client->getBearerToken(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param string $bearerToken |
157
|
|
|
* |
158
|
|
|
* @return $this |
159
|
|
|
*/ |
160
|
1 |
|
public function setBearerToken($bearerToken) |
161
|
|
|
{ |
162
|
1 |
|
$this->client->setBearerToken($bearerToken); |
163
|
|
|
|
164
|
1 |
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return ContactResource |
169
|
|
|
*/ |
170
|
11 |
|
public function getContactResource() |
171
|
|
|
{ |
172
|
11 |
|
if ($this->contactResource === null) { |
173
|
11 |
|
$this->contactResource = new ContactResource( |
174
|
11 |
|
$this->client, |
175
|
11 |
|
$this->responseTransformer |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
11 |
|
return $this->contactResource; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return UserResource |
184
|
|
|
*/ |
185
|
5 |
|
public function getUserResource() |
186
|
|
|
{ |
187
|
5 |
|
if ($this->userResource === null) { |
188
|
5 |
|
$this->userResource = new UserResource( |
189
|
5 |
|
$this->client, |
190
|
5 |
|
$this->responseTransformer |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
|
194
|
5 |
|
return $this->userResource; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return GroupResource |
199
|
|
|
*/ |
200
|
11 |
|
public function getGroupResource() |
201
|
|
|
{ |
202
|
11 |
|
if ($this->groupResource === null) { |
203
|
11 |
|
$this->groupResource = new GroupResource( |
204
|
11 |
|
$this->client, |
205
|
11 |
|
$this->responseTransformer |
206
|
|
|
); |
207
|
|
|
} |
208
|
|
|
|
209
|
11 |
|
return $this->groupResource; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return InvitationResource |
214
|
|
|
*/ |
215
|
9 |
|
public function getInvitationResource() |
216
|
|
|
{ |
217
|
9 |
|
if ($this->invitationResource === null) { |
218
|
9 |
|
$this->invitationResource = new InvitationResource( |
219
|
9 |
|
$this->client, |
220
|
9 |
|
$this->responseTransformer |
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
9 |
|
return $this->invitationResource; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return AccountResource |
229
|
|
|
*/ |
230
|
7 |
|
public function getAccountResource() |
231
|
|
|
{ |
232
|
7 |
|
if ($this->accountResource === null) { |
233
|
7 |
|
$this->accountResource = new AccountResource( |
234
|
7 |
|
$this->client, |
235
|
7 |
|
$this->responseTransformer |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
7 |
|
return $this->accountResource; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return WorkflowResource |
244
|
|
|
*/ |
245
|
7 |
|
public function getWorkflowResource() |
246
|
|
|
{ |
247
|
7 |
|
if ($this->workflowResource === null) { |
248
|
7 |
|
$this->workflowResource = new WorkflowResource( |
249
|
7 |
|
$this->client, |
250
|
7 |
|
$this->responseTransformer |
251
|
|
|
); |
252
|
|
|
} |
253
|
|
|
|
254
|
7 |
|
return $this->workflowResource; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return CustomFieldResource |
259
|
|
|
*/ |
260
|
13 |
|
public function getCustomFieldResource() |
261
|
|
|
{ |
262
|
13 |
|
if ($this->customFieldResource === null) { |
263
|
13 |
|
$this->customFieldResource = new CustomFieldResource( |
264
|
13 |
|
$this->client, |
265
|
13 |
|
$this->responseTransformer |
266
|
|
|
); |
267
|
|
|
} |
268
|
|
|
|
269
|
13 |
|
return $this->customFieldResource; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return FolderResource |
274
|
|
|
*/ |
275
|
19 |
|
public function getFolderResource() |
276
|
|
|
{ |
277
|
19 |
|
if ($this->folderResource === null) { |
278
|
19 |
|
$this->folderResource = new FolderResource( |
279
|
19 |
|
$this->client, |
280
|
19 |
|
$this->responseTransformer |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
|
284
|
19 |
|
return $this->folderResource; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return TaskResource |
289
|
|
|
*/ |
290
|
17 |
|
public function getTaskResource() |
291
|
|
|
{ |
292
|
17 |
|
if ($this->taskResource === null) { |
293
|
17 |
|
$this->taskResource = new TaskResource( |
294
|
17 |
|
$this->client, |
295
|
17 |
|
$this->responseTransformer |
296
|
|
|
); |
297
|
|
|
} |
298
|
|
|
|
299
|
17 |
|
return $this->taskResource; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return CommentResource |
304
|
|
|
*/ |
305
|
21 |
|
public function getCommentResource() |
306
|
|
|
{ |
307
|
21 |
|
if ($this->commentResource === null) { |
308
|
21 |
|
$this->commentResource = new CommentResource( |
309
|
21 |
|
$this->client, |
310
|
21 |
|
$this->responseTransformer |
311
|
|
|
); |
312
|
|
|
} |
313
|
|
|
|
314
|
21 |
|
return $this->commentResource; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @return DependencyResource |
319
|
|
|
*/ |
320
|
13 |
|
public function getDependencyResource() |
321
|
|
|
{ |
322
|
13 |
|
if ($this->dependencyResource === null) { |
323
|
13 |
|
$this->dependencyResource = new DependencyResource( |
324
|
13 |
|
$this->client, |
325
|
13 |
|
$this->responseTransformer |
326
|
|
|
); |
327
|
|
|
} |
328
|
|
|
|
329
|
13 |
|
return $this->dependencyResource; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @return TimelogResource |
334
|
|
|
*/ |
335
|
19 |
|
public function getTimelogResource() |
336
|
|
|
{ |
337
|
19 |
|
if ($this->timelogResource === null) { |
338
|
19 |
|
$this->timelogResource = new TimelogResource( |
339
|
19 |
|
$this->client, |
340
|
19 |
|
$this->responseTransformer |
341
|
|
|
); |
342
|
|
|
} |
343
|
|
|
|
344
|
19 |
|
return $this->timelogResource; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @return AttachmentResource |
349
|
|
|
*/ |
350
|
23 |
|
public function getAttachmentResource() |
351
|
|
|
{ |
352
|
23 |
|
if ($this->attachmentResource === null) { |
353
|
23 |
|
$this->attachmentResource = new AttachmentResource( |
354
|
23 |
|
$this->client, |
355
|
23 |
|
$this->responseTransformer |
356
|
|
|
); |
357
|
|
|
} |
358
|
|
|
|
359
|
23 |
|
return $this->attachmentResource; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @return VersionResource |
364
|
|
|
*/ |
365
|
3 |
|
public function getVersionResource() |
366
|
|
|
{ |
367
|
3 |
|
if ($this->versionResource === null) { |
368
|
3 |
|
$this->versionResource = new VersionResource( |
369
|
3 |
|
$this->client, |
370
|
3 |
|
$this->responseTransformer |
371
|
|
|
); |
372
|
|
|
} |
373
|
|
|
|
374
|
3 |
|
return $this->versionResource; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @return IdResource |
379
|
|
|
*/ |
380
|
3 |
|
public function getIdResource() |
381
|
|
|
{ |
382
|
3 |
|
if ($this->idResource === null) { |
383
|
3 |
|
$this->idResource = new IdResource( |
384
|
3 |
|
$this->client, |
385
|
3 |
|
$this->responseTransformer |
386
|
|
|
); |
387
|
|
|
} |
388
|
|
|
|
389
|
3 |
|
return $this->idResource; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @return ColorResource |
394
|
|
|
*/ |
395
|
3 |
|
public function getColorResource() |
396
|
|
|
{ |
397
|
3 |
|
if ($this->colorResource === null) { |
398
|
3 |
|
$this->colorResource = new ColorResource( |
399
|
3 |
|
$this->client, |
400
|
3 |
|
$this->responseTransformer |
401
|
|
|
); |
402
|
|
|
} |
403
|
|
|
|
404
|
3 |
|
return $this->colorResource; |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
|