-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented ContactEvents and missing ContactLists APIs #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
examples/java/io/mailtrap/examples/contactevents/ContactEventsExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package io.mailtrap.examples.contactevents; | ||
|
|
||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.request.contactevents.CreateContactEventRequest; | ||
| import io.mailtrap.model.response.contactevents.ContactEventResponse; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class ContactEventsExample { | ||
|
|
||
| private static final String TOKEN = "<YOUR MAILTRAP TOKEN>"; | ||
| private static final long ACCOUNT_ID = 1L; | ||
| private static final String CONTACT_EVENT_ID = "b691272b-3e50-4813-997b-c7c9b317dcb2"; | ||
|
|
||
| public static void main(String[] args) { | ||
| final var config = new MailtrapConfig.Builder() | ||
| .token(TOKEN) | ||
| .build(); | ||
|
|
||
| final var client = MailtrapClientFactory.createMailtrapClient(config); | ||
|
|
||
| final CreateContactEventRequest request = new CreateContactEventRequest("UserLogin", Map.of( | ||
| "user_id", 11, | ||
| "user_name", "Dillan Doe", | ||
| "is_active", true | ||
| )); | ||
|
|
||
| final ContactEventResponse contactEvent = client.contactsApi().contactEvents().createContactEvent(ACCOUNT_ID, CONTACT_EVENT_ID, request); | ||
| System.out.println(contactEvent); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/io/mailtrap/api/contactevents/ContactEvents.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package io.mailtrap.api.contactevents; | ||
|
|
||
| import io.mailtrap.model.request.contactevents.CreateContactEventRequest; | ||
| import io.mailtrap.model.response.contactevents.ContactEventResponse; | ||
|
|
||
| public interface ContactEvents { | ||
|
|
||
| /** | ||
| * Submit custom event for contact | ||
| * | ||
| * @param accountId unique account ID | ||
| * @param contactIdentifier Contact UUID or Email | ||
| * @param request body | ||
| * @return created contact event | ||
| */ | ||
| ContactEventResponse createContactEvent(long accountId, String contactIdentifier, CreateContactEventRequest request); | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/mailtrap/api/contactevents/ContactEventsImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package io.mailtrap.api.contactevents; | ||
|
|
||
| import io.mailtrap.Constants; | ||
| import io.mailtrap.api.apiresource.ApiResource; | ||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.http.RequestData; | ||
| import io.mailtrap.model.request.contactevents.CreateContactEventRequest; | ||
| import io.mailtrap.model.response.contactevents.ContactEventResponse; | ||
|
|
||
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| public class ContactEventsImpl extends ApiResource implements ContactEvents { | ||
|
|
||
| public ContactEventsImpl(final MailtrapConfig config) { | ||
| super(config); | ||
| this.apiHost = Constants.GENERAL_HOST; | ||
| } | ||
|
|
||
| @Override | ||
| public ContactEventResponse createContactEvent(final long accountId, final String contactIdentifier, final CreateContactEventRequest request) { | ||
| return httpClient.post( | ||
| String.format(apiHost + "/api/accounts/%d/contacts/%s/events", accountId, URLEncoder.encode(contactIdentifier, StandardCharsets.UTF_8)), | ||
| request, | ||
| new RequestData(), | ||
| ContactEventResponse.class | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/io/mailtrap/model/request/contactevents/CreateContactEventRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package io.mailtrap.model.request.contactevents; | ||
|
|
||
| import io.mailtrap.model.AbstractModel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class CreateContactEventRequest extends AbstractModel { | ||
| private String name; | ||
| private Map<String, Object> params; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/mailtrap/model/request/contactlists/CreateUpdateContactListRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.mailtrap.model.request.contactlists; | ||
|
|
||
| import io.mailtrap.model.AbstractModel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class CreateUpdateContactListRequest extends AbstractModel { | ||
|
vitalii-t marked this conversation as resolved.
Outdated
|
||
| private String name; | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
src/main/java/io/mailtrap/model/response/contactevents/ContactEventResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package io.mailtrap.model.response.contactevents; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| public class ContactEventResponse { | ||
|
|
||
| @JsonProperty("contact_id") | ||
| private String contactId; | ||
|
|
||
| @JsonProperty("contact_email") | ||
| private String contactEmail; | ||
|
|
||
| private String name; | ||
|
|
||
| private Map<String, Object> params; | ||
|
|
||
| } |
53 changes: 53 additions & 0 deletions
53
src/test/java/io/mailtrap/api/contactevents/ContactEventsImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package io.mailtrap.api.contactevents; | ||
|
|
||
| import io.mailtrap.Constants; | ||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.request.contactevents.CreateContactEventRequest; | ||
| import io.mailtrap.model.response.contactevents.ContactEventResponse; | ||
| import io.mailtrap.testutils.BaseTest; | ||
| import io.mailtrap.testutils.DataMock; | ||
| import io.mailtrap.testutils.TestHttpClient; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| class ContactEventsImplTest extends BaseTest { | ||
| private ContactEvents api; | ||
|
|
||
| @BeforeEach | ||
| public void init() { | ||
| final TestHttpClient httpClient = new TestHttpClient(List.of( | ||
| DataMock.build(Constants.GENERAL_HOST + "/api/accounts/" + accountId + "/contacts/" + contactEventIdEncoded + "/events", | ||
| "POST", "api/contactevents/createRequest.json", "api/contactevents/contactEvent.json") | ||
| )); | ||
|
|
||
| final MailtrapConfig testConfig = new MailtrapConfig.Builder() | ||
| .httpClient(httpClient) | ||
| .token("dummy_token") | ||
| .build(); | ||
|
|
||
| api = MailtrapClientFactory.createMailtrapClient(testConfig).contactsApi().contactEvents(); | ||
| } | ||
|
|
||
| @Test | ||
| void test_createContactEvent() { | ||
| final CreateContactEventRequest request = new CreateContactEventRequest("UserLogin", Map.of( | ||
| "user_id", 11, | ||
| "user_name", "Dillan Doe", | ||
| "is_active", true | ||
| )); | ||
|
|
||
| final ContactEventResponse created = api.createContactEvent(accountId, contactEventId, request); | ||
|
|
||
| assertNotNull(created); | ||
| assertEquals(contactEventId, created.getContactId()); | ||
| assertEquals(3, created.getParams().size()); | ||
| assertEquals("Dillan Doe", created.getParams().get("user_name")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.