also looking at this
initialize progress
#1
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.
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | namespace Meema\MeemaApi; |
| 4 | 4 | |
| 5 | 5 | use GuzzleHttp\Client as GuzzleClient; |
| 6 | use Meema\MeemaApi\Models\Folder; | |
| 6 | 7 | |
| 7 | 8 | class Client |
| 8 | 9 | { |
| @@ -11,6 +12,12 @@ class Client | ||
| 11 | 12 | */ |
| 12 | 13 | protected $client; |
| 13 | 14 | |
| 15 | /** | |
| 16 | * @var Meema\MeemaApi\Models\Folder | |
| 17 | */ | |
| 18 | public $folders; | |
| 19 | ||
| 20 | ||
| 14 | 21 | /** |
| 15 | 22 | * @var string |
| 16 | 23 | */ |
| @@ -25,7 +32,7 @@ class Client | ||
| 25 | 32 | { |
| 26 | 33 | $this->accessKey = $accessKey; |
| 27 | 34 | $this->client = new GuzzleClient([ |
| 28 | 'base_uri' => 'http://127.0.0.1:8000/api/', | |
| 35 | 'base_uri' => 'http://meema-api.test/api/', | |
| 29 | 36 | ]); |
| 30 | 37 | } |
| 31 | 38 | |
| @@ -45,7 +52,9 @@ class Client | ||
| 45 | 52 | 'Content-Type' => 'application/json', |
| 46 | 53 | 'Authorization' => "Bearer {$this->accessKey}", |
| 47 | 54 | ], |
| 48 | ])->getBody()->getContents(); | |
| 55 | ]) | |
| 56 | ->getBody() | |
| 57 | ->getContents(); | |
| 49 | 58 | |
| 50 | 59 | return json_decode($content, true); |
| 51 | 60 | } |
| @@ -61,23 +70,22 @@ class Client | ||
| 61 | 70 | } |
| 62 | 71 | |
| 63 | 72 | /** |
| 64 | * List folders. | |
| 73 | * Get the access key | |
| 65 | 74 | * |
| 66 | * @return array | |
| 75 | * @return string | |
| 67 | 76 | */ |
| 68 | public function listFolders() | |
| 77 | public function getAccessKey(): string | |
| 69 | 78 | { |
| 70 | return $this->request('GET', 'folders'); | |
| 79 | return $this->accessKey; | |
| 71 | 80 | } |
| 72 | 81 | |
| 73 | 82 | /** |
| 74 | * Create folder. | |
| 83 | * Initialize the folder model | |
| 75 | 84 | * |
| 76 | * @param string $name | |
| 77 | * @return array | |
| 85 | * @return Meema\MeemaApi\Models\Folder | |
| 78 | 86 | */ |
| 79 | public function createFolder($name) | |
| 87 | public function folders($id = null): Folder | |
| 80 | 88 | { |
| 81 | return $this->request('POST', 'folders', compact('name')); | |
| 89 | return new Folder($this, $id); | |
| 82 | 90 | } |
| 83 | 91 | } |
| @@ -0,0 +1,107 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | namespace Meema\MeemaApi\Models; | |
| 4 | ||
| 5 | use Meema\MeemaApi\Client; | |
| 6 | ||
| 7 | class 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 | } | |