|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the slack-cli package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
|
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 CL\SlackCli\Command; |
|
13
|
|
|
|
|
14
|
|
|
use CL\Slack\Payload\StarsListPayload; |
|
15
|
|
|
use CL\Slack\Payload\StarsListPayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class StarsListCommand extends AbstractApiCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
|
|
$this->setName('stars:list'); |
|
31
|
|
|
$this->setDescription('Returns a list of all the items starred by a user'); |
|
32
|
|
|
$this->addOption('user-id', null, InputOption::VALUE_REQUIRED, 'Show stars by this user. Defaults to the token\'s user.'); |
|
33
|
|
|
$this->setHelp(<<<EOT |
|
34
|
|
|
The <info>stars:list</info> returns a list of all the items starred by a user. |
|
35
|
|
|
|
|
36
|
|
|
For more information about the related API method, check out the official documentation: |
|
37
|
|
|
<comment>https://api.slack.com/methods/stars.list</comment> |
|
38
|
|
|
EOT |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return StarsListPayload |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function createPayload() |
|
46
|
|
|
{ |
|
47
|
|
|
$payload = new StarsListPayload(); |
|
48
|
|
|
$payload->setUserId($this->input->getOption('user-id')); |
|
49
|
|
|
|
|
50
|
|
|
return $payload; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
* |
|
56
|
|
|
* @param StarsListPayloadResponse $payloadResponse |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function handleResponse($payloadResponse) |
|
59
|
|
|
{ |
|
60
|
|
|
if ($payloadResponse->isOk()) { |
|
61
|
|
|
$stars = $payloadResponse->getItems(); |
|
62
|
|
|
$this->output->writeln(sprintf('Received <comment>%d</comment> starred items...', count($stars))); |
|
63
|
|
|
if (!empty($stars)) { |
|
64
|
|
|
$this->renderTable($stars, null); |
|
65
|
|
|
$this->writeOk('Finished listing starred items'); |
|
66
|
|
|
} else { |
|
67
|
|
|
$this->writeComment('No starred items to list'); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
$this->writeError(sprintf( |
|
71
|
|
|
'Failed to list starred items: %s', |
|
72
|
|
|
lcfirst($payloadResponse->getErrorExplanation()) |
|
73
|
|
|
)); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|