@@ 190-206 (lines=17) @@ | ||
187 | * @throws ApiError |
|
188 | * @throws InvalidNewsletterList |
|
189 | */ |
|
190 | public function unsubscribe(string $email, string $listName = '') |
|
191 | { |
|
192 | $list = $this->lists->findByName($listName); |
|
193 | ||
194 | $body = [ |
|
195 | 'Email' => $email, |
|
196 | 'Action' => 'unsub', |
|
197 | ]; |
|
198 | ||
199 | $response = $this->client->post(Resources::$ContactslistManagecontact, ['id' => $list->getId(), 'body' => $body]); |
|
200 | ||
201 | if (! $response->success()) { |
|
202 | throw ApiError::responseError($response->getReasonPhrase(), 'mailjet', $response->getStatus()); |
|
203 | } |
|
204 | ||
205 | return $response; |
|
206 | } |
|
207 | ||
208 | ||
209 | /** |
|
@@ 216-236 (lines=21) @@ | ||
213 | * @throws ApiError |
|
214 | * @throws InvalidNewsletterList |
|
215 | */ |
|
216 | public function delete(string $email, string $listName = '') |
|
217 | { |
|
218 | $list = $this->lists->findByName($listName); |
|
219 | ||
220 | $body = [ |
|
221 | 'Email' => $email, |
|
222 | 'Action' => 'remove', |
|
223 | ]; |
|
224 | ||
225 | $response = $this->client->post(Resources::$ContactslistManagecontact, [ |
|
226 | 'id' => $list->getId(), |
|
227 | 'body' => $body |
|
228 | ] |
|
229 | ); |
|
230 | ||
231 | if (! $response->success()) { |
|
232 | throw ApiError::responseError($response->getReasonPhrase(), 'mailjet', $response->getStatus()); |
|
233 | } |
|
234 | ||
235 | return $response; |
|
236 | } |
|
237 | ||
238 | public function getApi() |
|
239 | { |