also looking at this
Favorites model
#11
3 files
+131
-0
| @@ -4,6 +4,7 @@ namespace Meema\MeemaApi; | ||
| 4 | 4 | |
| 5 | 5 | use Dotenv\Dotenv; |
| 6 | 6 | use GuzzleHttp\Client as GuzzleClient; |
| 7 | use Meema\MeemaApi\Models\Favorite; | |
| 7 | 8 | use Meema\MeemaApi\Models\Folder; |
| 8 | 9 | use Meema\MeemaApi\Models\Media; |
| 9 | 10 | use Meema\MeemaApi\Models\Tag; |
| @@ -116,4 +117,14 @@ class Client | ||
| 116 | 117 | { |
| 117 | 118 | return new Tag($this); |
| 118 | 119 | } |
| 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 | } | |
| 119 | 130 | } |
| @@ -0,0 +1,108 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | namespace Meema\MeemaApi\Models; | |
| 4 | ||
| 5 | use Meema\MeemaApi\Client; | |
| 6 | use Meema\MeemaApi\Response\Response; | |
| 7 | ||
| 8 | class 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 | } | |