also looking at this
Favorites model
#11
3 files
+131
-0
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.
| @@ -4,12 +4,9 @@ namespace Meema\MeemaApi\Models; | ||
| 4 | 4 | |
| 5 | 5 | use Meema\MeemaApi\Client; |
| 6 | 6 | use Meema\MeemaApi\Response\Response; |
| 7 | use Meema\MeemaApi\Traits\SerializesResponse; | |
| 8 | 7 | |
| 9 | 8 | class Favorite |
| 10 | 9 | { |
| 11 | use SerializesResponse; | |
| 12 | ||
| 13 | 10 | /** |
| 14 | 11 | * @var Meema\MeemaApi\Client |
| 15 | 12 | */ |
| @@ -20,26 +17,14 @@ class Favorite | ||
| 20 | 17 | */ |
| 21 | 18 | protected $id; |
| 22 | 19 | |
| 23 | /** | |
| 24 | * @var int | |
| 25 | */ | |
| 26 | protected $favoriteId; | |
| 27 | ||
| 28 | /** | |
| 29 | * @var array | |
| 30 | */ | |
| 31 | protected $content; | |
| 32 | ||
| 33 | 20 | /** |
| 34 | 21 | * Construct Favorite model. |
| 35 | 22 | * |
| 36 | 23 | * @param Meema\MeemaApi\Client $client |
| 37 | 24 | */ |
| 38 | public function __construct(Client $client, $favoriteId = null) | |
| 25 | public function __construct(Client $client) | |
| 39 | 26 | { |
| 40 | 27 | $this->client = $client; |
| 41 | ||
| 42 | $this->favoriteId = $favoriteId; | |
| 43 | 28 | } |
| 44 | 29 | |
| 45 | 30 | /** |
| @@ -81,9 +66,6 @@ class Favorite | ||
| 81 | 66 | { |
| 82 | 67 | $response = $this->client->request('GET', "favorites/${id}"); |
| 83 | 68 | |
| 84 | $this->content = $response; | |
| 85 | $this->id = $response['data']['id']; | |
| 86 | ||
| 87 | 69 | return new Response($this, $response); |
| 88 | 70 | } |
| 89 | 71 | |
| @@ -107,10 +89,8 @@ class Favorite | ||
| 107 | 89 | * |
| 108 | 90 | * @return array |
| 109 | 91 | */ |
| 110 | public function update($data, $id = null): array | |
| 92 | public function update($id, $data): array | |
| 111 | 93 | { |
| 112 | $id = $this->id ?? $id; | |
| 113 | ||
| 114 | 94 | return $this->client->request('PATCH', "favorites/{$id}", $data); |
| 115 | 95 | } |
| 116 | 96 | |
| @@ -121,10 +101,8 @@ class Favorite | ||
| 121 | 101 | * |
| 122 | 102 | * @return null |
| 123 | 103 | */ |
| 124 | public function delete($id = null) | |
| 104 | public function delete($id) | |
| 125 | 105 | { |
| 126 | $id = $this->id ?? $id; | |
| 127 | ||
| 128 | 106 | return $this->client->request('DELETE', "favorites/{$id}"); |
| 129 | 107 | } |
| 130 | 108 | } |