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

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.

src/Client.phpmodified+12-4
Changes to src/Client.php
@@ -4,6 +4,7 @@ namespace Meema\MeemaApi;
44
55use Dotenv\Dotenv;
66use GuzzleHttp\Client as GuzzleClient;
7use Illuminate\Support\Collection;
78use Meema\MeemaApi\Models\Favorite;
89use Meema\MeemaApi\Models\Folder;
910use Meema\MeemaApi\Models\Media;
@@ -21,18 +22,25 @@ class Client
2122 */
2223 protected $accessKey;
2324
25 /**
26 * @var bool
27 */
28 protected $toCollection;
29
2430 /**
2531 * Construct Meema client.
2632 *
2733 * @param string $accessKey
2834 */
29 public function __construct($accessKey, $baseUrl = null)
35 public function __construct($accessKey, $config = [])
3036 {
3137 $this->initializeEnv();
3238
3339 $this->accessKey = $accessKey;
3440
35 $url = $baseUrl ?? env('BASE_URL');
41 $this->toCollection = $config['to_collection'] ?? null;
42
43 $url = $config['base_url'] ?? env('BASE_URL');
3644
3745 $this->client = new GuzzleClient([
3846 'base_uri' => $url ?? 'https://api.mee.ma',
@@ -75,10 +83,10 @@ class Client
7583 $body = json_decode($content, true);
7684
7785 if ($body && array_key_exists('data', $body)) {
78 return $body['data'];
86 return $this->toCollection ? collect($body['data']) : $body['data'];
7987 }
8088
81 return $body;
89 return $this->toCollection ? collect($body) : $body;
8290 }
8391
8492 /**
src/Models/Favorite.phpmodified+2-2
Changes to src/Models/Favorite.php
@@ -33,7 +33,7 @@ class Favorite
3333 *
3434 * @return array
3535 */
36 public function all(): array
36 public function all()
3737 {
3838 return $this->client->request('GET', 'favorites');
3939 }
@@ -100,7 +100,7 @@ class Favorite
100100 *
101101 * @return array
102102 */
103 public function update($id, $data): array
103 public function update($id, $data)
104104 {
105105 if (! is_int($id)) {
106106 throw new InvalidFormatException();
src/Models/Folder.phpmodified+5-5
Changes to src/Models/Folder.php
@@ -38,7 +38,7 @@ class Folder
3838 *
3939 * @return array
4040 */
41 public function all(): array
41 public function all()
4242 {
4343 return $this->client->request('GET', 'folders');
4444 }
@@ -108,7 +108,7 @@ class Folder
108108 *
109109 * @return array
110110 */
111 public function create($name): array
111 public function create($name)
112112 {
113113 $name = is_array($name) ? $name : compact('name');
114114
@@ -129,7 +129,7 @@ class Folder
129129 *
130130 * @return array
131131 */
132 public function update($id, $name): array
132 public function update($id, $name)
133133 {
134134 if (! is_int($id)) {
135135 throw new InvalidFormatException();
@@ -240,7 +240,7 @@ class Folder
240240 *
241241 * @throws InvalidFormatException
242242 */
243 public function duplicate($ids): array
243 public function duplicate($ids)
244244 {
245245 $ids = is_array($ids) ? $ids : func_get_args();
246246
@@ -270,7 +270,7 @@ class Folder
270270 *
271271 * @throws InvalidFormatException
272272 */
273 protected function addFolderToMedia($id, $name): array
273 protected function addFolderToMedia($id, $name)
274274 {
275275 if (! is_int($id)) {
276276 throw new InvalidFormatException();
src/Models/Media.phpmodified+4-4
Changes to src/Models/Media.php
@@ -41,7 +41,7 @@ class Media
4141 *
4242 * @return array
4343 */
44 public function all(): array
44 public function all()
4545 {
4646 return $this->client->request('GET', 'media');
4747 }
@@ -115,7 +115,7 @@ class Media
115115 *
116116 * @return array
117117 */
118 public function create($name): array
118 public function create($name)
119119 {
120120 $name = is_array($name) ? $name : compact('name');
121121
@@ -449,7 +449,7 @@ class Media
449449 *
450450 * @return array
451451 */
452 protected function fetchMediaForFolder($id): array
452 protected function fetchMediaForFolder($id)
453453 {
454454 return $this->client->request('GET', "folders/{$id}/media");
455455 }
@@ -461,7 +461,7 @@ class Media
461461 *
462462 * @return array
463463 */
464 protected function fetchMediaForTag($id): array
464 protected function fetchMediaForTag($id)
465465 {
466466 return $this->client->request('GET', "tags/{$id}/media");
467467 }
src/Models/Tag.phpmodified+8-8
Changes to src/Models/Tag.php
@@ -38,7 +38,7 @@ class Tag
3838 *
3939 * @return array
4040 */
41 public function all(): array
41 public function all()
4242 {
4343 return $this->client->request('GET', 'tags');
4444 }
@@ -50,7 +50,7 @@ class Tag
5050 *
5151 * @return array
5252 */
53 public function get($ids = null): array
53 public function get($ids = null)
5454 {
5555 if ($this->model) {
5656 return $this->fetchForModel();
@@ -97,7 +97,7 @@ class Tag
9797 *
9898 * @return array
9999 */
100 public function update($id, $color): array
100 public function update($id, $color)
101101 {
102102 if (! is_int($id)) {
103103 throw new InvalidFormatException();
@@ -197,7 +197,7 @@ class Tag
197197 *
198198 * @return array
199199 */
200 protected function fetchTagsForMedia($id): array
200 protected function fetchTagsForMedia($id)
201201 {
202202 return $this->client->request('GET', "media/{$id}/tags");
203203 }
@@ -209,7 +209,7 @@ class Tag
209209 *
210210 * @return array
211211 */
212 protected function fetchTagsForFolder($id): array
212 protected function fetchTagsForFolder($id)
213213 {
214214 return $this->client->request('GET', "folders/{$id}/tags");
215215 }
@@ -257,7 +257,7 @@ class Tag
257257 *
258258 * @return array
259259 */
260 protected function fetchForModel(): array
260 protected function fetchForModel()
261261 {
262262 $data = [];
263263
@@ -282,7 +282,7 @@ class Tag
282282 *
283283 * @return array
284284 */
285 protected function associateToModel($tag): array
285 protected function associateToModel($tag)
286286 {
287287 $data = [];
288288
@@ -307,7 +307,7 @@ class Tag
307307 *
308308 * @return array
309309 */
310 protected function disassociateToModel($tag): array
310 protected function disassociateToModel($tag)
311311 {
312312 $data = [];
313313
src/Models/Team.phpmodified+2-2
Changes to src/Models/Team.php
@@ -28,7 +28,7 @@ class Team
2828 *
2929 * @return array
3030 */
31 public function all(): array
31 public function all()
3232 {
3333 return $this->client->request('GET', 'teams');
3434 }
@@ -85,7 +85,7 @@ class Team
8585 *
8686 * @return array
8787 */
88 public function update($id, $name): array
88 public function update($id, $name)
8989 {
9090 $name = is_array($name) ? $name : compact('name');
9191
tests/ClientTest.phpmodified+1-1
Changes to tests/ClientTest.php
@@ -23,7 +23,7 @@ class ClientTest extends TestCase
2323 {
2424 $teamId = env('PUBLISHABLE_KEY');
2525
26 $client = new Client($teamId, env('BASE_URL_TEST'));
26 $client = new Client($teamId, ['base_url' => env('BASE_URL_TEST')]);
2727
2828 $this->client = $client;
2929