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+54-90
Changes to src/Models/Media.php
@@ -137,25 +137,19 @@ class Media
137137 {
138138 $ids = is_array($id) ? $id : func_get_args();
139139
140 try {
141 foreach ($ids as $id) {
142 if (! is_int($id)) {
143 throw new InvalidFormatException();
144 }
140 foreach ($ids as $id) {
141 if (! is_int($id)) {
142 throw new InvalidFormatException();
145143 }
144 }
146145
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();
146 if (count($ids) > 1) {
147 return $this->client->request('POST', 'bulk/media/delete', ['media_ids' => $ids]);
157148 }
158149
150 // If count is equal to 1 get the first element
151 $id = $ids[0];
152
159153 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
160154 }
161155
@@ -184,25 +178,19 @@ class Media
184178 {
185179 $ids = is_array($id) ? $id : func_get_args();
186180
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]);
181 foreach ($ids as $id) {
182 if (! is_int($id)) {
183 throw new InvalidFormatException();
196184 }
185 }
197186
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();
187 if (count($ids) > 1) {
188 return $this->client->request('POST', 'bulk/media/archive', ['media_ids' => $ids]);
204189 }
205190
191 // If count is equal to 1 get the first element
192 $id = $ids[0];
193
206194 return $this->client->request('POST', "media/{$id}/archive");
207195 }
208196
@@ -219,25 +207,19 @@ class Media
219207 {
220208 $ids = is_array($id) ? $id : func_get_args();
221209
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]);
210 foreach ($ids as $id) {
211 if (! is_int($id)) {
212 throw new InvalidFormatException();
231213 }
214 }
232215
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();
216 if (count($ids) > 1) {
217 return $this->client->request('POST', 'bulk/media/unarchive', ['media_ids' => $ids]);
239218 }
240219
220 // If count is equal to 1 get the first element
221 $id = $ids[0];
222
241223 return $this->client->request('POST', "media/{$id}/unarchive");
242224 }
243225
@@ -254,25 +236,19 @@ class Media
254236 {
255237 $ids = is_array($id) ? $id : func_get_args();
256238
257 try {
258 foreach ($ids as $id) {
259 if (! is_int($id)) {
260 throw new InvalidFormatException();
261 }
239 foreach ($ids as $id) {
240 if (! is_int($id)) {
241 throw new InvalidFormatException();
262242 }
243 }
263244
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();
245 if (count($ids) > 1) {
246 return $this->client->request('POST', 'bulk/media/make-private', ['media_ids' => $ids]);
274247 }
275248
249 // If count is equal to 1 get the first element
250 $id = $ids[0];
251
276252 return $this->client->request('PATCH', "media/{$id}/make-private");
277253 }
278254
@@ -289,25 +265,19 @@ class Media
289265 {
290266 $ids = is_array($id) ? $id : func_get_args();
291267
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]);
268 foreach ($ids as $id) {
269 if (! is_int($id)) {
270 throw new InvalidFormatException();
301271 }
272 }
302273
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();
274 if (count($ids) > 1) {
275 return $this->client->request('POST', 'bulk/media/make-public', ['media_ids' => $ids]);
309276 }
310277
278 // If count is equal to 1 get the first element
279 $id = $ids[0];
280
311281 return $this->client->request('PATCH', "media/{$id}/make-public");
312282 }
313283
@@ -324,25 +294,19 @@ class Media
324294 {
325295 $ids = is_array($id) ? $id : func_get_args();
326296
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]);
297 foreach ($ids as $id) {
298 if (! is_int($id)) {
299 throw new InvalidFormatException();
336300 }
301 }
337302
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();
303 if (count($ids) > 1) {
304 return $this->client->request('POST', 'bulk/media/duplicate', ['media_ids' => $ids]);
344305 }
345306
307 // If count is equal to 1 get the first element
308 $id = $ids[0];
309
346310 return $this->client->request('POST', "media/{$id}/duplicate");
347311 }
348312