This commit is contained in:
Simon Vieille 2015-11-07 22:27:41 +01:00
parent e31baef7ca
commit 767e5abab4
5 changed files with 18 additions and 20 deletions

View file

@ -203,15 +203,15 @@ Help:
--show-url, -u --show-url, -u
Display only the url of the gist Display only the url of the gist
$ ./app/console --help create $ ./app/console --help update
Usage: Usage:
update [options] [--] <input> update [options] [--] <input>
Arguments: Arguments:
input Input input Input
Options: Options:
--id=ID Gist Id --gist=GIST Id or File of the gist
-u, --show-url Display only the gist url -u, --show-url Display only the gist url
-i, --show-id Display only the gist Id -i, --show-id Display only the gist Id
-h, --help Display this help message -h, --help Display this help message
@ -234,8 +234,8 @@ Help:
Default value: text Default value: text
Options: Options:
--id --gist
Defines the Gist to update by using its ID Defines the Gist to update by using its Id or its File
--show-id, -i --show-id, -i
Display only the Id of the gist Display only the Id of the gist

View file

@ -35,5 +35,5 @@ api_create:
defaults: {_controller: Gist\Controller\ApiController::createAction, _locale: en} defaults: {_controller: Gist\Controller\ApiController::createAction, _locale: en}
api_update: api_update:
path: /api/update/{id} path: /api/update/{gist}
defaults: {_controller: Gist\Controller\ApiController::updateAction, _locale: en} defaults: {_controller: Gist\Controller\ApiController::updateAction, _locale: en}

View file

@ -11,7 +11,7 @@ use GuzzleHttp\Client as BaseClient;
class Client extends BaseClient class Client extends BaseClient
{ {
const CREATE = '/en/api/create'; const CREATE = '/en/api/create';
const UPDATE = '/en/api/update/{id}'; const UPDATE = '/en/api/update/{gist}';
public function create($title, $type, $content) public function create($title, $type, $content)
{ {
@ -35,10 +35,10 @@ class Client extends BaseClient
return []; return [];
} }
public function update($id, $content) public function update($gist, $content)
{ {
$response = $this->post( $response = $this->post(
str_replace('{id}', $id, self::UPDATE), str_replace('{gist}', $gist, self::UPDATE),
array( array(
'form_params' => array( 'form_params' => array(
'form' => array( 'form' => array(

View file

@ -17,7 +17,7 @@ class UpdateCommand extends Command
->setName('update') ->setName('update')
->setDescription('Update a gist using the API') ->setDescription('Update a gist using the API')
->addArgument('input', InputArgument::REQUIRED, 'Input') ->addArgument('input', InputArgument::REQUIRED, 'Input')
->addOption('id', null, InputOption::VALUE_REQUIRED, 'Gist Id') ->addOption('gist', null, InputOption::VALUE_REQUIRED, 'Id or File of the gist')
->addOption('show-url', 'u', InputOption::VALUE_NONE, 'Display only the gist url') ->addOption('show-url', 'u', InputOption::VALUE_NONE, 'Display only the gist url')
->addOption('show-id', 'i', InputOption::VALUE_NONE, 'Display only the gist Id') ->addOption('show-id', 'i', InputOption::VALUE_NONE, 'Display only the gist Id')
->setHelp(<<<EOF ->setHelp(<<<EOF
@ -32,8 +32,8 @@ Arguments:
Default value: <comment>text</comment> Default value: <comment>text</comment>
Options: Options:
<info>--id</info> <info>--gist</info>
Defines the Gist to update by using its ID Defines the Gist to update by using its Id or its File
<info>--show-id</info>, <info>-i</info> <info>--show-id</info>, <info>-i</info>
Display only the Id of the gist Display only the Id of the gist
@ -49,7 +49,7 @@ EOF
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test')); //$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
$file = $input->getArgument('input'); $file = $input->getArgument('input');
$id = $input->getOption('id'); $gist = $input->getOption('gist');
if ($file === '-') { if ($file === '-') {
$content = file_get_contents('php://stdin'); $content = file_get_contents('php://stdin');
@ -73,7 +73,7 @@ EOF
$output->writeln(sprintf('<error>You can not create an empty gist.</error>', $type)); $output->writeln(sprintf('<error>You can not create an empty gist.</error>', $type));
} }
$gist = $this->getSilexApplication()['api_client']->update($id, $content); $gist = $this->getSilexApplication()['api_client']->update($gist, $content);
if ($input->getOption('show-url')) { if ($input->getOption('show-url')) {
$output->writeln($gist['url']); $output->writeln($gist['url']);

View file

@ -54,19 +54,17 @@ class ApiController extends Controller
return $this->invalidRequestResponse('Invalid field(s)'); return $this->invalidRequestResponse('Invalid field(s)');
} }
public function updateAction(Request $request, Application $app, $id) public function updateAction(Request $request, Application $app, $gist)
{ {
if (false === $request->isMethod('post')) { if (false === $request->isMethod('post')) {
return $this->invalidMethodResponse('POST method is required.'); return $this->invalidMethodResponse('POST method is required.');
} }
if (!ctype_digit($id)) {
return $this->invalidRequestResponse('Invalid Gist');
}
$gist = GistQuery::create() $gist = GistQuery::create()
->filterByCipher(false) ->filterByCipher(false)
->filterById((int) $id) ->filterById((int) $gist)
->_or()
->filterByFile($gist)
->findOne(); ->findOne();
if (!$gist) { if (!$gist) {