also looking at this
Collection response
#52
11 files
+3638
-3582
| @@ -8,9 +8,12 @@ use GuzzleHttp\Psr7\Request; | ||
| 8 | 8 | use Meema\MeemaApi\Client; |
| 9 | 9 | use Meema\MeemaApi\Exceptions\InvalidFormatException; |
| 10 | 10 | use Meema\MeemaApi\Response\Response; |
| 11 | use Meema\MeemaApi\Traits\CollectionsResponse; | |
| 11 | 12 | |
| 12 | 13 | class Media |
| 13 | 14 | { |
| 15 | use CollectionsResponse; | |
| 16 | ||
| 14 | 17 | /** |
| 15 | 18 | * @var \Meema\MeemaApi\Client |
| 16 | 19 | */ |
| @@ -39,9 +42,9 @@ class Media | ||
| 39 | 42 | /** |
| 40 | 43 | * List all media. |
| 41 | 44 | * |
| 42 | * @return array | |
| 45 | * @return \Illuminate\Support\Collection|array | |
| 43 | 46 | */ |
| 44 | public function all(): array | |
| 47 | public function all() | |
| 45 | 48 | { |
| 46 | 49 | return $this->client->request('GET', 'media'); |
| 47 | 50 | } |
| @@ -51,18 +54,18 @@ class Media | ||
| 51 | 54 | * |
| 52 | 55 | * @param array $ids |
| 53 | 56 | * |
| 54 | * @return array | |
| 57 | * @return \Illuminate\Support\Collection|array | |
| 55 | 58 | * |
| 56 | 59 | * @throws InvalidFormatException |
| 57 | 60 | */ |
| 58 | 61 | public function get($ids = null) |
| 59 | 62 | { |
| 60 | 63 | if ($this->model) { |
| 61 | return $this->fetchForModel(); | |
| 64 | return $this->toCollection($this->fetchForModel()); | |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | if (! $ids) { |
| 65 | return $this->all(); | |
| 68 | return $this->toCollection($this->all()); | |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | 71 | $ids = is_array($ids) ? $ids : func_get_args(); |
| @@ -73,7 +76,9 @@ class Media | ||
| 73 | 76 | } |
| 74 | 77 | } |
| 75 | 78 | |
| 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); | |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | 84 | /** |
| @@ -81,11 +86,13 @@ class Media | ||
| 81 | 86 | * |
| 82 | 87 | * @param string $query |
| 83 | 88 | * |
| 84 | * @return array | |
| 89 | * @return \Illuminate\Support\Collection|array | |
| 85 | 90 | */ |
| 86 | 91 | public function search($query) |
| 87 | 92 | { |
| 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); | |
| 89 | 96 | } |
| 90 | 97 | |
| 91 | 98 | /** |
| @@ -115,7 +122,7 @@ class Media | ||
| 115 | 122 | * |
| 116 | 123 | * @return array |
| 117 | 124 | */ |
| 118 | public function create($name): array | |
| 125 | public function create($name) | |
| 119 | 126 | { |
| 120 | 127 | $name = is_array($name) ? $name : compact('name'); |
| 121 | 128 | |
| @@ -449,7 +456,7 @@ class Media | ||
| 449 | 456 | * |
| 450 | 457 | * @return array |
| 451 | 458 | */ |
| 452 | protected function fetchMediaForFolder($id): array | |
| 459 | protected function fetchMediaForFolder($id) | |
| 453 | 460 | { |
| 454 | 461 | return $this->client->request('GET', "folders/{$id}/media"); |
| 455 | 462 | } |
| @@ -461,7 +468,7 @@ class Media | ||
| 461 | 468 | * |
| 462 | 469 | * @return array |
| 463 | 470 | */ |
| 464 | protected function fetchMediaForTag($id): array | |
| 471 | protected function fetchMediaForTag($id) | |
| 465 | 472 | { |
| 466 | 473 | return $this->client->request('GET', "tags/{$id}/media"); |
| 467 | 474 | } |