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 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,7 +60,15 @@ class Media | ||
| 57 | 60 | return $this->all(); |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | $ids = is_array($id) ? $id : func_get_args(); | |
| 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->errorMessage(); | |
| 71 | } | |
| 61 | 72 | |
| 62 | 73 | return $this->client->request('GET', 'media/show', ['media_ids' => $ids]); |
| 63 | 74 | } |
| @@ -68,10 +79,20 @@ class Media | ||
| 68 | 79 | * @param int $id |
| 69 | 80 | * |
| 70 | 81 | * @return array |
| 82 | * | |
| 83 | * @throws InvalidFormatException | |
| 71 | 84 | */ |
| 72 | 85 | public function find($id) |
| 73 | 86 | { |
| 74 | $response = $this->client->request('GET', "media/${id}"); | |
| 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->errorMessage(); | |
| 95 | } | |
| 75 | 96 | |
| 76 | 97 | return new Response($this, $response); |
| 77 | 98 | } |
| @@ -97,12 +118,22 @@ class Media | ||
| 97 | 118 | * @param string $name |
| 98 | 119 | * |
| 99 | 120 | * @return array |
| 121 | * | |
| 122 | * @throws InvalidFormatException | |
| 100 | 123 | */ |
| 101 | public function update($id, $name): array | |
| 124 | public function update($id, $name) | |
| 102 | 125 | { |
| 103 | $name = is_array($name) ? $name : compact('name'); | |
| 126 | try { | |
| 127 | if (! is_int($id)) { | |
| 128 | throw new InvalidFormatException(); | |
| 129 | } | |
| 130 | ||
| 131 | $name = is_array($name) ? $name : compact('name'); | |
| 104 | 132 | |
| 105 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); | |
| 133 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); | |
| 134 | } catch (InvalidFormatException $e) { | |
| 135 | return $e->errorMessage(); | |
| 136 | } | |
| 106 | 137 | } |
| 107 | 138 | |
| 108 | 139 | /** |
| @@ -111,10 +142,20 @@ class Media | ||
| 111 | 142 | * @param int $id |
| 112 | 143 | * |
| 113 | 144 | * @return null |
| 145 | * | |
| 146 | * @throws InvalidFormatException | |
| 114 | 147 | */ |
| 115 | public function delete($id = null) | |
| 148 | public function delete($id) | |
| 116 | 149 | { |
| 117 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); | |
| 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->errorMessage(); | |
| 158 | } | |
| 118 | 159 | } |
| 119 | 160 | |
| 120 | 161 | /** |
| @@ -135,10 +176,20 @@ class Media | ||
| 135 | 176 | * @param int $id |
| 136 | 177 | * |
| 137 | 178 | * @return array |
| 179 | * | |
| 180 | * @throws InvalidFormatException | |
| 138 | 181 | */ |
| 139 | public function archive($id = null): array | |
| 182 | public function archive($id) | |
| 140 | 183 | { |
| 141 | return $this->client->request('POST', "media/{$id}/archive"); | |
| 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->errorMessage(); | |
| 192 | } | |
| 142 | 193 | } |
| 143 | 194 | |
| 144 | 195 | /** |
| @@ -147,10 +198,20 @@ class Media | ||
| 147 | 198 | * @param int $id |
| 148 | 199 | * |
| 149 | 200 | * @return array |
| 201 | * | |
| 202 | * @throws InvalidFormatException | |
| 150 | 203 | */ |
| 151 | public function unarchive($id): array | |
| 204 | public function unarchive($id) | |
| 152 | 205 | { |
| 153 | return $this->client->request('POST', "media/{$id}/unarchive"); | |
| 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->errorMessage(); | |
| 214 | } | |
| 154 | 215 | } |
| 155 | 216 | |
| 156 | 217 | /** |
| @@ -159,10 +220,20 @@ class Media | ||
| 159 | 220 | * @param int $id |
| 160 | 221 | * |
| 161 | 222 | * @return array |
| 223 | * | |
| 224 | * @throws InvalidFormatException | |
| 162 | 225 | */ |
| 163 | 226 | public function makePrivate($id): array |
| 164 | 227 | { |
| 165 | return $this->client->request('PATCH', "media/{$id}/make-private"); | |
| 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->errorMessage(); | |
| 236 | } | |
| 166 | 237 | } |
| 167 | 238 | |
| 168 | 239 | /** |
| @@ -171,10 +242,20 @@ class Media | ||
| 171 | 242 | * @param int $id |
| 172 | 243 | * |
| 173 | 244 | * @return array |
| 245 | * | |
| 246 | * @throws InvalidFormatException | |
| 174 | 247 | */ |
| 175 | public function makePublic($id): array | |
| 248 | public function makePublic($id) | |
| 176 | 249 | { |
| 177 | return $this->client->request('PATCH', "media/{$id}/make-public"); | |
| 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->errorMessage(); | |
| 258 | } | |
| 178 | 259 | } |
| 179 | 260 | |
| 180 | 261 | /** |
| @@ -183,10 +264,20 @@ class Media | ||
| 183 | 264 | * @param int $id |
| 184 | 265 | * |
| 185 | 266 | * @return array |
| 267 | * | |
| 268 | * @throws InvalidFormatException | |
| 186 | 269 | */ |
| 187 | 270 | public function duplicate($id): array |
| 188 | 271 | { |
| 189 | return $this->client->request('POST', "media/{$id}/duplicate"); | |
| 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->errorMessage(); | |
| 280 | } | |
| 190 | 281 | } |
| 191 | 282 | |
| 192 | 283 | /** |