|
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\FilesListPayload; |
|
15
|
|
|
use CL\Slack\Payload\FilesListPayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class FilesListCommand extends AbstractApiCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
|
|
$this->setName('files:list'); |
|
31
|
|
|
$this->setDescription('Returns a list of all files in your Slack team'); |
|
32
|
|
|
$this->addOption('user-id', 'u', InputOption::VALUE_REQUIRED, 'Filter files created by a single user.'); |
|
33
|
|
|
$this->addOption('from', null, InputOption::VALUE_REQUIRED, 'Filter files created after this timestamp (inclusive).'); |
|
34
|
|
|
$this->addOption('to', null, InputOption::VALUE_REQUIRED, 'Filter files created before this timestamp (inclusive).'); |
|
35
|
|
|
$this->addOption('types', null, InputOption::VALUE_REQUIRED, 'Filter files by type. You can pass multiple values in the types argument, like types=posts,snippets. The default value is all, which does not filter the list.'); |
|
36
|
|
|
$this->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'Number of items to return per page.'); |
|
37
|
|
|
$this->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'Page number of results to return.'); |
|
38
|
|
|
$this->setHelp(<<<EOT |
|
39
|
|
|
The <info>files:list</info> command returns a list of files within the team. |
|
40
|
|
|
It can be filtered and sliced in various ways. |
|
41
|
|
|
|
|
42
|
|
|
The response contains a list of files, followed by some paging information. |
|
43
|
|
|
|
|
44
|
|
|
- Files are always returned with the most recent first. |
|
45
|
|
|
- Paging contains: |
|
46
|
|
|
- the count of files returned |
|
47
|
|
|
- the total number of files matching the filter(s) (if any were supplied) |
|
48
|
|
|
- the page of results returned in this response |
|
49
|
|
|
- the total number of pages available |
|
50
|
|
|
EOT |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return FilesListPayload |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function createPayload() |
|
58
|
|
|
{ |
|
59
|
|
|
$payload = new FilesListPayload(); |
|
60
|
|
|
$payload->setUserId($this->input->getOption('user-id')); |
|
61
|
|
|
$payload->setCount($this->input->getOption('count')); |
|
62
|
|
|
$payload->setPage($this->input->getOption('page')); |
|
63
|
|
|
$payload->setTimestampFrom($this->input->getOption('from')); |
|
64
|
|
|
$payload->setTimestampTo($this->input->getOption('to')); |
|
65
|
|
|
$payload->setTypes($this->input->getOption('types')); |
|
66
|
|
|
|
|
67
|
|
|
return $payload; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
* |
|
73
|
|
|
* @param FilesListPayloadResponse $payloadResponse |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function handleResponse($payloadResponse) |
|
76
|
|
|
{ |
|
77
|
|
|
if ($payloadResponse->isOk()) { |
|
78
|
|
|
$files = $payloadResponse->getFiles(); |
|
79
|
|
|
$this->writeOk(sprintf('Received <comment>%d</comment> files...', count($files))); |
|
80
|
|
|
if (!empty($files)) { |
|
81
|
|
|
$this->output->writeln('Listing files...'); |
|
82
|
|
|
$this->renderTable($files, null); |
|
83
|
|
|
} |
|
84
|
|
|
if ($payloadResponse->getPaging()) { |
|
85
|
|
|
$this->output->writeln('Paging...'); |
|
86
|
|
|
$this->renderKeyValueTable($payloadResponse->getPaging()); |
|
87
|
|
|
} |
|
88
|
|
|
} else { |
|
89
|
|
|
$this->writeError(sprintf('Failed to list files. %s', lcfirst($payloadResponse->getErrorExplanation()))); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getMethod() |
|
97
|
|
|
{ |
|
98
|
|
|
return 'files.list'; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|