ReviewOS

also looking at this

meemalabs/meema-client-php

Bulk Media

#29
Merged glennmichael123 wants to merge bulk-media into main
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.

src/Models/Media.phpmodified+114-12
Changes to src/Models/Media.php
@@ -135,8 +135,25 @@ class Media
135135 */
136136 public function delete($id)
137137 {
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();
140157 }
141158
142159 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
@@ -165,8 +182,25 @@ class Media
165182 */
166183 public function archive($id)
167184 {
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();
170204 }
171205
172206 return $this->client->request('POST', "media/{$id}/archive");
@@ -183,8 +217,25 @@ class Media
183217 */
184218 public function unarchive($id)
185219 {
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();
188239 }
189240
190241 return $this->client->request('POST', "media/{$id}/unarchive");
@@ -201,8 +252,25 @@ class Media
201252 */
202253 public function makePrivate($id)
203254 {
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();
206274 }
207275
208276 return $this->client->request('PATCH', "media/{$id}/make-private");
@@ -219,8 +287,25 @@ class Media
219287 */
220288 public function makePublic($id)
221289 {
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();
224309 }
225310
226311 return $this->client->request('PATCH', "media/{$id}/make-public");
@@ -237,8 +322,25 @@ class Media
237322 */
238323 public function duplicate($id)
239324 {
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();
242344 }
243345
244346 return $this->client->request('POST', "media/{$id}/duplicate");