ReviewOS

also looking at this

meemalabs/meema-client-php

Exceptions

#27
Merged glennmichael123 wants to merge exceptions into main
5 files +168 -14
src/Models/Media.phpmodified+63-8
Changes to src/Models/Media.php
@@ -3,6 +3,7 @@
33namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Exceptions\InvalidFormatException;
67use Meema\MeemaApi\Response\Response;
78
89class Media
@@ -46,6 +47,8 @@ class Media
4647 * Get specific media.
4748 *
4849 * @return array
50 *
51 * @throws InvalidFormatException
4952 */
5053 public function get($id = null)
5154 {
@@ -57,9 +60,13 @@ class Media
5760 return $this->all();
5861 }
5962
63 if (! is_int($id)) {
64 throw new InvalidFormatException();
65 }
66
6067 $ids = is_array($id) ? $id : func_get_args();
6168
62 return $this->client->request('GET', 'media/show', ['media_ids' => $ids]);
69 return $this->client->request('GET', 'media', ['media_ids' => $ids]);
6370 }
6471
6572 /**
@@ -68,9 +75,15 @@ class Media
6875 * @param int $id
6976 *
7077 * @return array
78 *
79 * @throws InvalidFormatException
7180 */
7281 public function find($id)
7382 {
83 if (! is_int($id)) {
84 throw new InvalidFormatException();
85 }
86
7487 $response = $this->client->request('GET', "media/${id}");
7588
7689 return new Response($this, $response);
@@ -97,9 +110,15 @@ class Media
97110 * @param string $name
98111 *
99112 * @return array
113 *
114 * @throws InvalidFormatException
100115 */
101 public function update($id, $name): array
116 public function update($id, $name)
102117 {
118 if (! is_int($id)) {
119 throw new InvalidFormatException();
120 }
121
103122 $name = is_array($name) ? $name : compact('name');
104123
105124 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
@@ -111,9 +130,15 @@ class Media
111130 * @param int $id
112131 *
113132 * @return null
133 *
134 * @throws InvalidFormatException
114135 */
115 public function delete($id = null)
136 public function delete($id)
116137 {
138 if (! is_int($id)) {
139 throw new InvalidFormatException();
140 }
141
117142 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
118143 }
119144
@@ -135,9 +160,15 @@ class Media
135160 * @param int $id
136161 *
137162 * @return array
163 *
164 * @throws InvalidFormatException
138165 */
139 public function archive($id = null): array
166 public function archive($id)
140167 {
168 if (! is_int($id)) {
169 throw new InvalidFormatException();
170 }
171
141172 return $this->client->request('POST', "media/{$id}/archive");
142173 }
143174
@@ -147,9 +178,15 @@ class Media
147178 * @param int $id
148179 *
149180 * @return array
181 *
182 * @throws InvalidFormatException
150183 */
151 public function unarchive($id): array
184 public function unarchive($id)
152185 {
186 if (! is_int($id)) {
187 throw new InvalidFormatException();
188 }
189
153190 return $this->client->request('POST', "media/{$id}/unarchive");
154191 }
155192
@@ -159,9 +196,15 @@ class Media
159196 * @param int $id
160197 *
161198 * @return array
199 *
200 * @throws InvalidFormatException
162201 */
163 public function makePrivate($id): array
202 public function makePrivate($id)
164203 {
204 if (! is_int($id)) {
205 throw new InvalidFormatException();
206 }
207
165208 return $this->client->request('PATCH', "media/{$id}/make-private");
166209 }
167210
@@ -171,9 +214,15 @@ class Media
171214 * @param int $id
172215 *
173216 * @return array
217 *
218 * @throws InvalidFormatException
174219 */
175 public function makePublic($id): array
220 public function makePublic($id)
176221 {
222 if (! is_int($id)) {
223 throw new InvalidFormatException();
224 }
225
177226 return $this->client->request('PATCH', "media/{$id}/make-public");
178227 }
179228
@@ -183,9 +232,15 @@ class Media
183232 * @param int $id
184233 *
185234 * @return array
235 *
236 * @throws InvalidFormatException
186237 */
187 public function duplicate($id): array
238 public function duplicate($id)
188239 {
240 if (! is_int($id)) {
241 throw new InvalidFormatException();
242 }
243
189244 return $this->client->request('POST', "media/{$id}/duplicate");
190245 }
191246