thecatontheflat /
atlassian-connect-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace AtlassianConnectBundle\Command; |
||
| 6 | |||
| 7 | use AtlassianConnectBundle\Repository\TenantRepositoryInterface; |
||
| 8 | use AtlassianConnectBundle\Service\AtlassianRestClientInterface; |
||
| 9 | use Symfony\Component\Console\Command\Command; |
||
| 10 | use Symfony\Component\Console\Input\InputArgument; |
||
| 11 | use Symfony\Component\Console\Input\InputInterface; |
||
| 12 | use Symfony\Component\Console\Input\InputOption; |
||
| 13 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 14 | |||
| 15 | class RequestAPICommand extends Command |
||
| 16 | { |
||
| 17 | private TenantRepositoryInterface $repository; |
||
| 18 | private AtlassianRestClientInterface $restClient; |
||
| 19 | |||
| 20 | public function __construct(TenantRepositoryInterface $repository, AtlassianRestClientInterface $restClient) |
||
| 21 | { |
||
| 22 | parent::__construct(); |
||
| 23 | $this->repository = $repository; |
||
| 24 | $this->restClient = $restClient; |
||
| 25 | } |
||
| 26 | |||
| 27 | protected function configure(): void |
||
| 28 | { |
||
| 29 | $this |
||
| 30 | ->setName('ac:request-api') |
||
| 31 | ->addArgument('rest-url', InputArgument::REQUIRED, 'REST api endpoint, like /rest/api/2/issue/{issueIdOrKey}') |
||
| 32 | ->addOption('client-key', 'c', InputOption::VALUE_REQUIRED, 'Client-key from tenant') |
||
| 33 | ->addOption('tenant-id', 't', InputOption::VALUE_REQUIRED, 'Tenant-id') |
||
| 34 | ->setDescription('Request REST end-points. Documentation available on https://docs.atlassian.com/jira/REST/cloud/'); |
||
| 35 | } |
||
| 36 | |||
| 37 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 38 | { |
||
| 39 | $restUrl = $input->getArgument('rest-url'); |
||
| 40 | |||
| 41 | if ($input->getOption('tenant-id')) { |
||
| 42 | $tenant = $this->repository->findById($input->getOption('tenant-id')); |
||
| 43 | } elseif ($input->getOption('client-key')) { |
||
| 44 | $tenant = $this->repository->findByClientKey($input->getOption('client-key')); |
||
| 45 | } else { |
||
| 46 | throw new \RuntimeException('Please provide client-key or tenant-id'); |
||
| 47 | } |
||
| 48 | |||
| 49 | $this->restClient->setTenant($tenant); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 50 | |||
| 51 | $json = $this->restClient->get($restUrl); |
||
| 52 | |||
| 53 | $output->writeln(''); |
||
| 54 | $output->writeln($json); |
||
| 55 | $output->writeln(''); |
||
| 56 | |||
| 57 | return 0; |
||
| 58 | } |
||
| 59 | } |
||
| 60 |