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 Tag |
| 10 | 11 | { |
| 12 | use CollectionsResponse; | |
| 13 | ||
| 11 | 14 | /** |
| 12 | 15 | * @var \Meema\MeemaApi\Client |
| 13 | 16 | */ |
| @@ -38,7 +41,7 @@ class Tag | ||
| 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', 'tags'); |
| 44 | 47 | } |
| @@ -48,16 +51,16 @@ class Tag | ||
| 48 | 51 | * |
| 49 | 52 | * @param array $ids |
| 50 | 53 | * |
| 51 | * @return array | |
| 54 | * @return \Illuminate\Support\Collection|array | |
| 52 | 55 | */ |
| 53 | public function get($ids = null): array | |
| 56 | public function get($ids = null) | |
| 54 | 57 | { |
| 55 | 58 | if ($this->model) { |
| 56 | return $this->fetchForModel(); | |
| 59 | return $this->toCollection($this->fetchForModel()); | |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | 62 | if (! $ids) { |
| 60 | return $this->all(); | |
| 63 | return $this->toCollection($this->all()); | |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | 66 | $ids = is_array($ids) ? $ids : func_get_args(); |
| @@ -68,7 +71,9 @@ class Tag | ||
| 68 | 71 | } |
| 69 | 72 | } |
| 70 | 73 | |
| 71 | return $this->client->request('GET', 'tags', ['tag_ids' => $ids]); | |
| 74 | $response = $this->client->request('GET', 'tags', ['tag_ids' => $ids]); | |
| 75 | ||
| 76 | return $this->toCollection($response); | |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | /** |
| @@ -97,7 +102,7 @@ class Tag | ||
| 97 | 102 | * |
| 98 | 103 | * @return array |
| 99 | 104 | */ |
| 100 | public function update($id, $color): array | |
| 105 | public function update($id, $color) | |
| 101 | 106 | { |
| 102 | 107 | if (! is_int($id)) { |
| 103 | 108 | throw new InvalidFormatException(); |
formatting only · 8 hidden lines
| @@ -150,7 +155,7 @@ class Tag formatting only | ||
| 150 | 155 | return $this->associateToModel($tag); |
| 151 | 156 | } |
| 152 | 157 | |
| 153 | /** | |
| 158 | /** | |
| 154 | 159 | * Associate tags to media. |
| 155 | 160 | * |
| 156 | 161 | * @param array $tag |
| @@ -197,7 +202,7 @@ class Tag | ||
| 197 | 202 | * |
| 198 | 203 | * @return array |
| 199 | 204 | */ |
| 200 | protected function fetchTagsForMedia($id): array | |
| 205 | protected function fetchTagsForMedia($id) | |
| 201 | 206 | { |
| 202 | 207 | return $this->client->request('GET', "media/{$id}/tags"); |
| 203 | 208 | } |
| @@ -209,7 +214,7 @@ class Tag | ||
| 209 | 214 | * |
| 210 | 215 | * @return array |
| 211 | 216 | */ |
| 212 | protected function fetchTagsForFolder($id): array | |
| 217 | protected function fetchTagsForFolder($id) | |
| 213 | 218 | { |
| 214 | 219 | return $this->client->request('GET', "folders/{$id}/tags"); |
| 215 | 220 | } |
| @@ -257,7 +262,7 @@ class Tag | ||
| 257 | 262 | * |
| 258 | 263 | * @return array |
| 259 | 264 | */ |
| 260 | protected function fetchForModel(): array | |
| 265 | protected function fetchForModel() | |
| 261 | 266 | { |
| 262 | 267 | $data = []; |
| 263 | 268 | |
| @@ -282,7 +287,7 @@ class Tag | ||
| 282 | 287 | * |
| 283 | 288 | * @return array |
| 284 | 289 | */ |
| 285 | protected function associateToModel($tag): array | |
| 290 | protected function associateToModel($tag) | |
| 286 | 291 | { |
| 287 | 292 | $data = []; |
| 288 | 293 | |
| @@ -307,7 +312,7 @@ class Tag | ||
| 307 | 312 | * |
| 308 | 313 | * @return array |
| 309 | 314 | */ |
| 310 | protected function disassociateToModel($tag): array | |
| 315 | protected function disassociateToModel($tag) | |
| 311 | 316 | { |
| 312 | 317 | $data = []; |
| 313 | 318 | |