1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Polidog\Esa; |
4
|
|
|
|
5
|
|
|
use Polidog\Esa\Client\Client; |
6
|
|
|
use Polidog\Esa\Client\ClientInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ApiMethods. |
10
|
|
|
*/ |
11
|
|
|
class Api |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ClientInterface |
15
|
|
|
*/ |
16
|
|
|
private $client; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $currentTeam; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param ClientInterface $client |
25
|
|
|
* @param string $currentTeam |
26
|
|
|
*/ |
27
|
|
|
public function __construct(ClientInterface $client, $currentTeam) |
28
|
|
|
{ |
29
|
|
|
$this->client = $client; |
30
|
|
|
$this->currentTeam = $currentTeam; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param array $params |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function user(array $params = []) |
39
|
|
|
{ |
40
|
|
|
return $this->client->request('GET', 'user', [ |
41
|
|
|
'query' => $params, |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function teams() |
49
|
|
|
{ |
50
|
|
|
return $this->client->request('GET', 'teams'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string|null $name |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function team($name = null) |
59
|
|
|
{ |
60
|
|
|
return $this->client->request('GET', "teams/{$name}"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function stats() |
67
|
|
|
{ |
68
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('stats')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function members() |
75
|
|
|
{ |
76
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('members')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array $params |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function posts(array $params = []) |
85
|
|
|
{ |
86
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('posts'), [ |
87
|
|
|
'query' => $params, |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param int $number |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function post($number) |
97
|
|
|
{ |
98
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("posts/{$number}")); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param array $data |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
public function createPost($data) |
107
|
|
|
{ |
108
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl('posts'), [ |
109
|
|
|
'json' => [ |
110
|
|
|
'post' => $data, |
111
|
|
|
], |
112
|
|
|
]); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param int $number |
117
|
|
|
* @param array $data |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public function updatePost($number, array $data) |
122
|
|
|
{ |
123
|
|
|
return $this->client->request('PATCH', $this->getCurrentTeamUrl("posts/{$number}"), [ |
124
|
|
|
'json' => [ |
125
|
|
|
'post' => $data, |
126
|
|
|
], |
127
|
|
|
]); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param int $number |
132
|
|
|
* |
133
|
|
|
* @return array |
134
|
|
|
*/ |
135
|
|
|
public function deletePost($number) |
136
|
|
|
{ |
137
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("posts/{$number}")); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param int $number |
142
|
|
|
* @param array $params |
143
|
|
|
* |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function comments($number = null, array $params = []) |
147
|
|
|
{ |
148
|
|
|
if (empty($number)) { |
149
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('comments'), [ |
150
|
|
|
'query' => $params, |
151
|
|
|
]); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("posts/{$number}/comments"), [ |
155
|
|
|
'query' => $params, |
156
|
|
|
]); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param int $commentId |
161
|
|
|
* @param array $params |
162
|
|
|
* |
163
|
|
|
* @return array |
164
|
|
|
*/ |
165
|
|
|
public function comment($commentId, array $params = []) |
166
|
|
|
{ |
167
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("comments/{$commentId}"), [ |
168
|
|
|
'query' => $params, |
169
|
|
|
]); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param int $postNumber |
174
|
|
|
* @param array $data |
175
|
|
|
* |
176
|
|
|
* @return array |
177
|
|
|
*/ |
178
|
|
|
public function createComment($postNumber, array $data) |
179
|
|
|
{ |
180
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl("posts/{$postNumber}/comments"), [ |
181
|
|
|
'json' => [ |
182
|
|
|
'comment' => $data, |
183
|
|
|
], |
184
|
|
|
]); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param int $commentId |
189
|
|
|
* @param array $data |
190
|
|
|
* |
191
|
|
|
* @return array |
192
|
|
|
*/ |
193
|
|
|
public function updateComment($commentId, array $data) |
194
|
|
|
{ |
195
|
|
|
return $this->client->request('PATCH', $this->getCurrentTeamUrl("comments/{$commentId}"), [ |
196
|
|
|
'json' => [ |
197
|
|
|
'comment' => $data, |
198
|
|
|
], |
199
|
|
|
]); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param int $commentId |
204
|
|
|
* |
205
|
|
|
* @return array |
206
|
|
|
*/ |
207
|
|
|
public function deleteComment($commentId) |
208
|
|
|
{ |
209
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("comments/{$commentId}")); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param int $postNumber |
214
|
|
|
* |
215
|
|
|
* @return array |
216
|
|
|
*/ |
217
|
|
|
public function createSharing($postNumber) |
218
|
|
|
{ |
219
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl("posts/{$postNumber}/sharing")); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param int $postNumber |
224
|
|
|
* |
225
|
|
|
* @return array |
226
|
|
|
*/ |
227
|
|
|
public function deleteSharing($postNumber) |
228
|
|
|
{ |
229
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("posts/{$postNumber}/sharing")); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param int $postNumber |
234
|
|
|
* @param array $params |
235
|
|
|
* |
236
|
|
|
* @return array |
237
|
|
|
*/ |
238
|
|
|
public function postStargazers($postNumber, array $params = []) |
239
|
|
|
{ |
240
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("posts/{$postNumber}/stargazers"), [ |
241
|
|
|
'query' => $params, |
242
|
|
|
]); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param int $postNumber |
247
|
|
|
* @param array $params |
248
|
|
|
* |
249
|
|
|
* @return array |
250
|
|
|
*/ |
251
|
|
|
public function addPostStar($postNumber, array $params = []) |
252
|
|
|
{ |
253
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl("posts/{$postNumber}/star"), [ |
254
|
|
|
'json' => $params, |
255
|
|
|
]); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param int $postNumber |
260
|
|
|
* |
261
|
|
|
* @return array |
262
|
|
|
*/ |
263
|
|
|
public function deletePostStar($postNumber) |
264
|
|
|
{ |
265
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("posts/{$postNumber}/star")); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @param int $commentId |
270
|
|
|
* @param array $params |
271
|
|
|
* |
272
|
|
|
* @return array |
273
|
|
|
*/ |
274
|
|
|
public function commentStargazers($commentId, array $params = []) |
275
|
|
|
{ |
276
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("comments/{$commentId}/stargazers"), [ |
277
|
|
|
'query' => $params, |
278
|
|
|
]); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @param $commentId |
283
|
|
|
* @param array $params |
284
|
|
|
* |
285
|
|
|
* @return array |
286
|
|
|
*/ |
287
|
|
|
public function addCommentStar($commentId, array $params = []) |
288
|
|
|
{ |
289
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl("comments/{$commentId}/star"), [ |
290
|
|
|
'json' => $params, |
291
|
|
|
]); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param $commentId |
296
|
|
|
* |
297
|
|
|
* @return array |
298
|
|
|
*/ |
299
|
|
|
public function deleteCommentStar($commentId) |
300
|
|
|
{ |
301
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("comments/{$commentId}/star")); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @param integer$postNumber |
306
|
|
|
* @param array $params |
307
|
|
|
* |
308
|
|
|
* @return array |
309
|
|
|
*/ |
310
|
|
|
public function watchers($postNumber, array $params = []) |
311
|
|
|
{ |
312
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl("posts/{$postNumber}/watchers"), [ |
313
|
|
|
'query' => $params, |
314
|
|
|
]); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param $postNumber |
319
|
|
|
* |
320
|
|
|
* @return array |
321
|
|
|
*/ |
322
|
|
|
public function addWatch($postNumber) |
323
|
|
|
{ |
324
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl("posts/{$postNumber}/watch")); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @param $postNumber |
329
|
|
|
* |
330
|
|
|
* @return array |
331
|
|
|
*/ |
332
|
|
|
public function deleteWatch($postNumber) |
333
|
|
|
{ |
334
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("posts/{$postNumber}/watch")); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @return array |
339
|
|
|
*/ |
340
|
|
|
public function categories() |
341
|
|
|
{ |
342
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('categories')); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param array $params |
347
|
|
|
* |
348
|
|
|
* @return array |
349
|
|
|
*/ |
350
|
|
|
public function batchMoveCategory(array $params = []) |
351
|
|
|
{ |
352
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl('categories/batch_move'), [ |
353
|
|
|
'json' => $params, |
354
|
|
|
]); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @return array |
359
|
|
|
*/ |
360
|
|
|
public function tags() |
361
|
|
|
{ |
362
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('tags')); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* @return array |
367
|
|
|
*/ |
368
|
|
|
public function invitation() |
369
|
|
|
{ |
370
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('invitation')); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @return array |
375
|
|
|
*/ |
376
|
|
|
public function regenerateInvitation() |
377
|
|
|
{ |
378
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl('invitation_regenerator')); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @param $params |
383
|
|
|
* |
384
|
|
|
* @return array |
385
|
|
|
*/ |
386
|
|
|
public function pendingInvitations(array $params = []) |
387
|
|
|
{ |
388
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('invitations'), [ |
389
|
|
|
'query' => $params, |
390
|
|
|
]); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @param array $emails |
395
|
|
|
* |
396
|
|
|
* @return array |
397
|
|
|
*/ |
398
|
|
|
public function sendInvitation(array $emails) |
399
|
|
|
{ |
400
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl('invitations'), [ |
401
|
|
|
'json' => [ |
402
|
|
|
'members' => ['emails' => $emails], |
403
|
|
|
], |
404
|
|
|
]); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* @param string $code |
409
|
|
|
* |
410
|
|
|
* @return array |
411
|
|
|
*/ |
412
|
|
|
public function cancelInvitation($code) |
413
|
|
|
{ |
414
|
|
|
return $this->client->request('DELETE', $this->getCurrentTeamUrl("invitations/{$code}")); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @param array $params |
419
|
|
|
* |
420
|
|
|
* @return array |
421
|
|
|
*/ |
422
|
|
|
public function emojis(array $params = []) |
423
|
|
|
{ |
424
|
|
|
return $this->client->request('GET', $this->getCurrentTeamUrl('emojis'), [ |
425
|
|
|
'query' => $params, |
426
|
|
|
]); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param $data |
431
|
|
|
* |
432
|
|
|
* @return array |
433
|
|
|
*/ |
434
|
|
|
public function createEmoji(array $data) |
435
|
|
|
{ |
436
|
|
|
return $this->client->request('POST', $this->getCurrentTeamUrl('emojis'), [ |
437
|
|
|
'json' => [ |
438
|
|
|
'emoji' => $data, |
439
|
|
|
], |
440
|
|
|
]); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @param $code |
445
|
|
|
* |
446
|
|
|
* @return array |
447
|
|
|
*/ |
448
|
|
|
public function deleteEmoji($code) |
449
|
|
|
{ |
450
|
|
|
return $this->client->request('DELETE', "teams/{$this->currentTeam}/emojis/{$code}"); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* @param $accessToken |
455
|
|
|
* @param $currentTeam |
456
|
|
|
* |
457
|
|
|
* @return Api |
458
|
|
|
*/ |
459
|
|
|
public static function factory($accessToken, $currentTeam) |
460
|
|
|
{ |
461
|
|
|
$client = Client::factory($accessToken); |
462
|
|
|
|
463
|
|
|
return new self($client, $currentTeam); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
private function getCurrentTeamUrl($path = '') |
467
|
|
|
{ |
468
|
|
|
return "teams/{$this->currentTeam}/$path"; |
469
|
|
|
} |
470
|
|
|
} |
471
|
|
|
|