|
| 1 | +package io.mailtrap.api.webhooks; |
| 2 | + |
| 3 | +import io.mailtrap.Constants; |
| 4 | +import io.mailtrap.api.apiresource.ApiResource; |
| 5 | +import io.mailtrap.config.MailtrapConfig; |
| 6 | +import io.mailtrap.http.RequestData; |
| 7 | +import io.mailtrap.model.request.webhooks.CreateWebhookRequest; |
| 8 | +import io.mailtrap.model.request.webhooks.UpdateWebhookRequest; |
| 9 | +import io.mailtrap.model.response.webhooks.CreateWebhookResponse; |
| 10 | +import io.mailtrap.model.response.webhooks.ListWebhooksResponse; |
| 11 | +import io.mailtrap.model.response.webhooks.WebhookResponse; |
| 12 | + |
| 13 | +public class WebhooksImpl extends ApiResource implements Webhooks { |
| 14 | + |
| 15 | + public WebhooksImpl(final MailtrapConfig config) { |
| 16 | + super(config); |
| 17 | + this.apiHost = Constants.GENERAL_HOST; |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public CreateWebhookResponse createWebhook(final long accountId, final CreateWebhookRequest request) { |
| 22 | + return httpClient.post( |
| 23 | + String.format(apiHost + "/api/accounts/%d/webhooks", accountId), |
| 24 | + request, |
| 25 | + new RequestData(), |
| 26 | + CreateWebhookResponse.class |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public ListWebhooksResponse getAllWebhooks(final long accountId) { |
| 32 | + return httpClient.get( |
| 33 | + String.format(apiHost + "/api/accounts/%d/webhooks", accountId), |
| 34 | + new RequestData(), |
| 35 | + ListWebhooksResponse.class |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public WebhookResponse getWebhook(final long accountId, final long webhookId) { |
| 41 | + return httpClient.get( |
| 42 | + String.format(apiHost + "/api/accounts/%d/webhooks/%d", accountId, webhookId), |
| 43 | + new RequestData(), |
| 44 | + WebhookResponse.class |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public WebhookResponse updateWebhook(final long accountId, final long webhookId, final UpdateWebhookRequest request) { |
| 50 | + return httpClient.patch( |
| 51 | + String.format(apiHost + "/api/accounts/%d/webhooks/%d", accountId, webhookId), |
| 52 | + request, |
| 53 | + new RequestData(), |
| 54 | + WebhookResponse.class |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public WebhookResponse deleteWebhook(final long accountId, final long webhookId) { |
| 60 | + return httpClient.delete( |
| 61 | + String.format(apiHost + "/api/accounts/%d/webhooks/%d", accountId, webhookId), |
| 62 | + new RequestData(), |
| 63 | + WebhookResponse.class |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
0 commit comments