also looking at this
Collection response
#52
11 files
+3638
-3582
| @@ -5,9 +5,12 @@ namespace Meema\MeemaApi\Models; | ||
| 5 | 5 | use Meema\MeemaApi\Client; |
| 6 | 6 | use Meema\MeemaApi\Exceptions\InvalidFormatException; |
| 7 | 7 | use Meema\MeemaApi\Response\Response; |
| 8 | use Meema\MeemaApi\Traits\CollectionsResponse; | |
| 8 | 9 | |
| 9 | 10 | class Folder |
| 10 | 11 | { |
| 12 | use CollectionsResponse; | |
| 13 | ||
| 11 | 14 | /** |
| 12 | 15 | * @var \Meema\MeemaApi\Client |
| 13 | 16 | */ |
| @@ -38,7 +41,7 @@ class Folder | ||
| 38 | 41 | * |
| 39 | 42 | * @return array |
| 40 | 43 | */ |
| 41 | public function all(): array | |
| 44 | public function all() | |
| 42 | 45 | { |
| 43 | 46 | return $this->client->request('GET', 'folders'); |
| 44 | 47 | } |
| @@ -48,14 +51,14 @@ class Folder | ||
| 48 | 51 | * |
| 49 | 52 | * @param int $id |
| 50 | 53 | * |
| 51 | * @return mixed | |
| 54 | * @return \Illuminate\Support\Collection|array | |
| 52 | 55 | * |
| 53 | 56 | * @throws InvalidFormatException |
| 54 | 57 | */ |
| 55 | 58 | public function get($id = null) |
| 56 | 59 | { |
| 57 | 60 | if (! $id) { |
| 58 | return $this->all(); | |
| 61 | return $this->toCollection($this->all()); | |
| 59 | 62 | } |
| 60 | 63 | |
| 61 | 64 | $ids = is_array($id) ? $id : func_get_args(); |
| @@ -66,7 +69,9 @@ class Folder | ||
| 66 | 69 | } |
| 67 | 70 | } |
| 68 | 71 | |
| 69 | return $this->client->request('GET', 'folders', ['folder_ids' => $ids]); | |
| 72 | $response = $this->client->request('GET', 'folders', ['folder_ids' => $ids]); | |
| 73 | ||
| 74 | return $this->toCollection($response); | |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | /** |
| @@ -78,7 +83,9 @@ class Folder | ||
| 78 | 83 | */ |
| 79 | 84 | public function search($query) |
| 80 | 85 | { |
| 81 | return $this->client->request('POST', 'folders/search', compact('query')); | |
| 86 | $response = $this->client->request('POST', 'folders/search', compact('query')); | |
| 87 | ||
| 88 | return $this->toCollection($response); | |
| 82 | 89 | } |
| 83 | 90 | |
| 84 | 91 | /** |
| @@ -108,7 +115,7 @@ class Folder | ||
| 108 | 115 | * |
| 109 | 116 | * @return array |
| 110 | 117 | */ |
| 111 | public function create($name): array | |
| 118 | public function create($name) | |
| 112 | 119 | { |
| 113 | 120 | $name = is_array($name) ? $name : compact('name'); |
| 114 | 121 | |
| @@ -129,7 +136,7 @@ class Folder | ||
| 129 | 136 | * |
| 130 | 137 | * @return array |
| 131 | 138 | */ |
| 132 | public function update($id, $name): array | |
| 139 | public function update($id, $name) | |
| 133 | 140 | { |
| 134 | 141 | if (! is_int($id)) { |
| 135 | 142 | throw new InvalidFormatException(); |
| @@ -240,7 +247,7 @@ class Folder | ||
| 240 | 247 | * |
| 241 | 248 | * @throws InvalidFormatException |
| 242 | 249 | */ |
| 243 | public function duplicate($ids): array | |
| 250 | public function duplicate($ids) | |
| 244 | 251 | { |
| 245 | 252 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 246 | 253 | |
| @@ -270,7 +277,7 @@ class Folder | ||
| 270 | 277 | * |
| 271 | 278 | * @throws InvalidFormatException |
| 272 | 279 | */ |
| 273 | protected function addFolderToMedia($id, $name): array | |
| 280 | protected function addFolderToMedia($id, $name) | |
| 274 | 281 | { |
| 275 | 282 | if (! is_int($id)) { |
| 276 | 283 | throw new InvalidFormatException(); |