also looking at this
Bulk Media
#29
2 files
+80
-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.
| @@ -135,8 +135,25 @@ class Media | ||
| 135 | 135 | */ |
| 136 | 136 | public function delete($id) |
| 137 | 137 | { |
| 138 | if (! is_int($id)) { | |
| 139 | throw new InvalidFormatException(); | |
| 138 | $ids = is_array($id) ? $id : func_get_args(); | |
| 139 | ||
| 140 | try { | |
| 141 | foreach ($ids as $id) { | |
| 142 | if (! is_int($id)) { | |
| 143 | throw new InvalidFormatException(); | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | if (count($ids) > 1) { | |
| 148 | return $this->client->request('POST', 'bulk/media/delete', ['media_ids' => $ids]); | |
| 149 | } | |
| 150 | ||
| 151 | // If count is equal to 1 get the first element | |
| 152 | $id = $ids[0]; | |
| 153 | ||
| 154 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); | |
| 155 | } catch (InvalidFormatException $e) { | |
| 156 | return $e->getMessage(); | |
| 140 | 157 | } |
| 141 | 158 | |
| 142 | 159 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); |
| @@ -165,8 +182,25 @@ class Media | ||
| 165 | 182 | */ |
| 166 | 183 | public function archive($id) |
| 167 | 184 | { |
| 168 | if (! is_int($id)) { | |
| 169 | throw new InvalidFormatException(); | |
| 185 | $ids = is_array($id) ? $id : func_get_args(); | |
| 186 | ||
| 187 | try { | |
| 188 | foreach ($ids as $id) { | |
| 189 | if (! is_int($id)) { | |
| 190 | throw new InvalidFormatException(); | |
| 191 | } | |
| 192 | } | |
| 193 | ||
| 194 | if (count($ids) > 1) { | |
| 195 | return $this->client->request('POST', 'bulk/media/archive', ['media_ids' => $ids]); | |
| 196 | } | |
| 197 | ||
| 198 | // If count is equal to 1 get the first element | |
| 199 | $id = $ids[0]; | |
| 200 | ||
| 201 | return $this->client->request('POST', "media/{$id}/archive"); | |
| 202 | } catch (InvalidFormatException $e) { | |
| 203 | return $e->getMessage(); | |
| 170 | 204 | } |
| 171 | 205 | |
| 172 | 206 | return $this->client->request('POST', "media/{$id}/archive"); |
| @@ -183,8 +217,25 @@ class Media | ||
| 183 | 217 | */ |
| 184 | 218 | public function unarchive($id) |
| 185 | 219 | { |
| 186 | if (! is_int($id)) { | |
| 187 | throw new InvalidFormatException(); | |
| 220 | $ids = is_array($id) ? $id : func_get_args(); | |
| 221 | ||
| 222 | try { | |
| 223 | foreach ($ids as $id) { | |
| 224 | if (! is_int($id)) { | |
| 225 | throw new InvalidFormatException(); | |
| 226 | } | |
| 227 | } | |
| 228 | ||
| 229 | if (count($ids) > 1) { | |
| 230 | return $this->client->request('POST', 'bulk/media/unarchive', ['media_ids' => $ids]); | |
| 231 | } | |
| 232 | ||
| 233 | // If count is equal to 1 get the first element | |
| 234 | $id = $ids[0]; | |
| 235 | ||
| 236 | return $this->client->request('POST', "media/{$id}/unarchive"); | |
| 237 | } catch (InvalidFormatException $e) { | |
| 238 | return $e->getMessage(); | |
| 188 | 239 | } |
| 189 | 240 | |
| 190 | 241 | return $this->client->request('POST', "media/{$id}/unarchive"); |
| @@ -201,8 +252,25 @@ class Media | ||
| 201 | 252 | */ |
| 202 | 253 | public function makePrivate($id) |
| 203 | 254 | { |
| 204 | if (! is_int($id)) { | |
| 205 | throw new InvalidFormatException(); | |
| 255 | $ids = is_array($id) ? $id : func_get_args(); | |
| 256 | ||
| 257 | try { | |
| 258 | foreach ($ids as $id) { | |
| 259 | if (! is_int($id)) { | |
| 260 | throw new InvalidFormatException(); | |
| 261 | } | |
| 262 | } | |
| 263 | ||
| 264 | if (count($ids) > 1) { | |
| 265 | return $this->client->request('POST', 'bulk/media/make-private', ['media_ids' => $ids]); | |
| 266 | } | |
| 267 | ||
| 268 | // If count is equal to 1 get the first element | |
| 269 | $id = $ids[0]; | |
| 270 | ||
| 271 | return $this->client->request('PATCH', "media/{$id}/make-private"); | |
| 272 | } catch (InvalidFormatException $e) { | |
| 273 | return $e->getMessage(); | |
| 206 | 274 | } |
| 207 | 275 | |
| 208 | 276 | return $this->client->request('PATCH', "media/{$id}/make-private"); |
| @@ -219,8 +287,25 @@ class Media | ||
| 219 | 287 | */ |
| 220 | 288 | public function makePublic($id) |
| 221 | 289 | { |
| 222 | if (! is_int($id)) { | |
| 223 | throw new InvalidFormatException(); | |
| 290 | $ids = is_array($id) ? $id : func_get_args(); | |
| 291 | ||
| 292 | try { | |
| 293 | foreach ($ids as $id) { | |
| 294 | if (! is_int($id)) { | |
| 295 | throw new InvalidFormatException(); | |
| 296 | } | |
| 297 | } | |
| 298 | ||
| 299 | if (count($ids) > 1) { | |
| 300 | return $this->client->request('POST', 'bulk/media/make-public', ['media_ids' => $ids]); | |
| 301 | } | |
| 302 | ||
| 303 | // If count is equal to 1 get the first element | |
| 304 | $id = $ids[0]; | |
| 305 | ||
| 306 | return $this->client->request('PATCH', "media/{$id}/make-public"); | |
| 307 | } catch (InvalidFormatException $e) { | |
| 308 | return $e->getMessage(); | |
| 224 | 309 | } |
| 225 | 310 | |
| 226 | 311 | return $this->client->request('PATCH', "media/{$id}/make-public"); |
| @@ -237,8 +322,25 @@ class Media | ||
| 237 | 322 | */ |
| 238 | 323 | public function duplicate($id) |
| 239 | 324 | { |
| 240 | if (! is_int($id)) { | |
| 241 | throw new InvalidFormatException(); | |
| 325 | $ids = is_array($id) ? $id : func_get_args(); | |
| 326 | ||
| 327 | try { | |
| 328 | foreach ($ids as $id) { | |
| 329 | if (! is_int($id)) { | |
| 330 | throw new InvalidFormatException(); | |
| 331 | } | |
| 332 | } | |
| 333 | ||
| 334 | if (count($ids) > 1) { | |
| 335 | return $this->client->request('POST', 'bulk/media/duplicate', ['media_ids' => $ids]); | |
| 336 | } | |
| 337 | ||
| 338 | // If count is equal to 1 get the first element | |
| 339 | $id = $ids[0]; | |
| 340 | ||
| 341 | return $this->client->request('POST', "media/{$id}/duplicate"); | |
| 342 | } catch (InvalidFormatException $e) { | |
| 343 | return $e->getMessage(); | |
| 242 | 344 | } |
| 243 | 345 | |
| 244 | 346 | return $this->client->request('POST', "media/{$id}/duplicate"); |