also looking at this
Exceptions
#27
5 files
+168
-14
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | namespace Meema\MeemaApi\Models; |
| 4 | 4 | |
| 5 | 5 | use Meema\MeemaApi\Client; |
| 6 | use Meema\MeemaApi\Exceptions\InvalidFormatException; | |
| 6 | 7 | use Meema\MeemaApi\Response\Response; |
| 7 | 8 | |
| 8 | 9 | class Favorite |
| @@ -50,6 +51,10 @@ class Favorite | ||
| 50 | 51 | return $this->all(); |
| 51 | 52 | } |
| 52 | 53 | |
| 54 | if (! is_int($id)) { | |
| 55 | throw new InvalidFormatException(); | |
| 56 | } | |
| 57 | ||
| 53 | 58 | $ids = is_array($id) ? $id : func_get_args(); |
| 54 | 59 | |
| 55 | 60 | return $this->client->request('GET', 'favorites', ['favorite_ids' => $ids]); |
| @@ -64,6 +69,10 @@ class Favorite | ||
| 64 | 69 | */ |
| 65 | 70 | public function find($id) |
| 66 | 71 | { |
| 72 | if (! is_int($id)) { | |
| 73 | throw new InvalidFormatException(); | |
| 74 | } | |
| 75 | ||
| 67 | 76 | $response = $this->client->request('GET', "favorites/${id}"); |
| 68 | 77 | |
| 69 | 78 | return new Response($this, $response); |
| @@ -91,6 +100,10 @@ class Favorite | ||
| 91 | 100 | */ |
| 92 | 101 | public function update($id, $data): array |
| 93 | 102 | { |
| 103 | if (! is_int($id)) { | |
| 104 | throw new InvalidFormatException(); | |
| 105 | } | |
| 106 | ||
| 94 | 107 | return $this->client->request('PATCH', "favorites/{$id}", $data); |
| 95 | 108 | } |
| 96 | 109 | |
| @@ -103,6 +116,10 @@ class Favorite | ||
| 103 | 116 | */ |
| 104 | 117 | public function delete($id) |
| 105 | 118 | { |
| 119 | if (! is_int($id)) { | |
| 120 | throw new InvalidFormatException(); | |
| 121 | } | |
| 122 | ||
| 106 | 123 | return $this->client->request('DELETE', "favorites/{$id}"); |
| 107 | 124 | } |
| 108 | 125 | } |
| @@ -58,16 +58,12 @@ class Folder | ||
| 58 | 58 | return $this->all(); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | try { | |
| 62 | if (! is_int($id)) { | |
| 63 | throw new InvalidFormatException(); | |
| 64 | } | |
| 65 | ||
| 66 | $ids = is_array($id) ? $id : func_get_args(); | |
| 67 | } catch (InvalidFormatException $e) { | |
| 68 | return $e->getMessage(); | |
| 61 | if (! is_int($id)) { | |
| 62 | throw new InvalidFormatException(); | |
| 69 | 63 | } |
| 70 | 64 | |
| 65 | $ids = is_array($id) ? $id : func_get_args(); | |
| 66 | ||
| 71 | 67 | return $this->client->request('GET', 'folders', ['folder_ids' => $ids]); |
| 72 | 68 | } |
| 73 | 69 | |
| @@ -82,16 +78,12 @@ class Folder | ||
| 82 | 78 | */ |
| 83 | 79 | public function find($id) |
| 84 | 80 | { |
| 85 | try { | |
| 86 | if (! is_int($id)) { | |
| 87 | throw new InvalidFormatException(); | |
| 88 | } | |
| 89 | ||
| 90 | $response = $this->client->request('GET', "folders/${id}"); | |
| 91 | } catch (InvalidFormatException $e) { | |
| 92 | return $e->getMessage(); | |
| 81 | if (! is_int($id)) { | |
| 82 | throw new InvalidFormatException(); | |
| 93 | 83 | } |
| 94 | 84 | |
| 85 | $response = $this->client->request('GET', "folders/${id}"); | |
| 86 | ||
| 95 | 87 | return new Response($this, $response); |
| 96 | 88 | } |
| 97 | 89 | |
| @@ -124,17 +116,13 @@ class Folder | ||
| 124 | 116 | * @return array |
| 125 | 117 | */ |
| 126 | 118 | public function update($id, $name): array |
| 127 | { | |
| 128 | try { | |
| 129 | if (! is_int($id)) { | |
| 130 | throw new InvalidFormatException(); | |
| 131 | } | |
| 132 | ||
| 133 | $name = is_array($name) ? $name : compact('name'); | |
| 134 | } catch (InvalidFormatException $e) { | |
| 135 | return $e->getMessage(); | |
| 119 | { | |
| 120 | if (! is_int($id)) { | |
| 121 | throw new InvalidFormatException(); | |
| 136 | 122 | } |
| 137 | 123 | |
| 124 | $name = is_array($name) ? $name : compact('name'); | |
| 125 | ||
| 138 | 126 | return $this->client->request('PATCH', "folders/{$id}", $name); |
| 139 | 127 | } |
| 140 | 128 | |
| @@ -149,16 +137,12 @@ class Folder | ||
| 149 | 137 | */ |
| 150 | 138 | public function delete($id) |
| 151 | 139 | { |
| 152 | try { | |
| 153 | if (! is_int($id)) { | |
| 154 | throw new InvalidFormatException(); | |
| 155 | } | |
| 156 | ||
| 157 | if ($this->model) { | |
| 158 | return $this->deleteFolderFromMedia($this->model->getId(), $id); | |
| 159 | } | |
| 160 | } catch (InvalidFormatException $e) { | |
| 161 | return $e->getMessage(); | |
| 140 | if (! is_int($id)) { | |
| 141 | throw new InvalidFormatException(); | |
| 142 | } | |
| 143 | ||
| 144 | if ($this->model) { | |
| 145 | return $this->deleteFolderFromMedia($this->model->getId(), $id); | |
| 162 | 146 | } |
| 163 | 147 | |
| 164 | 148 | return $this->client->request('DELETE', "folders/{$id}"); |
| @@ -186,16 +170,12 @@ class Folder | ||
| 186 | 170 | * @throws InvalidFormatException |
| 187 | 171 | */ |
| 188 | 172 | public function archive($id) |
| 189 | { | |
| 190 | try { | |
| 191 | if (! is_int($id)) { | |
| 192 | throw new InvalidFormatException(); | |
| 193 | } | |
| 194 | ||
| 195 | return $this->client->request('POST', "folders/{$id}/archive"); | |
| 196 | } catch (InvalidFormatException $e) { | |
| 197 | return $e->getMessage(); | |
| 173 | { | |
| 174 | if (! is_int($id)) { | |
| 175 | throw new InvalidFormatException(); | |
| 198 | 176 | } |
| 177 | ||
| 178 | return $this->client->request('POST', "folders/{$id}/archive"); | |
| 199 | 179 | } |
| 200 | 180 | |
| 201 | 181 | /** |
| @@ -209,15 +189,11 @@ class Folder | ||
| 209 | 189 | */ |
| 210 | 190 | public function unarchive($id) |
| 211 | 191 | { |
| 212 | try { | |
| 213 | if (! is_int($id)) { | |
| 214 | throw new InvalidFormatException(); | |
| 215 | } | |
| 216 | ||
| 217 | return $this->client->request('POST', "folders/{$id}/unarchive"); | |
| 218 | } catch (InvalidFormatException $e) { | |
| 219 | return $e->getMessage(); | |
| 192 | if (! is_int($id)) { | |
| 193 | throw new InvalidFormatException(); | |
| 220 | 194 | } |
| 195 | ||
| 196 | return $this->client->request('POST', "folders/{$id}/unarchive"); | |
| 221 | 197 | } |
| 222 | 198 | |
| 223 | 199 | /** |
| @@ -231,15 +207,11 @@ class Folder | ||
| 231 | 207 | */ |
| 232 | 208 | public function duplicate($id): array |
| 233 | 209 | { |
| 234 | try { | |
| 235 | if (! is_int($id)) { | |
| 236 | throw new InvalidFormatException(); | |
| 237 | } | |
| 238 | ||
| 239 | return $this->client->request('POST', "folders/{$id}/duplicate"); | |
| 240 | } catch (InvalidFormatException $e) { | |
| 241 | return $e->getMessage(); | |
| 210 | if (! is_int($id)) { | |
| 211 | throw new InvalidFormatException(); | |
| 242 | 212 | } |
| 213 | ||
| 214 | return $this->client->request('POST', "folders/{$id}/duplicate"); | |
| 243 | 215 | } |
| 244 | 216 | |
| 245 | 217 | /** |
| @@ -253,15 +225,11 @@ class Folder | ||
| 253 | 225 | */ |
| 254 | 226 | public function addFolderToMedia($id, $name): array |
| 255 | 227 | { |
| 256 | try { | |
| 257 | if (! is_int($id)) { | |
| 258 | throw new InvalidFormatException(); | |
| 259 | } | |
| 260 | ||
| 261 | return $this->client->request('POST', "media/{$id}/folders", $name); | |
| 262 | } catch (InvalidFormatException $e) { | |
| 263 | return $e->getMessage(); | |
| 228 | if (! is_int($id)) { | |
| 229 | throw new InvalidFormatException(); | |
| 264 | 230 | } |
| 231 | ||
| 232 | return $this->client->request('POST', "media/{$id}/folders", $name); | |
| 265 | 233 | } |
| 266 | 234 | |
| 267 | 235 | /** |
| @@ -276,15 +244,11 @@ class Folder | ||
| 276 | 244 | */ |
| 277 | 245 | public function deleteFolderFromMedia($id, $folderId) |
| 278 | 246 | { |
| 279 | try { | |
| 280 | if (! is_int($id) || ! is_int($folderId)) { | |
| 281 | throw new InvalidFormatException(); | |
| 282 | } | |
| 283 | ||
| 284 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); | |
| 285 | } catch (InvalidFormatException $e) { | |
| 286 | return $e->getMessage(); | |
| 247 | if (! is_int($id) || ! is_int($folderId)) { | |
| 248 | throw new InvalidFormatException(); | |
| 287 | 249 | } |
| 250 | ||
| 251 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); | |
| 288 | 252 | } |
| 289 | 253 | |
| 290 | 254 | /** |
| @@ -60,16 +60,12 @@ class Media | ||
| 60 | 60 | return $this->all(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | try { | |
| 64 | if (! is_int($id)) { | |
| 65 | throw new InvalidFormatException(); | |
| 66 | } | |
| 67 | ||
| 68 | $ids = is_array($id) ? $id : func_get_args(); | |
| 69 | } catch (InvalidFormatException $e) { | |
| 70 | return $e->getMessage(); | |
| 63 | if (! is_int($id)) { | |
| 64 | throw new InvalidFormatException(); | |
| 71 | 65 | } |
| 72 | 66 | |
| 67 | $ids = is_array($id) ? $id : func_get_args(); | |
| 68 | ||
| 73 | 69 | return $this->client->request('GET', 'media', ['media_ids' => $ids]); |
| 74 | 70 | } |
| 75 | 71 | |
| @@ -84,16 +80,12 @@ class Media | ||
| 84 | 80 | */ |
| 85 | 81 | public function find($id) |
| 86 | 82 | { |
| 87 | try { | |
| 88 | if (! is_int($id)) { | |
| 89 | throw new InvalidFormatException(); | |
| 90 | } | |
| 91 | ||
| 92 | $response = $this->client->request('GET', "media/${id}"); | |
| 93 | } catch (InvalidFormatException $e) { | |
| 94 | return $e->getMessage(); | |
| 83 | if (! is_int($id)) { | |
| 84 | throw new InvalidFormatException(); | |
| 95 | 85 | } |
| 96 | 86 | |
| 87 | $response = $this->client->request('GET', "media/${id}"); | |
| 88 | ||
| 97 | 89 | return new Response($this, $response); |
| 98 | 90 | } |
| 99 | 91 | |
| @@ -123,17 +115,13 @@ class Media | ||
| 123 | 115 | */ |
| 124 | 116 | public function update($id, $name) |
| 125 | 117 | { |
| 126 | try { | |
| 127 | if (! is_int($id)) { | |
| 128 | throw new InvalidFormatException(); | |
| 129 | } | |
| 118 | if (! is_int($id)) { | |
| 119 | throw new InvalidFormatException(); | |
| 120 | } | |
| 130 | 121 | |
| 131 | $name = is_array($name) ? $name : compact('name'); | |
| 122 | $name = is_array($name) ? $name : compact('name'); | |
| 132 | 123 | |
| 133 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); | |
| 134 | } catch (InvalidFormatException $e) { | |
| 135 | return $e->getMessage(); | |
| 136 | } | |
| 124 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); | |
| 137 | 125 | } |
| 138 | 126 | |
| 139 | 127 | /** |
| @@ -147,15 +135,11 @@ class Media | ||
| 147 | 135 | */ |
| 148 | 136 | public function delete($id) |
| 149 | 137 | { |
| 150 | try { | |
| 151 | if (! is_int($id)) { | |
| 152 | throw new InvalidFormatException(); | |
| 153 | } | |
| 154 | ||
| 155 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); | |
| 156 | } catch (InvalidFormatException $e) { | |
| 157 | return $e->getMessage(); | |
| 138 | if (! is_int($id)) { | |
| 139 | throw new InvalidFormatException(); | |
| 158 | 140 | } |
| 141 | ||
| 142 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); | |
| 159 | 143 | } |
| 160 | 144 | |
| 161 | 145 | /** |
| @@ -181,15 +165,11 @@ class Media | ||
| 181 | 165 | */ |
| 182 | 166 | public function archive($id) |
| 183 | 167 | { |
| 184 | try { | |
| 185 | if (! is_int($id)) { | |
| 186 | throw new InvalidFormatException(); | |
| 187 | } | |
| 188 | ||
| 189 | return $this->client->request('POST', "media/{$id}/archive"); | |
| 190 | } catch (InvalidFormatException $e) { | |
| 191 | return $e->getMessage(); | |
| 168 | if (! is_int($id)) { | |
| 169 | throw new InvalidFormatException(); | |
| 192 | 170 | } |
| 171 | ||
| 172 | return $this->client->request('POST', "media/{$id}/archive"); | |
| 193 | 173 | } |
| 194 | 174 | |
| 195 | 175 | /** |
| @@ -203,15 +183,11 @@ class Media | ||
| 203 | 183 | */ |
| 204 | 184 | public function unarchive($id) |
| 205 | 185 | { |
| 206 | try { | |
| 207 | if (! is_int($id)) { | |
| 208 | throw new InvalidFormatException(); | |
| 209 | } | |
| 210 | ||
| 211 | return $this->client->request('POST', "media/{$id}/unarchive"); | |
| 212 | } catch (InvalidFormatException $e) { | |
| 213 | return $e->getMessage(); | |
| 186 | if (! is_int($id)) { | |
| 187 | throw new InvalidFormatException(); | |
| 214 | 188 | } |
| 189 | ||
| 190 | return $this->client->request('POST', "media/{$id}/unarchive"); | |
| 215 | 191 | } |
| 216 | 192 | |
| 217 | 193 | /** |
| @@ -225,15 +201,11 @@ class Media | ||
| 225 | 201 | */ |
| 226 | 202 | public function makePrivate($id) |
| 227 | 203 | { |
| 228 | try { | |
| 229 | if (! is_int($id)) { | |
| 230 | throw new InvalidFormatException(); | |
| 231 | } | |
| 232 | ||
| 233 | return $this->client->request('PATCH', "media/{$id}/make-private"); | |
| 234 | } catch (InvalidFormatException $e) { | |
| 235 | return $e->getMessage(); | |
| 204 | if (! is_int($id)) { | |
| 205 | throw new InvalidFormatException(); | |
| 236 | 206 | } |
| 207 | ||
| 208 | return $this->client->request('PATCH', "media/{$id}/make-private"); | |
| 237 | 209 | } |
| 238 | 210 | |
| 239 | 211 | /** |
| @@ -247,15 +219,11 @@ class Media | ||
| 247 | 219 | */ |
| 248 | 220 | public function makePublic($id) |
| 249 | 221 | { |
| 250 | try { | |
| 251 | if (! is_int($id)) { | |
| 252 | throw new InvalidFormatException(); | |
| 253 | } | |
| 254 | ||
| 255 | return $this->client->request('PATCH', "media/{$id}/make-public"); | |
| 256 | } catch (InvalidFormatException $e) { | |
| 257 | return $e->getMessage(); | |
| 222 | if (! is_int($id)) { | |
| 223 | throw new InvalidFormatException(); | |
| 258 | 224 | } |
| 225 | ||
| 226 | return $this->client->request('PATCH', "media/{$id}/make-public"); | |
| 259 | 227 | } |
| 260 | 228 | |
| 261 | 229 | /** |
| @@ -269,15 +237,11 @@ class Media | ||
| 269 | 237 | */ |
| 270 | 238 | public function duplicate($id) |
| 271 | 239 | { |
| 272 | try { | |
| 273 | if (! is_int($id)) { | |
| 274 | throw new InvalidFormatException(); | |
| 275 | } | |
| 276 | ||
| 277 | return $this->client->request('POST', "media/{$id}/duplicate"); | |
| 278 | } catch (InvalidFormatException $e) { | |
| 279 | return $e->getMessage(); | |
| 240 | if (! is_int($id)) { | |
| 241 | throw new InvalidFormatException(); | |
| 280 | 242 | } |
| 243 | ||
| 244 | return $this->client->request('POST', "media/{$id}/duplicate"); | |
| 281 | 245 | } |
| 282 | 246 | |
| 283 | 247 | /** |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | namespace Meema\MeemaApi\Models; |
| 4 | 4 | |
| 5 | 5 | use Meema\MeemaApi\Client; |
| 6 | use Meema\MeemaApi\Exceptions\InvalidFormatException; | |
| 6 | 7 | use Meema\MeemaApi\Response\Response; |
| 7 | 8 | |
| 8 | 9 | class Tag |
| @@ -59,6 +60,10 @@ class Tag | ||
| 59 | 60 | return $this->all(); |
| 60 | 61 | } |
| 61 | 62 | |
| 63 | if (! is_int($id)) { | |
| 64 | throw new InvalidFormatException(); | |
| 65 | } | |
| 66 | ||
| 62 | 67 | $ids = is_array($id) ? $id : func_get_args(); |
| 63 | 68 | |
| 64 | 69 | return $this->client->request('GET', 'tags', ['tag_ids' => $ids]); |
| @@ -73,6 +78,10 @@ class Tag | ||
| 73 | 78 | */ |
| 74 | 79 | public function find($id): Response |
| 75 | 80 | { |
| 81 | if (! is_int($id)) { | |
| 82 | throw new InvalidFormatException(); | |
| 83 | } | |
| 84 | ||
| 76 | 85 | $response = $this->client->request('GET', "tags/${id}"); |
| 77 | 86 | |
| 78 | 87 | return new Response($this, $response); |
| @@ -102,6 +111,10 @@ class Tag | ||
| 102 | 111 | */ |
| 103 | 112 | public function update($id, $data): array |
| 104 | 113 | { |
| 114 | if (! is_int($id)) { | |
| 115 | throw new InvalidFormatException(); | |
| 116 | } | |
| 117 | ||
| 105 | 118 | return $this->client->request('PATCH', 'tags/color', $data); |
| 106 | 119 | } |
| 107 | 120 | |
| @@ -114,6 +127,10 @@ class Tag | ||
| 114 | 127 | */ |
| 115 | 128 | public function delete($id) |
| 116 | 129 | { |
| 130 | if (! is_int($id)) { | |
| 131 | throw new InvalidFormatException(); | |
| 132 | } | |
| 133 | ||
| 117 | 134 | return $this->client->request('DELETE', "tags/{$id}"); |
| 118 | 135 | } |
| 119 | 136 | |