1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00
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
Display only the url of the gist
$ ./app/console --help create
Usage:
$ ./app/console --help update
Usage:
update [options] [--] <input>
Arguments:
input Input
Options:
--id=ID Gist Id
--gist=GIST Id or File of the gist
-u, --show-url Display only the gist url
-i, --show-id Display only the gist Id
-h, --help Display this help message
@ -234,8 +234,8 @@ Help:
Default value: text
Options:
--id
Defines the Gist to update by using its ID
--gist
Defines the Gist to update by using its Id or its File
--show-id, -i
Display only the Id of the gist

View File

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

View File

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

View File

@ -17,7 +17,7 @@ class UpdateCommand extends Command
->setName('update')
->setDescription('Update a gist using the API')
->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-id', 'i', InputOption::VALUE_NONE, 'Display only the gist Id')
->setHelp(<<<EOF
@ -32,8 +32,8 @@ Arguments:
Default value: <comment>text</comment>
Options:
<info>--id</info>
Defines the Gist to update by using its ID
<info>--gist</info>
Defines the Gist to update by using its Id or its File
<info>--show-id</info>, <info>-i</info>
Display only the Id of the gist
@ -49,7 +49,7 @@ EOF
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
$file = $input->getArgument('input');
$id = $input->getOption('id');
$gist = $input->getOption('gist');
if ($file === '-') {
$content = file_get_contents('php://stdin');
@ -73,7 +73,7 @@ EOF
$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')) {
$output->writeln($gist['url']);

View File

@ -54,19 +54,17 @@ class ApiController extends Controller
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')) {
return $this->invalidMethodResponse('POST method is required.');
}
if (!ctype_digit($id)) {
return $this->invalidRequestResponse('Invalid Gist');
}
$gist = GistQuery::create()
->filterByCipher(false)
->filterById((int) $id)
->filterById((int) $gist)
->_or()
->filterByFile($gist)
->findOne();
if (!$gist) {