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\ChannelsLeavePayload; |
15
|
|
|
use CL\Slack\Payload\ChannelsLeavePayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ChannelsLeaveCommand extends AbstractApiCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
1 |
|
protected function configure() |
27
|
|
|
{ |
28
|
1 |
|
parent::configure(); |
29
|
|
|
|
30
|
1 |
|
$this->setName('channels:leave'); |
31
|
1 |
|
$this->setDescription('Leave a channel (as the user of the token).'); |
32
|
1 |
|
$this->addArgument('channel-id', InputArgument::REQUIRED, 'The ID of the channel to leav'); |
33
|
1 |
|
$this->setHelp(<<<EOT |
34
|
|
|
The <info>channels:leave</info> command leaves a channel as the user of the token. |
35
|
|
|
|
36
|
|
|
For more information about the related API method, check out the official documentation: |
37
|
|
|
<comment>https://api.slack.com/methods/channels.leave</comment> |
38
|
|
|
EOT |
39
|
1 |
|
); |
40
|
1 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return ChannelsLeavePayload |
44
|
|
|
*/ |
45
|
1 |
|
protected function createPayload() |
46
|
|
|
{ |
47
|
1 |
|
$payload = new ChannelsLeavePayload(); |
48
|
1 |
|
$payload->setChannelId($this->input->getArgument('channel-id')); |
49
|
|
|
|
50
|
1 |
|
return $payload; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
* |
56
|
|
|
* @param ChannelsLeavePayloadResponse $payloadResponse |
57
|
|
|
*/ |
58
|
1 |
|
protected function handleResponse($payloadResponse) |
59
|
|
|
{ |
60
|
1 |
|
if ($payloadResponse->isOk()) { |
61
|
1 |
|
if ($payloadResponse->isNotInChannel()) { |
62
|
1 |
|
$this->writeError('Could not leave channel; not in channel'); |
63
|
1 |
|
} else { |
64
|
|
|
$this->writeOk('Successfully left channel!'); |
65
|
|
|
} |
66
|
1 |
|
} else { |
67
|
1 |
|
$this->writeError(sprintf('Failed to leave channel: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
68
|
|
|
} |
69
|
1 |
|
} |
70
|
|
|
} |
71
|
|
|
|