|
| 1 | +package io.mailtrap.api.emailcampaigns; |
| 2 | + |
| 3 | +import io.mailtrap.model.request.emailcampaigns.CreateEmailCampaign; |
| 4 | +import io.mailtrap.model.request.emailcampaigns.ScheduleEmailCampaignRequest; |
| 5 | +import io.mailtrap.model.request.emailcampaigns.UpdateEmailCampaign; |
| 6 | +import io.mailtrap.model.response.emailcampaigns.EmailCampaignListResponse; |
| 7 | +import io.mailtrap.model.response.emailcampaigns.EmailCampaignResponse; |
| 8 | +import io.mailtrap.model.response.emailcampaigns.EmailCampaignStatsResponse; |
| 9 | + |
| 10 | +/** |
| 11 | + * Email Campaigns API. Manage email marketing campaigns and retrieve their performance |
| 12 | + * statistics. |
| 13 | + * |
| 14 | + * <p>The account is resolved from the API token, so these endpoints are token-scoped and the |
| 15 | + * path is not account-scoped. |
| 16 | + */ |
| 17 | +public interface EmailCampaigns { |
| 18 | + |
| 19 | + /** |
| 20 | + * List the account's email campaigns, newest first. |
| 21 | + * |
| 22 | + * @param perPage number of campaigns per page (max 100, default 50); {@code null} to omit |
| 23 | + * @param search filter campaigns by name; {@code null} to omit |
| 24 | + * @param token page number to retrieve (page-token pagination, default 1); |
| 25 | + * {@code null} to omit |
| 26 | + * @return a page of campaigns and the pagination metadata |
| 27 | + */ |
| 28 | + EmailCampaignListResponse getEmailCampaigns(Integer perPage, String search, Integer token); |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a new email campaign in the {@code draft} state. |
| 32 | + * |
| 33 | + * @param request the campaign attributes ({@code name}, {@code mailsendDomainId}, |
| 34 | + * {@code fromLocalPart} and a template {@code subject} are required) |
| 35 | + * @return the created email campaign |
| 36 | + */ |
| 37 | + EmailCampaignResponse createEmailCampaign(CreateEmailCampaign request); |
| 38 | + |
| 39 | + /** |
| 40 | + * Get a single email campaign by ID. |
| 41 | + * |
| 42 | + * @param emailCampaignId unique email campaign ID |
| 43 | + * @return the email campaign |
| 44 | + */ |
| 45 | + EmailCampaignResponse getEmailCampaign(long emailCampaignId); |
| 46 | + |
| 47 | + /** |
| 48 | + * Update an existing {@code draft} email campaign. Only the provided attributes are |
| 49 | + * changed. |
| 50 | + * |
| 51 | + * @param emailCampaignId unique email campaign ID |
| 52 | + * @param request the attributes to update |
| 53 | + * @return the updated email campaign |
| 54 | + */ |
| 55 | + EmailCampaignResponse updateEmailCampaign(long emailCampaignId, UpdateEmailCampaign request); |
| 56 | + |
| 57 | + /** |
| 58 | + * Delete an email campaign. The campaign must not be in a sending state. |
| 59 | + * |
| 60 | + * @param emailCampaignId unique email campaign ID |
| 61 | + */ |
| 62 | + void deleteEmailCampaign(long emailCampaignId); |
| 63 | + |
| 64 | + /** |
| 65 | + * Start sending a {@code draft} campaign immediately. |
| 66 | + * |
| 67 | + * @param emailCampaignId unique email campaign ID |
| 68 | + * @return the started email campaign |
| 69 | + */ |
| 70 | + EmailCampaignResponse startEmailCampaign(long emailCampaignId); |
| 71 | + |
| 72 | + /** |
| 73 | + * Schedule a {@code draft} campaign to start sending at a future time. The scheduled time |
| 74 | + * is reported back in {@code currentStateMetadata.scheduledAt}. |
| 75 | + * |
| 76 | + * @param emailCampaignId unique email campaign ID |
| 77 | + * @param request when to start sending the campaign |
| 78 | + * @return the scheduled email campaign |
| 79 | + */ |
| 80 | + EmailCampaignResponse scheduleEmailCampaign(long emailCampaignId, ScheduleEmailCampaignRequest request); |
| 81 | + |
| 82 | + /** |
| 83 | + * Cancel a {@code scheduled} campaign, returning it to the {@code draft} state. |
| 84 | + * |
| 85 | + * @param emailCampaignId unique email campaign ID |
| 86 | + * @return the cancelled email campaign |
| 87 | + */ |
| 88 | + EmailCampaignResponse cancelEmailCampaign(long emailCampaignId); |
| 89 | + |
| 90 | + /** |
| 91 | + * Terminate a campaign that is currently sending ({@code started}, {@code queued} or |
| 92 | + * {@code paused}), aborting the in-flight send. |
| 93 | + * |
| 94 | + * @param emailCampaignId unique email campaign ID |
| 95 | + * @return the terminated email campaign |
| 96 | + */ |
| 97 | + EmailCampaignResponse terminateEmailCampaign(long emailCampaignId); |
| 98 | + |
| 99 | + /** |
| 100 | + * Reset a {@code scheduled} campaign back to the {@code draft} state. |
| 101 | + * |
| 102 | + * @param emailCampaignId unique email campaign ID |
| 103 | + * @return the reset email campaign |
| 104 | + */ |
| 105 | + EmailCampaignResponse resetEmailCampaign(long emailCampaignId); |
| 106 | + |
| 107 | + /** |
| 108 | + * Get aggregated performance statistics for an email campaign over the whole period since |
| 109 | + * the campaign was last started. If the campaign has never been started, all counts and |
| 110 | + * rates are returned as {@code 0}. |
| 111 | + * |
| 112 | + * @param emailCampaignId unique email campaign ID |
| 113 | + * @return aggregated campaign statistics |
| 114 | + */ |
| 115 | + EmailCampaignStatsResponse getEmailCampaignStats(long emailCampaignId); |
| 116 | + |
| 117 | + /** |
| 118 | + * Get aggregated performance statistics for an email campaign over a narrowed aggregation |
| 119 | + * window. |
| 120 | + * |
| 121 | + * @param emailCampaignId unique email campaign ID |
| 122 | + * @param startDate start of the aggregation window (inclusive), in |
| 123 | + * {@code YYYY-MM-DD} format; {@code null} to omit |
| 124 | + * @param endDate end of the aggregation window (inclusive), in {@code YYYY-MM-DD} |
| 125 | + * format; {@code null} to omit |
| 126 | + * @return aggregated campaign statistics |
| 127 | + */ |
| 128 | + EmailCampaignStatsResponse getEmailCampaignStats(long emailCampaignId, String startDate, String endDate); |
| 129 | + |
| 130 | +} |
0 commit comments