also looking at this
Collection response
#52
11 files
+3638
-3582
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.
| @@ -4,6 +4,7 @@ namespace Meema\MeemaApi; | ||
| 4 | 4 | |
| 5 | 5 | use Dotenv\Dotenv; |
| 6 | 6 | use GuzzleHttp\Client as GuzzleClient; |
| 7 | use Illuminate\Support\Collection; | |
| 7 | 8 | use Meema\MeemaApi\Models\Favorite; |
| 8 | 9 | use Meema\MeemaApi\Models\Folder; |
| 9 | 10 | use Meema\MeemaApi\Models\Media; |
| @@ -21,18 +22,25 @@ class Client | ||
| 21 | 22 | */ |
| 22 | 23 | protected $accessKey; |
| 23 | 24 | |
| 25 | /** | |
| 26 | * @var bool | |
| 27 | */ | |
| 28 | protected $toCollection; | |
| 29 | ||
| 24 | 30 | /** |
| 25 | 31 | * Construct Meema client. |
| 26 | 32 | * |
| 27 | 33 | * @param string $accessKey |
| 28 | 34 | */ |
| 29 | public function __construct($accessKey, $baseUrl = null) | |
| 35 | public function __construct($accessKey, $config = []) | |
| 30 | 36 | { |
| 31 | 37 | $this->initializeEnv(); |
| 32 | 38 | |
| 33 | 39 | $this->accessKey = $accessKey; |
| 34 | 40 | |
| 35 | $url = $baseUrl ?? env('BASE_URL'); | |
| 41 | $this->toCollection = $config['to_collection'] ?? null; | |
| 42 | ||
| 43 | $url = $config['base_url'] ?? env('BASE_URL'); | |
| 36 | 44 | |
| 37 | 45 | $this->client = new GuzzleClient([ |
| 38 | 46 | 'base_uri' => $url ?? 'https://api.mee.ma', |
| @@ -75,10 +83,10 @@ class Client | ||
| 75 | 83 | $body = json_decode($content, true); |
| 76 | 84 | |
| 77 | 85 | if ($body && array_key_exists('data', $body)) { |
| 78 | return $body['data']; | |
| 86 | return $this->toCollection ? collect($body['data']) : $body['data']; | |
| 79 | 87 | } |
| 80 | 88 | |
| 81 | return $body; | |
| 89 | return $this->toCollection ? collect($body) : $body; | |
| 82 | 90 | } |
| 83 | 91 | |
| 84 | 92 | /** |
| @@ -33,7 +33,7 @@ class Favorite | ||
| 33 | 33 | * |
| 34 | 34 | * @return array |
| 35 | 35 | */ |
| 36 | public function all(): array | |
| 36 | public function all() | |
| 37 | 37 | { |
| 38 | 38 | return $this->client->request('GET', 'favorites'); |
| 39 | 39 | } |
| @@ -100,7 +100,7 @@ class Favorite | ||
| 100 | 100 | * |
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | public function update($id, $data): array | |
| 103 | public function update($id, $data) | |
| 104 | 104 | { |
| 105 | 105 | if (! is_int($id)) { |
| 106 | 106 | throw new InvalidFormatException(); |
| @@ -38,7 +38,7 @@ class Folder | ||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | public function all(): array | |
| 41 | public function all() | |
| 42 | 42 | { |
| 43 | 43 | return $this->client->request('GET', 'folders'); |
| 44 | 44 | } |
| @@ -108,7 +108,7 @@ class Folder | ||
| 108 | 108 | * |
| 109 | 109 | * @return array |
| 110 | 110 | */ |
| 111 | public function create($name): array | |
| 111 | public function create($name) | |
| 112 | 112 | { |
| 113 | 113 | $name = is_array($name) ? $name : compact('name'); |
| 114 | 114 | |
| @@ -129,7 +129,7 @@ class Folder | ||
| 129 | 129 | * |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | public function update($id, $name): array | |
| 132 | public function update($id, $name) | |
| 133 | 133 | { |
| 134 | 134 | if (! is_int($id)) { |
| 135 | 135 | throw new InvalidFormatException(); |
| @@ -240,7 +240,7 @@ class Folder | ||
| 240 | 240 | * |
| 241 | 241 | * @throws InvalidFormatException |
| 242 | 242 | */ |
| 243 | public function duplicate($ids): array | |
| 243 | public function duplicate($ids) | |
| 244 | 244 | { |
| 245 | 245 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 246 | 246 | |
| @@ -270,7 +270,7 @@ class Folder | ||
| 270 | 270 | * |
| 271 | 271 | * @throws InvalidFormatException |
| 272 | 272 | */ |
| 273 | protected function addFolderToMedia($id, $name): array | |
| 273 | protected function addFolderToMedia($id, $name) | |
| 274 | 274 | { |
| 275 | 275 | if (! is_int($id)) { |
| 276 | 276 | throw new InvalidFormatException(); |
| @@ -41,7 +41,7 @@ class Media | ||
| 41 | 41 | * |
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | public function all(): array | |
| 44 | public function all() | |
| 45 | 45 | { |
| 46 | 46 | return $this->client->request('GET', 'media'); |
| 47 | 47 | } |
| @@ -115,7 +115,7 @@ class Media | ||
| 115 | 115 | * |
| 116 | 116 | * @return array |
| 117 | 117 | */ |
| 118 | public function create($name): array | |
| 118 | public function create($name) | |
| 119 | 119 | { |
| 120 | 120 | $name = is_array($name) ? $name : compact('name'); |
| 121 | 121 | |
| @@ -449,7 +449,7 @@ class Media | ||
| 449 | 449 | * |
| 450 | 450 | * @return array |
| 451 | 451 | */ |
| 452 | protected function fetchMediaForFolder($id): array | |
| 452 | protected function fetchMediaForFolder($id) | |
| 453 | 453 | { |
| 454 | 454 | return $this->client->request('GET', "folders/{$id}/media"); |
| 455 | 455 | } |
| @@ -461,7 +461,7 @@ class Media | ||
| 461 | 461 | * |
| 462 | 462 | * @return array |
| 463 | 463 | */ |
| 464 | protected function fetchMediaForTag($id): array | |
| 464 | protected function fetchMediaForTag($id) | |
| 465 | 465 | { |
| 466 | 466 | return $this->client->request('GET', "tags/{$id}/media"); |
| 467 | 467 | } |
| @@ -38,7 +38,7 @@ class Tag | ||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | public function all(): array | |
| 41 | public function all() | |
| 42 | 42 | { |
| 43 | 43 | return $this->client->request('GET', 'tags'); |
| 44 | 44 | } |
| @@ -50,7 +50,7 @@ class Tag | ||
| 50 | 50 | * |
| 51 | 51 | * @return array |
| 52 | 52 | */ |
| 53 | public function get($ids = null): array | |
| 53 | public function get($ids = null) | |
| 54 | 54 | { |
| 55 | 55 | if ($this->model) { |
| 56 | 56 | return $this->fetchForModel(); |
| @@ -97,7 +97,7 @@ class Tag | ||
| 97 | 97 | * |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | public function update($id, $color): array | |
| 100 | public function update($id, $color) | |
| 101 | 101 | { |
| 102 | 102 | if (! is_int($id)) { |
| 103 | 103 | throw new InvalidFormatException(); |
| @@ -197,7 +197,7 @@ class Tag | ||
| 197 | 197 | * |
| 198 | 198 | * @return array |
| 199 | 199 | */ |
| 200 | protected function fetchTagsForMedia($id): array | |
| 200 | protected function fetchTagsForMedia($id) | |
| 201 | 201 | { |
| 202 | 202 | return $this->client->request('GET', "media/{$id}/tags"); |
| 203 | 203 | } |
| @@ -209,7 +209,7 @@ class Tag | ||
| 209 | 209 | * |
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | protected function fetchTagsForFolder($id): array | |
| 212 | protected function fetchTagsForFolder($id) | |
| 213 | 213 | { |
| 214 | 214 | return $this->client->request('GET', "folders/{$id}/tags"); |
| 215 | 215 | } |
| @@ -257,7 +257,7 @@ class Tag | ||
| 257 | 257 | * |
| 258 | 258 | * @return array |
| 259 | 259 | */ |
| 260 | protected function fetchForModel(): array | |
| 260 | protected function fetchForModel() | |
| 261 | 261 | { |
| 262 | 262 | $data = []; |
| 263 | 263 | |
| @@ -282,7 +282,7 @@ class Tag | ||
| 282 | 282 | * |
| 283 | 283 | * @return array |
| 284 | 284 | */ |
| 285 | protected function associateToModel($tag): array | |
| 285 | protected function associateToModel($tag) | |
| 286 | 286 | { |
| 287 | 287 | $data = []; |
| 288 | 288 | |
| @@ -307,7 +307,7 @@ class Tag | ||
| 307 | 307 | * |
| 308 | 308 | * @return array |
| 309 | 309 | */ |
| 310 | protected function disassociateToModel($tag): array | |
| 310 | protected function disassociateToModel($tag) | |
| 311 | 311 | { |
| 312 | 312 | $data = []; |
| 313 | 313 | |
| @@ -28,7 +28,7 @@ class Team | ||
| 28 | 28 | * |
| 29 | 29 | * @return array |
| 30 | 30 | */ |
| 31 | public function all(): array | |
| 31 | public function all() | |
| 32 | 32 | { |
| 33 | 33 | return $this->client->request('GET', 'teams'); |
| 34 | 34 | } |
| @@ -85,7 +85,7 @@ class Team | ||
| 85 | 85 | * |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | public function update($id, $name): array | |
| 88 | public function update($id, $name) | |
| 89 | 89 | { |
| 90 | 90 | $name = is_array($name) ? $name : compact('name'); |
| 91 | 91 | |