ReviewOS

also looking at this

meemalabs/meema-client-php

Collection response

#52
Merged glennmichael123 wants to merge collection-response into main
11 files +3638 -3582
src/Models/Media.phpmodified+18-11
Changes to src/Models/Media.php
@@ -8,9 +8,12 @@ use GuzzleHttp\Psr7\Request;
88use Meema\MeemaApi\Client;
99use Meema\MeemaApi\Exceptions\InvalidFormatException;
1010use Meema\MeemaApi\Response\Response;
11use Meema\MeemaApi\Traits\CollectionsResponse;
1112
1213class Media
1314{
15 use CollectionsResponse;
16
1417 /**
1518 * @var \Meema\MeemaApi\Client
1619 */
@@ -39,9 +42,9 @@ class Media
3942 /**
4043 * List all media.
4144 *
42 * @return array
45 * @return \Illuminate\Support\Collection|array
4346 */
44 public function all(): array
47 public function all()
4548 {
4649 return $this->client->request('GET', 'media');
4750 }
@@ -51,18 +54,18 @@ class Media
5154 *
5255 * @param array $ids
5356 *
54 * @return array
57 * @return \Illuminate\Support\Collection|array
5558 *
5659 * @throws InvalidFormatException
5760 */
5861 public function get($ids = null)
5962 {
6063 if ($this->model) {
61 return $this->fetchForModel();
64 return $this->toCollection($this->fetchForModel());
6265 }
6366
6467 if (! $ids) {
65 return $this->all();
68 return $this->toCollection($this->all());
6669 }
6770
6871 $ids = is_array($ids) ? $ids : func_get_args();
@@ -73,7 +76,9 @@ class Media
7376 }
7477 }
7578
76 return $this->client->request('GET', 'media', ['media_ids' => $ids]);
79 $response = $this->client->request('GET', 'media', ['media_ids' => $ids]);
80
81 return $this->toCollection($response);
7782 }
7883
7984 /**
@@ -81,11 +86,13 @@ class Media
8186 *
8287 * @param string $query
8388 *
84 * @return array
89 * @return \Illuminate\Support\Collection|array
8590 */
8691 public function search($query)
8792 {
88 return $this->client->request('POST', 'media/search', compact('query'));
93 $response = $this->client->request('POST', 'media/search', compact('query'));
94
95 return $this->toCollection($response);
8996 }
9097
9198 /**
@@ -115,7 +122,7 @@ class Media
115122 *
116123 * @return array
117124 */
118 public function create($name): array
125 public function create($name)
119126 {
120127 $name = is_array($name) ? $name : compact('name');
121128
@@ -449,7 +456,7 @@ class Media
449456 *
450457 * @return array
451458 */
452 protected function fetchMediaForFolder($id): array
459 protected function fetchMediaForFolder($id)
453460 {
454461 return $this->client->request('GET', "folders/{$id}/media");
455462 }
@@ -461,7 +468,7 @@ class Media
461468 *
462469 * @return array
463470 */
464 protected function fetchMediaForTag($id): array
471 protected function fetchMediaForTag($id)
465472 {
466473 return $this->client->request('GET', "tags/{$id}/media");
467474 }