resq/catalyst/api-bundle/Command/TestCommand.php

67 lines
2.2 KiB
PHP

<?php
namespace Catalyst\APIBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Catalyst\APIBundle\Connector\Client as APIClient;
class TestCommand extends Command
{
protected function configure()
{
$this->setName('api:test-connector')
->setDescription('Test API connector.')
->setHelp('Test API Connector.')
->addArgument('protocol', InputArgument::REQUIRED, 'protocol')
->addArgument('server', InputArgument::REQUIRED, 'server')
->addArgument('api_key', InputArgument::REQUIRED, 'api_key')
->addArgument('secret_key', InputArgument::REQUIRED, 'secret_key');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$protocol = $input->getArgument('protocol');
$server = $input->getArgument('server');
$api_key = $input->getArgument('api_key');
$secret_key = $input->getArgument('secret_key');
// api client
$api = new APIClient($server, $api_key, $secret_key);
$api->setProtocol($protocol);
// test
$api->get('/capi/test');
// TODO: shift this out of the bundle, since it's project specific
// warranty register
$params = [
'serial' => 'LJ34LJADR12SDLKJL',
'plate_number' => 'XEN918',
'warranty_class' => 'private',
'date_purchase' => '20181001',
'date_expire' => '20191001',
];
$api->post('/capi/warranty', $params);
// warranty find
$api->get('/capi/warranty/LJ34LJADR12SDLKJL');
// warranty claim
$api->post('/capi/warranty/LJ34LJADR12SDLKJL/claim');
// battery
// $api->get('/capi/battery_models');
// $api->get('/capi/battery_sizes');
// vehicle
// $api->get('/capi/vehicle_manufacturers');
// $api->get('/capi/vehicles');
}
}