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

91 lines
2.7 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
$serial = 'AJ34LJADR12134LKJL';
$plate_num = 'XEN918';
$params = [
'serial' => $serial,
'plate_number' => $plate_num,
'warranty_class' => 'private',
'battery_model_id' => 438,
'battery_size_id' => 1171,
'date_purchase' => '20181001',
'date_expire' => '20191001',
];
$api->post('/capi/warranties', $params);
*/
// get all warranties
$api->get('/capi/warranties');
/*
// warranty find
$api->get('/capi/warranties/' . $serial);
*/
// warranty claim
$id = 86811;
$serial = 'TEST001';
$params = [
'serial' => $serial,
];
$api->post('/capi/warranties/' . $id . '/claim', $params);
/*
// plate warranty
$api->get('/capi/plates/' . $plate_num . '/warranties');
*/
// battery
$api->get('/capi/battery_brands');
$api->get('/capi/battery_sizes');
$api->get('/capi/batteries');
// vehicle
// $api->get('/capi/vehicle_manufacturers');
// $api->get('/capi/vehicles');
}
}