Browse Source

Fix issue with API: the client requested 'list' instead of 'update' for updating gist and the update controller found bad gist

Simon Vieille 1 week ago
parent
commit
31ffaced48
2 changed files with 11 additions and 7 deletions
  1. 1 1
      src/Gist/Api/Client.php
  2. 10 6
      src/Gist/Controller/ApiController.php

+ 1 - 1
src/Gist/Api/Client.php

@@ -88,7 +88,7 @@ class Client extends BaseClient
     public function update($gist, $content)
     {
         $response = $this->post(
-            str_replace('{gist}', $gist, $this->mergeApiKey(self::LIST)),
+            str_replace('{gist}', $gist, $this->mergeApiKey(self::UPDATE)),
             array(
                 'form_params' => array(
                     'form' => array(

+ 10 - 6
src/Gist/Controller/ApiController.php

@@ -158,12 +158,16 @@ class ApiController extends Controller
             return $this->invalidMethodResponse('POST method is required.');
         }
 
-        $gist = GistQuery::create()
-            ->filterByCipher(false)
-            ->filterById((int) $gist)
-            ->_or()
-            ->filterByFile($gist)
-            ->findOne();
+        $query = GistQuery::create()
+            ->filterByCipher(false);
+
+        if (ctype_digit($gist)) {
+            $query->filterById((int) $gist);
+        } else {
+            $query->filterByFile($gist);
+        }
+
+        $gist = $query->findOne();
 
         if (!$gist) {
             return $this->invalidRequestResponse('Invalid Gist');