also looking at this
Exceptions
#27
5 files
+168
-14
| @@ -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 | |