ReviewOS

also looking at this

meemalabs/meema-client-php

Favorites model

#11
Merged glennmichael123 wants to merge tags-model into main
3 files +131 -0
src/Client.phpmodified+11-0
Changes to src/Client.php
@@ -4,6 +4,7 @@ namespace Meema\MeemaApi;
44
55use Dotenv\Dotenv;
66use GuzzleHttp\Client as GuzzleClient;
7use Meema\MeemaApi\Models\Favorite;
78use Meema\MeemaApi\Models\Folder;
89use Meema\MeemaApi\Models\Media;
910use Meema\MeemaApi\Models\Tag;
@@ -116,4 +117,14 @@ class Client
116117 {
117118 return new Tag($this);
118119 }
120
121 /**
122 * Initialize the favorite model.
123 *
124 * @return Meema\MeemaApi\Models\Favorite
125 */
126 public function favorites(): Favorite
127 {
128 return new Favorite($this);
129 }
119130}
src/Models/Favorite.phpadded+108-0
Changes to src/Models/Favorite.php
@@ -0,0 +1,108 @@
1<?php
2
3namespace Meema\MeemaApi\Models;
4
5use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Response\Response;
7
8class Favorite
9{
10 /**
11 * @var Meema\MeemaApi\Client
12 */
13 protected $client;
14
15 /**
16 * @var int
17 */
18 protected $id;
19
20 /**
21 * Construct Favorite model.
22 *
23 * @param Meema\MeemaApi\Client $client
24 */
25 public function __construct(Client $client)
26 {
27 $this->client = $client;
28 }
29
30 /**
31 * List all favorites.
32 *
33 * @return array
34 */
35 public function all(): array
36 {
37 return $this->client->request('GET', 'favorites');
38 }
39
40 /**
41 * Get specific favorites.
42 *
43 * @param int $id
44 *
45 * @return array
46 */
47 public function get($id = null)
48 {
49 if (! $id) {
50 return $this->all();
51 }
52
53 $ids = is_array($id) ? $id : func_get_args();
54
55 return $this->client->request('GET', 'favorites', ['favorite_ids' => $ids]);
56 }
57
58 /**
59 * Get specific favorites.
60 *
61 * @param int $id
62 *
63 * @return array
64 */
65 public function find($id)
66 {
67 $response = $this->client->request('GET', "favorites/${id}");
68
69 return new Response($this, $response);
70 }
71
72 /**
73 * Create folder.
74 *
75 * @param string $name
76 *
77 * @return array
78 */
79 public function create($data)
80 {
81 return $this->client->request('POST', "favorites/{$this->client->getAccessKey()}", $data);
82 }
83
84 /**
85 * Update folder.
86 *
87 * @param string $name
88 * @param int $id
89 *
90 * @return array
91 */
92 public function update($id, $data): array
93 {
94 return $this->client->request('PATCH', "favorites/{$id}", $data);
95 }
96
97 /**
98 * Delete a folder.
99 *
100 * @param int $id
101 *
102 * @return null
103 */
104 public function delete($id)
105 {
106 return $this->client->request('DELETE', "favorites/{$id}");
107 }
108}
src/Response/Response.phpmodified+12-0
Changes to src/Response/Response.php
@@ -85,4 +85,16 @@ class Response
8585
8686 return $this->content;
8787 }
88
89 /**
90 * Get response content to array.
91 *
92 * @param mixed $key
93 *
94 * @return array
95 */
96 public function toArray()
97 {
98 return $this->getContent();
99 }
88100}