diff --git a/README.md b/README.md
index 816ee2d..1184d6f 100644
--- a/README.md
+++ b/README.md
@@ -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] [--]
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
diff --git a/app/config/routing.yml b/app/config/routing.yml
index c7a2d5b..285e296 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -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}
diff --git a/src/Gist/Api/Client.php b/src/Gist/Api/Client.php
index d09bdb3..844fd24 100644
--- a/src/Gist/Api/Client.php
+++ b/src/Gist/Api/Client.php
@@ -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(
diff --git a/src/Gist/Command/UpdateCommand.php b/src/Gist/Command/UpdateCommand.php
index 2e4f666..a1e3dd5 100644
--- a/src/Gist/Command/UpdateCommand.php
+++ b/src/Gist/Command/UpdateCommand.php
@@ -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(<<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
@@ -49,7 +49,7 @@ EOF
//$output->writeln(sprintf('%s 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('You can not create an empty gist.', $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']);
diff --git a/src/Gist/Controller/ApiController.php b/src/Gist/Controller/ApiController.php
index 6d64039..03a5221 100644
--- a/src/Gist/Controller/ApiController.php
+++ b/src/Gist/Controller/ApiController.php
@@ -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) {