also looking at this
Exceptions
#27
5 files
+168
-14
| @@ -2,6 +2,18 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Meema\MeemaApi\Exceptions; |
| 4 | 4 | |
| 5 | class InvalidFormatException | |
| 5 | use Exception; | |
| 6 | ||
| 7 | class InvalidFormatException extends Exception | |
| 6 | 8 | { |
| 9 | /** | |
| 10 | * Construct exception. | |
| 11 | * | |
| 12 | * @param string $message | |
| 13 | */ | |
| 14 | public function __construct(string $message = null) | |
| 15 | { | |
| 16 | parent::__construct($message ?? 'Error on line '.$this->getLine().' in '.$this->getFile() | |
| 17 | .' ID is not a valid integer'); | |
| 18 | } | |
| 7 | 19 | } |
| @@ -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 | } |
| @@ -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 Folder |
| @@ -47,7 +48,9 @@ class Folder | ||
| 47 | 48 | * |
| 48 | 49 | * @param int $id |
| 49 | 50 | * |
| 50 | * @return array | |
| 51 | * @return mixed | |
| 52 | * | |
| 53 | * @throws InvalidFormatException | |
| 51 | 54 | */ |
| 52 | 55 | public function get($id = null) |
| 53 | 56 | { |
| @@ -55,6 +58,10 @@ class Folder | ||
| 55 | 58 | return $this->all(); |
| 56 | 59 | } |
| 57 | 60 | |
| 61 | if (! is_int($id)) { | |
| 62 | throw new InvalidFormatException(); | |
| 63 | } | |
| 64 | ||
| 58 | 65 | $ids = is_array($id) ? $id : func_get_args(); |
| 59 | 66 | |
| 60 | 67 | return $this->client->request('GET', 'folders', ['folder_ids' => $ids]); |
| @@ -66,9 +73,15 @@ class Folder | ||
| 66 | 73 | * @param int $id |
| 67 | 74 | * |
| 68 | 75 | * @return Response |
| 76 | * | |
| 77 | * @throws InvalidFormatException | |
| 69 | 78 | */ |
| 70 | public function find($id): Response | |
| 79 | public function find($id) | |
| 71 | 80 | { |
| 81 | if (! is_int($id)) { | |
| 82 | throw new InvalidFormatException(); | |
| 83 | } | |
| 84 | ||
| 72 | 85 | $response = $this->client->request('GET', "folders/${id}"); |
| 73 | 86 | |
| 74 | 87 | return new Response($this, $response); |
| @@ -97,13 +110,17 @@ class Folder | ||
| 97 | 110 | /** |
| 98 | 111 | * Update folder. |
| 99 | 112 | * |
| 100 | * @param string $name | |
| 101 | 113 | * @param int $id |
| 114 | * @param string $name | |
| 102 | 115 | * |
| 103 | 116 | * @return array |
| 104 | 117 | */ |
| 105 | 118 | public function update($id, $name): array |
| 106 | 119 | { |
| 120 | if (! is_int($id)) { | |
| 121 | throw new InvalidFormatException(); | |
| 122 | } | |
| 123 | ||
| 107 | 124 | $name = is_array($name) ? $name : compact('name'); |
| 108 | 125 | |
| 109 | 126 | return $this->client->request('PATCH', "folders/{$id}", $name); |
| @@ -115,9 +132,15 @@ class Folder | ||
| 115 | 132 | * @param int $id |
| 116 | 133 | * |
| 117 | 134 | * @return null |
| 135 | * | |
| 136 | * @throws InvalidFormatException | |
| 118 | 137 | */ |
| 119 | 138 | public function delete($id) |
| 120 | 139 | { |
| 140 | if (! is_int($id)) { | |
| 141 | throw new InvalidFormatException(); | |
| 142 | } | |
| 143 | ||
| 121 | 144 | if ($this->model) { |
| 122 | 145 | return $this->deleteFolderFromMedia($this->model->getId(), $id); |
| 123 | 146 | } |
| @@ -143,9 +166,15 @@ class Folder | ||
| 143 | 166 | * @param int $id |
| 144 | 167 | * |
| 145 | 168 | * @return array |
| 169 | * | |
| 170 | * @throws InvalidFormatException | |
| 146 | 171 | */ |
| 147 | public function archive($id): array | |
| 172 | public function archive($id) | |
| 148 | 173 | { |
| 174 | if (! is_int($id)) { | |
| 175 | throw new InvalidFormatException(); | |
| 176 | } | |
| 177 | ||
| 149 | 178 | return $this->client->request('POST', "folders/{$id}/archive"); |
| 150 | 179 | } |
| 151 | 180 | |
| @@ -155,9 +184,15 @@ class Folder | ||
| 155 | 184 | * @param int $id |
| 156 | 185 | * |
| 157 | 186 | * @return array |
| 187 | * | |
| 188 | * @throws InvalidFormatException | |
| 158 | 189 | */ |
| 159 | public function unarchive($id): array | |
| 190 | public function unarchive($id) | |
| 160 | 191 | { |
| 192 | if (! is_int($id)) { | |
| 193 | throw new InvalidFormatException(); | |
| 194 | } | |
| 195 | ||
| 161 | 196 | return $this->client->request('POST', "folders/{$id}/unarchive"); |
| 162 | 197 | } |
| 163 | 198 | |
| @@ -167,9 +202,15 @@ class Folder | ||
| 167 | 202 | * @param int $id |
| 168 | 203 | * |
| 169 | 204 | * @return array |
| 205 | * | |
| 206 | * @throws InvalidFormatException | |
| 170 | 207 | */ |
| 171 | 208 | public function duplicate($id): array |
| 172 | 209 | { |
| 210 | if (! is_int($id)) { | |
| 211 | throw new InvalidFormatException(); | |
| 212 | } | |
| 213 | ||
| 173 | 214 | return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 174 | 215 | } |
| 175 | 216 | |
| @@ -179,9 +220,15 @@ class Folder | ||
| 179 | 220 | * @param int $id |
| 180 | 221 | * |
| 181 | 222 | * @return array |
| 223 | * | |
| 224 | * @throws InvalidFormatException | |
| 182 | 225 | */ |
| 183 | 226 | public function addFolderToMedia($id, $name): array |
| 184 | 227 | { |
| 228 | if (! is_int($id)) { | |
| 229 | throw new InvalidFormatException(); | |
| 230 | } | |
| 231 | ||
| 185 | 232 | return $this->client->request('POST', "media/{$id}/folders", $name); |
| 186 | 233 | } |
| 187 | 234 | |
| @@ -192,9 +239,15 @@ class Folder | ||
| 192 | 239 | * @param int $folderId |
| 193 | 240 | * |
| 194 | 241 | * @return null |
| 242 | * | |
| 243 | * @throws InvalidFormatException | |
| 195 | 244 | */ |
| 196 | 245 | public function deleteFolderFromMedia($id, $folderId) |
| 197 | 246 | { |
| 247 | if (! is_int($id) || ! is_int($folderId)) { | |
| 248 | throw new InvalidFormatException(); | |
| 249 | } | |
| 250 | ||
| 198 | 251 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); |
| 199 | 252 | } |
| 200 | 253 | |
| @@ -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 Media |
| @@ -46,6 +47,8 @@ class Media | ||
| 46 | 47 | * Get specific media. |
| 47 | 48 | * |
| 48 | 49 | * @return array |
| 50 | * | |
| 51 | * @throws InvalidFormatException | |
| 49 | 52 | */ |
| 50 | 53 | public function get($id = null) |
| 51 | 54 | { |
| @@ -57,9 +60,13 @@ class Media | ||
| 57 | 60 | return $this->all(); |
| 58 | 61 | } |
| 59 | 62 | |
| 63 | if (! is_int($id)) { | |
| 64 | throw new InvalidFormatException(); | |
| 65 | } | |
| 66 | ||
| 60 | 67 | $ids = is_array($id) ? $id : func_get_args(); |
| 61 | 68 | |
| 62 | return $this->client->request('GET', 'media/show', ['media_ids' => $ids]); | |
| 69 | return $this->client->request('GET', 'media', ['media_ids' => $ids]); | |
| 63 | 70 | } |
| 64 | 71 | |
| 65 | 72 | /** |
| @@ -68,9 +75,15 @@ class Media | ||
| 68 | 75 | * @param int $id |
| 69 | 76 | * |
| 70 | 77 | * @return array |
| 78 | * | |
| 79 | * @throws InvalidFormatException | |
| 71 | 80 | */ |
| 72 | 81 | public function find($id) |
| 73 | 82 | { |
| 83 | if (! is_int($id)) { | |
| 84 | throw new InvalidFormatException(); | |
| 85 | } | |
| 86 | ||
| 74 | 87 | $response = $this->client->request('GET', "media/${id}"); |
| 75 | 88 | |
| 76 | 89 | return new Response($this, $response); |
| @@ -97,9 +110,15 @@ class Media | ||
| 97 | 110 | * @param string $name |
| 98 | 111 | * |
| 99 | 112 | * @return array |
| 113 | * | |
| 114 | * @throws InvalidFormatException | |
| 100 | 115 | */ |
| 101 | public function update($id, $name): array | |
| 116 | public function update($id, $name) | |
| 102 | 117 | { |
| 118 | if (! is_int($id)) { | |
| 119 | throw new InvalidFormatException(); | |
| 120 | } | |
| 121 | ||
| 103 | 122 | $name = is_array($name) ? $name : compact('name'); |
| 104 | 123 | |
| 105 | 124 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); |
| @@ -111,9 +130,15 @@ class Media | ||
| 111 | 130 | * @param int $id |
| 112 | 131 | * |
| 113 | 132 | * @return null |
| 133 | * | |
| 134 | * @throws InvalidFormatException | |
| 114 | 135 | */ |
| 115 | public function delete($id = null) | |
| 136 | public function delete($id) | |
| 116 | 137 | { |
| 138 | if (! is_int($id)) { | |
| 139 | throw new InvalidFormatException(); | |
| 140 | } | |
| 141 | ||
| 117 | 142 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); |
| 118 | 143 | } |
| 119 | 144 | |
| @@ -135,9 +160,15 @@ class Media | ||
| 135 | 160 | * @param int $id |
| 136 | 161 | * |
| 137 | 162 | * @return array |
| 163 | * | |
| 164 | * @throws InvalidFormatException | |
| 138 | 165 | */ |
| 139 | public function archive($id = null): array | |
| 166 | public function archive($id) | |
| 140 | 167 | { |
| 168 | if (! is_int($id)) { | |
| 169 | throw new InvalidFormatException(); | |
| 170 | } | |
| 171 | ||
| 141 | 172 | return $this->client->request('POST', "media/{$id}/archive"); |
| 142 | 173 | } |
| 143 | 174 | |
| @@ -147,9 +178,15 @@ class Media | ||
| 147 | 178 | * @param int $id |
| 148 | 179 | * |
| 149 | 180 | * @return array |
| 181 | * | |
| 182 | * @throws InvalidFormatException | |
| 150 | 183 | */ |
| 151 | public function unarchive($id): array | |
| 184 | public function unarchive($id) | |
| 152 | 185 | { |
| 186 | if (! is_int($id)) { | |
| 187 | throw new InvalidFormatException(); | |
| 188 | } | |
| 189 | ||
| 153 | 190 | return $this->client->request('POST', "media/{$id}/unarchive"); |
| 154 | 191 | } |
| 155 | 192 | |
| @@ -159,9 +196,15 @@ class Media | ||
| 159 | 196 | * @param int $id |
| 160 | 197 | * |
| 161 | 198 | * @return array |
| 199 | * | |
| 200 | * @throws InvalidFormatException | |
| 162 | 201 | */ |
| 163 | public function makePrivate($id): array | |
| 202 | public function makePrivate($id) | |
| 164 | 203 | { |
| 204 | if (! is_int($id)) { | |
| 205 | throw new InvalidFormatException(); | |
| 206 | } | |
| 207 | ||
| 165 | 208 | return $this->client->request('PATCH', "media/{$id}/make-private"); |
| 166 | 209 | } |
| 167 | 210 | |
| @@ -171,9 +214,15 @@ class Media | ||
| 171 | 214 | * @param int $id |
| 172 | 215 | * |
| 173 | 216 | * @return array |
| 217 | * | |
| 218 | * @throws InvalidFormatException | |
| 174 | 219 | */ |
| 175 | public function makePublic($id): array | |
| 220 | public function makePublic($id) | |
| 176 | 221 | { |
| 222 | if (! is_int($id)) { | |
| 223 | throw new InvalidFormatException(); | |
| 224 | } | |
| 225 | ||
| 177 | 226 | return $this->client->request('PATCH', "media/{$id}/make-public"); |
| 178 | 227 | } |
| 179 | 228 | |
| @@ -183,9 +232,15 @@ class Media | ||
| 183 | 232 | * @param int $id |
| 184 | 233 | * |
| 185 | 234 | * @return array |
| 235 | * | |
| 236 | * @throws InvalidFormatException | |
| 186 | 237 | */ |
| 187 | public function duplicate($id): array | |
| 238 | public function duplicate($id) | |
| 188 | 239 | { |
| 240 | if (! is_int($id)) { | |
| 241 | throw new InvalidFormatException(); | |
| 242 | } | |
| 243 | ||
| 189 | 244 | return $this->client->request('POST', "media/{$id}/duplicate"); |
| 190 | 245 | } |
| 191 | 246 | |
| @@ -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 | |