ReviewOS

also looking at this

meemalabs/meema-client-php

initialize progress

#1
Merged glennmichael123 wants to merge initial-progress into main
17 files +581 -48

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+19-11
Changes to src/Client.php
@@ -3,6 +3,7 @@
33namespace Meema\MeemaApi;
44
55use GuzzleHttp\Client as GuzzleClient;
6use Meema\MeemaApi\Models\Folder;
67
78class Client
89{
@@ -11,6 +12,12 @@ class Client
1112 */
1213 protected $client;
1314
15 /**
16 * @var Meema\MeemaApi\Models\Folder
17 */
18 public $folders;
19
20
1421 /**
1522 * @var string
1623 */
@@ -25,7 +32,7 @@ class Client
2532 {
2633 $this->accessKey = $accessKey;
2734 $this->client = new GuzzleClient([
28 'base_uri' => 'http://127.0.0.1:8000/api/',
35 'base_uri' => 'http://meema-api.test/api/',
2936 ]);
3037 }
3138
@@ -45,7 +52,9 @@ class Client
4552 'Content-Type' => 'application/json',
4653 'Authorization' => "Bearer {$this->accessKey}",
4754 ],
48 ])->getBody()->getContents();
55 ])
56 ->getBody()
57 ->getContents();
4958
5059 return json_decode($content, true);
5160 }
@@ -61,23 +70,22 @@ class Client
6170 }
6271
6372 /**
64 * List folders.
73 * Get the access key
6574 *
66 * @return array
75 * @return string
6776 */
68 public function listFolders()
77 public function getAccessKey(): string
6978 {
70 return $this->request('GET', 'folders');
79 return $this->accessKey;
7180 }
7281
7382 /**
74 * Create folder.
83 * Initialize the folder model
7584 *
76 * @param string $name
77 * @return array
85 * @return Meema\MeemaApi\Models\Folder
7886 */
79 public function createFolder($name)
87 public function folders($id = null): Folder
8088 {
81 return $this->request('POST', 'folders', compact('name'));
89 return new Folder($this, $id);
8290 }
8391}
src/Models/Folder.phpadded+107-0
Changes to src/Models/Folder.php
@@ -0,0 +1,107 @@
1<?php
2
3namespace Meema\MeemaApi\Models;
4
5use Meema\MeemaApi\Client;
6
7class Folder
8{
9 /**
10 * @var Meema\MeemaApi\Client
11 */
12 public $client;
13
14 /**
15 * @var int $id
16 */
17 public $id;
18
19 /**
20 * Construct Folder model.
21 *
22 * @param Meema\MeemaApi\Client $client
23 */
24 public function __construct(Client $client, $id)
25 {
26 $this->client = $client;
27
28 $this->id = $id;
29 }
30
31 /**
32 * List all folders.
33 *
34 * @return array
35 */
36 public function all(): array
37 {
38 return $this->client->request('GET', 'folders');
39 }
40
41 /**
42 * Create folder.
43 *
44 * @param string $name
45 *
46 * @return array
47 */
48 public function create($name): array
49 {
50 return $this->client->request('POST', "folders/{$this->client->getAccessKey()}", compact('name'));
51 }
52
53 /**
54 * Update folder.
55 *
56 * @param int $id
57 * @param string $name
58 *
59 * @return array
60 */
61 public function update($name): array
62 {
63 return $this->client->request('PATCH', "folders/{$this->id}", compact('name'));
64 }
65
66 /**
67 * Delete a folder.
68 *
69 * @param int|array $id
70 *
71 * @return array
72 */
73 public function delete(): array
74 {
75 return $this->client->request('DELETE', "folders/{$this->id}");
76 }
77
78 /**
79 * Archive a folder.
80 *
81 * @return array
82 */
83 public function archive(): array
84 {
85 return $this->client->request('POST', "folders/{$this->id}/archive");
86 }
87
88 /**
89 * Unarchive a folder.
90 *
91 * @return array
92 */
93 public function unarchive(): array
94 {
95 return $this->client->request('POST', "folders/{$this->id}/unarchive");
96 }
97
98 /**
99 * Duplicate a folder.
100 *
101 * @return array
102 */
103 public function duplicate(): array
104 {
105 return $this->client->request('POST', "folders/{$this->id}/duplicate");
106 }
107}