-
Notifications
You must be signed in to change notification settings - Fork 2
Add missing endpoints #240
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4d79da
Add api token endpoints
IgorDobryn 54ce25b
Add sub account endpoints
IgorDobryn 6e6b955
Add webhook endpoints
IgorDobryn 0fec15d
Remove .tool-versions
IgorDobryn 824f461
Add examples
IgorDobryn 0725079
Single sending stream
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 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
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
1 change: 1 addition & 0 deletions
1
examples/Mailtrap.Example.ApiTokens/Mailtrap.Example.ApiTokens.csproj
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 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" /> |
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,83 @@ | ||
| using Mailtrap; | ||
| using Mailtrap.Accounts; | ||
| using Mailtrap.ApiTokens; | ||
| using Mailtrap.ApiTokens.Models; | ||
| using Mailtrap.ApiTokens.Requests; | ||
| using Mailtrap.ApiTokens.Responses; | ||
| using Mailtrap.Core.Models; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
|
|
||
| HostApplicationBuilder hostBuilder = Host.CreateApplicationBuilder(args); | ||
|
|
||
| IConfigurationSection config = hostBuilder.Configuration.GetSection("Mailtrap"); | ||
|
|
||
| hostBuilder.Services.AddMailtrapClient(config); | ||
|
|
||
| using IHost host = hostBuilder.Build(); | ||
|
|
||
| ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>(); | ||
| IMailtrapClient mailtrapClient = host.Services.GetRequiredService<IMailtrapClient>(); | ||
|
|
||
| try | ||
| { | ||
| var accountId = 12345; | ||
| var inboxId = 67890; | ||
| IAccountResource accountResource = mailtrapClient.Account(accountId); | ||
|
|
||
| // Get resource for API tokens collection | ||
| IApiTokenCollectionResource apiTokensResource = accountResource.ApiTokens(); | ||
|
|
||
| // List all API tokens visible to the current API token | ||
| IList<ApiToken> apiTokens = await apiTokensResource.GetAll(); | ||
| logger.LogInformation("Found {Count} API token(s).", apiTokens.Count); | ||
|
|
||
| // Create a new API token scoped to a specific inbox with Viewer access | ||
| var createRequest = new CreateApiTokenRequest | ||
| { | ||
| Name = "Demo Viewer Token" | ||
| }; | ||
| createRequest.Resources.Add(new ApiTokenAccessRequest(ResourceType.Inbox, inboxId, AccessLevel.Viewer)); | ||
|
|
||
| CreateApiTokenResponse createdToken = await apiTokensResource.Create(createRequest); | ||
|
|
||
| // The full token value is only returned at creation time - store it securely | ||
| logger.LogInformation( | ||
| "Created API Token: Id={Id}, Name={Name}, Last4={Last4}", | ||
| createdToken.Id, | ||
| createdToken.Name, | ||
| createdToken.Last4Digits); | ||
| logger.LogInformation("Full token value (store securely, returned only once): {Token}", createdToken.Token); | ||
|
|
||
|
IgorDobryn marked this conversation as resolved.
|
||
| // Get resource for the specific API token | ||
| IApiTokenResource apiTokenResource = accountResource.ApiToken(createdToken.Id); | ||
|
|
||
| // Get details of the API token | ||
| ApiToken tokenDetails = await apiTokenResource.GetDetails(); | ||
| logger.LogInformation("Token details: Id={Id}, Name={Name}, CreatedBy={CreatedBy}", | ||
| tokenDetails.Id, | ||
| tokenDetails.Name, | ||
| tokenDetails.CreatedBy); | ||
|
|
||
| // Reset the API token - expires the current token and returns a new one with the same permissions | ||
| ApiTokenResetResponse resetResponse = await apiTokenResource.Reset(); | ||
| logger.LogInformation( | ||
| "Reset API Token: Id={Id}, NewLast4={Last4}", | ||
| resetResponse.Id, | ||
| resetResponse.Last4Digits); | ||
| logger.LogInformation("New token value (store securely, returned only once): {Token}", resetResponse.Token); | ||
|
|
||
| // Delete the API token | ||
| // The API token resource becomes invalid after deletion and should not be used anymore | ||
| await apiTokenResource.Delete(); | ||
| logger.LogInformation("API Token Deleted."); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError(ex, "An error occurred during API call."); | ||
| Environment.ExitCode = 1; | ||
| return; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
examples/Mailtrap.Example.ApiTokens/Properties/launchSettings.json
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,10 @@ | ||
| { | ||
| "profiles": { | ||
| "Project": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
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 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "System": "Warning", | ||
| "Microsoft": "Warning" | ||
| }, | ||
| "Debug": { | ||
| "LogLevel": { | ||
| "Default": "Debug" | ||
| } | ||
| } | ||
| }, | ||
| "Mailtrap": { | ||
| "ApiToken": "<API_KEY>" | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
examples/Mailtrap.Example.SubAccount/Mailtrap.Example.SubAccount.csproj
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 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" /> |
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,61 @@ | ||
| using Mailtrap; | ||
| using Mailtrap.Organizations; | ||
| using Mailtrap.Organizations.Models; | ||
| using Mailtrap.Organizations.Requests; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
|
|
||
| HostApplicationBuilder hostBuilder = Host.CreateApplicationBuilder(args); | ||
|
|
||
| IConfigurationSection config = hostBuilder.Configuration.GetSection("Mailtrap"); | ||
|
|
||
| hostBuilder.Services.AddMailtrapClient(config); | ||
|
|
||
| using IHost host = hostBuilder.Build(); | ||
|
|
||
| ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>(); | ||
|
|
||
| // Sub accounts live under /api/organizations/{organization_id}/... so they are | ||
| // accessed via the organization-scoped client, not IMailtrapClient. | ||
| IMailtrapOrganizationClient organizationClient = host.Services.GetRequiredService<IMailtrapOrganizationClient>(); | ||
|
|
||
| try | ||
| { | ||
| var organizationId = 12345; | ||
| IOrganizationResource organizationResource = organizationClient.Organization(organizationId); | ||
|
|
||
| // Get resource for sub accounts collection | ||
| IOrganizationSubAccountCollectionResource subAccountsResource = organizationResource.SubAccounts(); | ||
|
|
||
| // List sub accounts of the organization | ||
| IList<SubAccount> subAccounts = await subAccountsResource.GetAll(); | ||
| logger.LogInformation("Found {Count} sub account(s).", subAccounts.Count); | ||
|
|
||
| foreach (SubAccount subAccount in subAccounts) | ||
| { | ||
| logger.LogInformation("Sub Account: Id={Id}, Name={Name}", subAccount.Id, subAccount.Name); | ||
| } | ||
|
|
||
| // Create a new sub account under the organization | ||
| var createRequest = new CreateSubAccountRequest | ||
| { | ||
| Account = new SubAccountAttributes | ||
| { | ||
| Name = "Demo Sub Account" | ||
| } | ||
| }; | ||
| SubAccount createdSubAccount = await subAccountsResource.Create(createRequest); | ||
| logger.LogInformation( | ||
| "Created Sub Account: Id={Id}, Name={Name}", | ||
| createdSubAccount.Id, | ||
| createdSubAccount.Name); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError(ex, "An error occurred during API call."); | ||
| Environment.ExitCode = 1; | ||
| return; | ||
| } |
10 changes: 10 additions & 0 deletions
10
examples/Mailtrap.Example.SubAccount/Properties/launchSettings.json
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,10 @@ | ||
| { | ||
| "profiles": { | ||
| "Project": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
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 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "System": "Warning", | ||
| "Microsoft": "Warning" | ||
| }, | ||
| "Debug": { | ||
| "LogLevel": { | ||
| "Default": "Debug" | ||
| } | ||
| } | ||
| }, | ||
| "Mailtrap": { | ||
| "ApiToken": "<API_KEY>" | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
examples/Mailtrap.Example.Webhooks/Mailtrap.Example.Webhooks.csproj
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 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" /> |
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,92 @@ | ||
| using Mailtrap; | ||
| using Mailtrap.Accounts; | ||
| using Mailtrap.Webhooks; | ||
| using Mailtrap.Core.Models; | ||
| using Mailtrap.Webhooks.Models; | ||
| using Mailtrap.Webhooks.Requests; | ||
| using Mailtrap.Webhooks.Responses; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
|
|
||
| HostApplicationBuilder hostBuilder = Host.CreateApplicationBuilder(args); | ||
|
|
||
| IConfigurationSection config = hostBuilder.Configuration.GetSection("Mailtrap"); | ||
|
|
||
| hostBuilder.Services.AddMailtrapClient(config); | ||
|
|
||
| using IHost host = hostBuilder.Build(); | ||
|
|
||
| ILogger<Program> logger = host.Services.GetRequiredService<ILogger<Program>>(); | ||
| IMailtrapClient mailtrapClient = host.Services.GetRequiredService<IMailtrapClient>(); | ||
|
|
||
| try | ||
| { | ||
| var accountId = 12345; | ||
| IAccountResource accountResource = mailtrapClient.Account(accountId); | ||
|
|
||
| // Get resource for webhooks collection | ||
| IWebhookCollectionResource webhooksResource = accountResource.Webhooks(); | ||
|
|
||
| // List all webhooks for the account | ||
| IList<Webhook> webhooks = await webhooksResource.GetAll(); | ||
| logger.LogInformation("Found {Count} webhook(s).", webhooks.Count); | ||
|
|
||
| // Create a new "email_sending" webhook subscribed to delivery + bounce events on the transactional stream | ||
| var createRequest = new CreateWebhookRequest | ||
| { | ||
| Url = new Uri("https://example.com/webhooks/mailtrap"), | ||
| WebhookType = WebhookType.EmailSending, | ||
| Active = true, | ||
| PayloadFormat = WebhookPayloadFormat.Json, | ||
| SendingStream = SendingStream.Transactional | ||
| }; | ||
| createRequest.EventTypes.Add(WebhookEventType.Delivery); | ||
| createRequest.EventTypes.Add(WebhookEventType.Bounce); | ||
|
|
||
| CreateWebhookResponse createdWebhook = await webhooksResource.Create(createRequest); | ||
|
|
||
| // The signing secret is only returned at creation time - store it securely | ||
| logger.LogInformation( | ||
| "Created Webhook: Id={Id}, Url={Url}, Type={Type}", | ||
| createdWebhook.Id, | ||
| createdWebhook.Url, | ||
| createdWebhook.WebhookType); | ||
| logger.LogInformation("Signing secret (store securely, returned only once): {Secret}", createdWebhook.SigningSecret); | ||
|
|
||
|
IgorDobryn marked this conversation as resolved.
|
||
| // Get resource for the specific webhook | ||
| IWebhookResource webhookResource = accountResource.Webhook(createdWebhook.Id); | ||
|
|
||
| // Get details of the webhook | ||
| Webhook webhookDetails = await webhookResource.GetDetails(); | ||
| logger.LogInformation("Webhook details: Id={Id}, Url={Url}, Active={Active}", | ||
| webhookDetails.Id, | ||
| webhookDetails.Url, | ||
| webhookDetails.Active); | ||
|
|
||
| // Update the webhook - swap the event types and disable it | ||
| var updateRequest = new UpdateWebhookRequest | ||
| { | ||
| Active = false, | ||
| EventTypes = [WebhookEventType.Delivery, WebhookEventType.Open, WebhookEventType.Click] | ||
| }; | ||
| Webhook updatedWebhook = await webhookResource.Update(updateRequest); | ||
| logger.LogInformation( | ||
| "Updated Webhook: Id={Id}, Active={Active}, EventTypes={EventTypes}", | ||
| updatedWebhook.Id, | ||
| updatedWebhook.Active, | ||
| string.Join(",", updatedWebhook.EventTypes)); | ||
|
|
||
| // Delete the webhook | ||
| // The webhook resource becomes invalid after deletion and should not be used anymore | ||
| Webhook deletedWebhook = await webhookResource.Delete(); | ||
| logger.LogInformation("Webhook Deleted: Id={Id}", deletedWebhook.Id); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError(ex, "An error occurred during API call."); | ||
| Environment.ExitCode = 1; | ||
| return; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
examples/Mailtrap.Example.Webhooks/Properties/launchSettings.json
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,10 @@ | ||
| { | ||
| "profiles": { | ||
| "Project": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
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.
What's this?
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.
Same approach as in mailtrap/mailtrap-java#51 (comment)