-
Notifications
You must be signed in to change notification settings - Fork 0
Add missing endpoints #51
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
Open
IgorDobryn
wants to merge
6
commits into
main
Choose a base branch
from
MT-21864-add-missing-endpoints
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90323ab
Cover Get contact endpoint
IgorDobryn 58b48a3
Cover API token endpoints
IgorDobryn f15224b
Cover sub account endpoints
IgorDobryn 254252b
Cover webhook endpoints
IgorDobryn 52b2ac2
Add examples for recently added endpoints
IgorDobryn 940bf3a
Bring back removed env vars
IgorDobryn 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
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 |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| export GPG_TTY=$(tty) | ||
| export JAVA_TOOL_OPTIONS='-Duser.language=en -Duser.country=US' | ||
| export MAILTRAP_ACCOUNT_ID="op://Mailtrap Dev/Mailtrap SDK Dev API Key/account_id" | ||
| export MAILTRAP_ORGANIZATION_ID="op://Mailtrap Dev/Mailtrap SDK Dev API Key/organization_id" | ||
| export MAILTRAP_API_KEY="op://Mailtrap Dev/Mailtrap SDK Dev API Key/account_api_token" | ||
| export MAILTRAP_ORGANIZATION_API_KEY="op://Mailtrap Dev/Mailtrap SDK Dev API Key/organization_api_token" | ||
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 |
|---|---|---|
|
|
@@ -36,3 +36,4 @@ build/ | |
|
|
||
| ### Mac OS ### | ||
| .DS_Store | ||
| .idea/ | ||
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
48 changes: 48 additions & 0 deletions
48
examples/java/io/mailtrap/examples/general/ApiTokensExample.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,48 @@ | ||
| package io.mailtrap.examples.general; | ||
|
|
||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.AccessLevel; | ||
| import io.mailtrap.model.ResourceType; | ||
| import io.mailtrap.model.request.apitokens.ApiTokenResource; | ||
| import io.mailtrap.model.request.apitokens.CreateApiTokenRequest; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ApiTokensExample { | ||
|
|
||
| private static final String TOKEN = "<YOUR MAILTRAP TOKEN>"; | ||
| private static final long ACCOUNT_ID = 1L; | ||
|
|
||
| public static void main(String[] args) { | ||
| final var config = new MailtrapConfig.Builder() | ||
| .token(TOKEN) | ||
| .build(); | ||
|
|
||
| final var client = MailtrapClientFactory.createMailtrapClient(config); | ||
|
|
||
| // The full token value is returned only on creation — store it securely. | ||
| final var createRequest = new CreateApiTokenRequest( | ||
| "My token", | ||
| List.of(new ApiTokenResource(ResourceType.ACCOUNT, ACCOUNT_ID, AccessLevel.VIEWER))); | ||
|
|
||
| final var createdToken = client.generalApi().apiTokens() | ||
| .createApiToken(ACCOUNT_ID, createRequest); | ||
| System.out.println(createdToken); | ||
|
|
||
| final var tokenId = createdToken.getId(); | ||
|
|
||
| final var allTokens = client.generalApi().apiTokens().getAllApiTokens(ACCOUNT_ID); | ||
| System.out.println(allTokens); | ||
|
|
||
| final var token = client.generalApi().apiTokens().getApiToken(ACCOUNT_ID, tokenId); | ||
| System.out.println(token); | ||
|
|
||
| // Reset expires the existing token and returns a new one with the same permissions. | ||
| // The new token value is only returned here. | ||
| final var resetToken = client.generalApi().apiTokens().resetApiToken(ACCOUNT_ID, tokenId); | ||
| System.out.println(resetToken); | ||
|
|
||
| client.generalApi().apiTokens().deleteApiToken(ACCOUNT_ID, resetToken.getId()); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
examples/java/io/mailtrap/examples/organizations/SubAccountsExample.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,30 @@ | ||
| package io.mailtrap.examples.organizations; | ||
|
|
||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.request.subaccounts.CreateSubAccountRequest; | ||
| import io.mailtrap.model.request.subaccounts.SubAccountInput; | ||
|
|
||
| public class SubAccountsExample { | ||
|
|
||
| private static final String TOKEN = "<YOUR MAILTRAP TOKEN>"; | ||
| private static final long ORGANIZATION_ID = 1L; | ||
| private static final String SUB_ACCOUNT_NAME = "Acme Marketing"; | ||
|
|
||
| public static void main(String[] args) { | ||
| final var config = new MailtrapConfig.Builder() | ||
| .token(TOKEN) | ||
| .build(); | ||
|
|
||
| final var client = MailtrapClientFactory.createMailtrapClient(config); | ||
|
|
||
| // Requires sub account management permissions for the organization. | ||
| final var allSubAccounts = client.organizationsApi().subAccounts().getSubAccounts(ORGANIZATION_ID); | ||
| System.out.println(allSubAccounts); | ||
|
|
||
| final var createRequest = new CreateSubAccountRequest(new SubAccountInput(SUB_ACCOUNT_NAME)); | ||
| final var createdSubAccount = client.organizationsApi().subAccounts() | ||
| .createSubAccount(ORGANIZATION_ID, createRequest); | ||
| System.out.println(createdSubAccount); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
examples/java/io/mailtrap/examples/webhooks/WebhooksExample.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,71 @@ | ||
| package io.mailtrap.examples.webhooks; | ||
|
|
||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.factory.MailtrapClientFactory; | ||
| import io.mailtrap.model.SendingStream; | ||
| import io.mailtrap.model.WebhookEventType; | ||
| import io.mailtrap.model.WebhookPayloadFormat; | ||
| import io.mailtrap.model.WebhookType; | ||
| import io.mailtrap.model.request.webhooks.CreateWebhookRequest; | ||
| import io.mailtrap.model.request.webhooks.UpdateWebhookRequest; | ||
| import io.mailtrap.model.request.webhooks.WebhookInput; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class WebhooksExample { | ||
|
|
||
| private static final String TOKEN = "<YOUR MAILTRAP TOKEN>"; | ||
| private static final long ACCOUNT_ID = 1L; | ||
| private static final String WEBHOOK_URL = "https://example.com/webhooks/mailtrap"; | ||
| private static final String UPDATED_WEBHOOK_URL = "https://example.com/webhooks/mailtrap/v2"; | ||
|
|
||
| public static void main(String[] args) { | ||
| final var config = new MailtrapConfig.Builder() | ||
| .token(TOKEN) | ||
| .build(); | ||
|
|
||
| final var client = MailtrapClientFactory.createMailtrapClient(config); | ||
|
|
||
| final var createRequest = new CreateWebhookRequest( | ||
| WebhookInput.builder() | ||
| .url(WEBHOOK_URL) | ||
| .webhookType(WebhookType.EMAIL_SENDING) | ||
| .active(true) | ||
| .payloadFormat(WebhookPayloadFormat.JSON) | ||
| .sendingStream(SendingStream.TRANSACTIONAL) | ||
| .eventTypes(List.of( | ||
| WebhookEventType.DELIVERY, | ||
| WebhookEventType.BOUNCE, | ||
| WebhookEventType.OPEN, | ||
| WebhookEventType.CLICK, | ||
| WebhookEventType.UNSUBSCRIBE)) | ||
| .build()); | ||
|
|
||
| // `signing_secret` is only returned on creation — store it securely. | ||
| final var createResponse = client.generalApi().webhooks() | ||
| .createWebhook(ACCOUNT_ID, createRequest); | ||
| System.out.println(createResponse); | ||
|
|
||
| final var webhookId = createResponse.getData().getId(); | ||
|
|
||
| final var allWebhooks = client.generalApi().webhooks().getAllWebhooks(ACCOUNT_ID); | ||
| System.out.println(allWebhooks); | ||
|
|
||
| final var webhook = client.generalApi().webhooks().getWebhook(ACCOUNT_ID, webhookId); | ||
| System.out.println(webhook); | ||
|
|
||
| final var updateRequest = new UpdateWebhookRequest( | ||
| WebhookInput.builder() | ||
| .url(UPDATED_WEBHOOK_URL) | ||
| .active(false) | ||
| .eventTypes(List.of(WebhookEventType.DELIVERY, WebhookEventType.BOUNCE)) | ||
| .build()); | ||
|
|
||
| final var updateResponse = client.generalApi().webhooks() | ||
| .updateWebhook(ACCOUNT_ID, webhookId, updateRequest); | ||
| System.out.println(updateResponse); | ||
|
|
||
| final var deleteResponse = client.generalApi().webhooks().deleteWebhook(ACCOUNT_ID, webhookId); | ||
| System.out.println(deleteResponse); | ||
| } | ||
| } |
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,56 @@ | ||
| package io.mailtrap.api.apitokens; | ||
|
|
||
| import io.mailtrap.model.request.apitokens.CreateApiTokenRequest; | ||
| import io.mailtrap.model.response.apitokens.ApiToken; | ||
| import io.mailtrap.model.response.apitokens.ApiTokenWithToken; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ApiTokens { | ||
|
|
||
| /** | ||
| * List all API tokens visible to the current API token. | ||
| * | ||
| * @param accountId unique account ID | ||
| * @return list of API tokens | ||
| */ | ||
| List<ApiToken> getAllApiTokens(long accountId); | ||
|
|
||
| /** | ||
| * Create a new API token for the account with the given name and resource permissions. | ||
| * The full token value is returned only on creation. | ||
| * | ||
| * @param accountId unique account ID | ||
| * @param request token name and resource permissions | ||
| * @return created token, including the full token value | ||
| */ | ||
| ApiTokenWithToken createApiToken(long accountId, CreateApiTokenRequest request); | ||
|
|
||
| /** | ||
| * Get a single API token by id. | ||
| * | ||
| * @param accountId unique account ID | ||
| * @param id API token ID | ||
| * @return API token | ||
| */ | ||
| ApiToken getApiToken(long accountId, long id); | ||
|
|
||
| /** | ||
| * Permanently delete an API token. | ||
| * | ||
| * @param accountId unique account ID | ||
| * @param id API token ID | ||
| */ | ||
| void deleteApiToken(long accountId, long id); | ||
|
|
||
| /** | ||
| * Reset an API token. Expires the requested token and creates a new one with the same | ||
| * permissions; the new token value is returned only once. | ||
| * | ||
| * @param accountId unique account ID | ||
| * @param id API token ID | ||
| * @return new token, including the full token value | ||
| */ | ||
| ApiTokenWithToken resetApiToken(long accountId, long id); | ||
|
|
||
| } |
67 changes: 67 additions & 0 deletions
67
src/main/java/io/mailtrap/api/apitokens/ApiTokensImpl.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,67 @@ | ||
| package io.mailtrap.api.apitokens; | ||
|
|
||
| import io.mailtrap.Constants; | ||
| import io.mailtrap.api.apiresource.ApiResource; | ||
| import io.mailtrap.config.MailtrapConfig; | ||
| import io.mailtrap.http.RequestData; | ||
| import io.mailtrap.model.AbstractModel; | ||
| import io.mailtrap.model.request.apitokens.CreateApiTokenRequest; | ||
| import io.mailtrap.model.response.apitokens.ApiToken; | ||
| import io.mailtrap.model.response.apitokens.ApiTokenWithToken; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ApiTokensImpl extends ApiResource implements ApiTokens { | ||
|
|
||
| public ApiTokensImpl(final MailtrapConfig config) { | ||
| super(config); | ||
| this.apiHost = Constants.GENERAL_HOST; | ||
| } | ||
|
|
||
| @Override | ||
| public List<ApiToken> getAllApiTokens(final long accountId) { | ||
| return httpClient.getList( | ||
| String.format(apiHost + "/api/accounts/%d/api_tokens", accountId), | ||
| new RequestData(), | ||
| ApiToken.class | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public ApiTokenWithToken createApiToken(final long accountId, final CreateApiTokenRequest request) { | ||
| return httpClient.post( | ||
| String.format(apiHost + "/api/accounts/%d/api_tokens", accountId), | ||
| request, | ||
| new RequestData(), | ||
| ApiTokenWithToken.class | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public ApiToken getApiToken(final long accountId, final long id) { | ||
| return httpClient.get( | ||
| String.format(apiHost + "/api/accounts/%d/api_tokens/%d", accountId, id), | ||
| new RequestData(), | ||
| ApiToken.class | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteApiToken(final long accountId, final long id) { | ||
| httpClient.delete( | ||
| String.format(apiHost + "/api/accounts/%d/api_tokens/%d", accountId, id), | ||
| new RequestData(), | ||
| Void.class | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public ApiTokenWithToken resetApiToken(final long accountId, final long id) { | ||
| return httpClient.post( | ||
| String.format(apiHost + "/api/accounts/%d/api_tokens/%d/reset", accountId, id), | ||
| (AbstractModel) null, | ||
| new RequestData(), | ||
| ApiTokenWithToken.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
29 changes: 29 additions & 0 deletions
29
src/main/java/io/mailtrap/api/subaccounts/SubAccounts.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.subaccounts; | ||
|
|
||
| import io.mailtrap.model.request.subaccounts.CreateSubAccountRequest; | ||
| import io.mailtrap.model.response.subaccounts.SubAccount; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface SubAccounts { | ||
|
|
||
| /** | ||
| * Get a list of sub accounts for the specified organization. | ||
| * Requires sub account management permissions for the organization. | ||
| * | ||
| * @param organizationId unique organization ID | ||
| * @return list of sub accounts | ||
| */ | ||
| List<SubAccount> getSubAccounts(long organizationId); | ||
|
|
||
| /** | ||
| * Create a new sub account under the specified organization. | ||
| * Requires sub account management permissions for the organization. | ||
| * | ||
| * @param organizationId unique organization ID | ||
| * @param request sub account data | ||
| * @return created sub account | ||
| */ | ||
| SubAccount createSubAccount(long organizationId, CreateSubAccountRequest request); | ||
|
|
||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the highlevel idea is to have shared configuration across all SDK, load config into env and run examples. Basically, I already have something like that but with custom scripts. Next step would be to figure out how to run examples and that could be good integration test