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 2 months ago
parent
commit
31ffaced48
No known key found for this signature in database
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 View File

88
     public function update($gist, $content)
88
     public function update($gist, $content)
89
     {
89
     {
90
         $response = $this->post(
90
         $response = $this->post(
91
-            str_replace('{gist}', $gist, $this->mergeApiKey(self::LIST)),
91
+            str_replace('{gist}', $gist, $this->mergeApiKey(self::UPDATE)),
92
             array(
92
             array(
93
                 'form_params' => array(
93
                 'form_params' => array(
94
                     'form' => array(
94
                     'form' => array(

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

158
             return $this->invalidMethodResponse('POST method is required.');
158
             return $this->invalidMethodResponse('POST method is required.');
159
         }
159
         }
160
 
160
 
161
-        $gist = GistQuery::create()
162
-            ->filterByCipher(false)
163
-            ->filterById((int) $gist)
164
-            ->_or()
165
-            ->filterByFile($gist)
166
-            ->findOne();
161
+        $query = GistQuery::create()
162
+            ->filterByCipher(false);
163
+
164
+        if (ctype_digit($gist)) {
165
+            $query->filterById((int) $gist);
166
+        } else {
167
+            $query->filterByFile($gist);
168
+        }
169
+
170
+        $gist = $query->findOne();
167
 
171
 
168
         if (!$gist) {
172
         if (!$gist) {
169
             return $this->invalidRequestResponse('Invalid Gist');
173
             return $this->invalidRequestResponse('Invalid Gist');