-
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 3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dotnet 10.0.102 | ||
|
IgorDobryn marked this conversation as resolved.
Outdated
|
||
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
42 changes: 42 additions & 0 deletions
42
src/Mailtrap.Abstractions/ApiTokens/IApiTokenCollectionResource.cs
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,42 @@ | ||
| namespace Mailtrap.ApiTokens; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents API token collection resource. | ||
| /// </summary> | ||
| public interface IApiTokenCollectionResource : IRestResource | ||
| { | ||
| /// <summary> | ||
| /// List all API tokens visible to the current API token. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="cancellationToken"> | ||
| /// Token to control operation cancellation. | ||
| /// </param> | ||
| /// | ||
| /// <returns> | ||
| /// Collection of API token details. | ||
| /// </returns> | ||
| public Task<IList<ApiToken>> GetAll(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Create a new API token. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="request"> | ||
| /// API token creation request. | ||
| /// </param> | ||
| /// | ||
| /// <param name="cancellationToken"> | ||
| /// Token to control operation cancellation. | ||
| /// </param> | ||
| /// | ||
| /// <returns> | ||
| /// Created API token details, including the full token value. | ||
| /// </returns> | ||
| /// | ||
| /// <remarks> | ||
| /// The full token value is only returned once at creation — store it securely. | ||
| /// </remarks> | ||
| public Task<CreateApiTokenResponse> Create(CreateApiTokenRequest request, CancellationToken cancellationToken = default); | ||
| } |
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,49 @@ | ||
| namespace Mailtrap.ApiTokens; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents a single API token resource. | ||
| /// </summary> | ||
| public interface IApiTokenResource : IRestResource | ||
| { | ||
| /// <summary> | ||
| /// Get details of the API token represented by this resource. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="cancellationToken"> | ||
| /// Token to control operation cancellation. | ||
| /// </param> | ||
| /// | ||
| /// <returns> | ||
| /// API token details. | ||
| /// </returns> | ||
| public Task<ApiToken> GetDetails(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Permanently delete the API token represented by this resource. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="cancellationToken"> | ||
| /// Token to control operation cancellation. | ||
| /// </param> | ||
| public Task Delete(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Reset the API token represented by this resource. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="cancellationToken"> | ||
| /// Token to control operation cancellation. | ||
| /// </param> | ||
| /// | ||
| /// <returns> | ||
| /// New API token details, including the full token value. | ||
| /// </returns> | ||
| /// | ||
| /// <remarks> | ||
| /// Expires the requested token and creates a new token with the same permissions. | ||
| /// The old token stops working after a short grace period. The response includes | ||
| /// the new token value — store it securely; it is only returned once. | ||
| /// </remarks> | ||
| public Task<ApiTokenResetResponse> Reset(CancellationToken cancellationToken = default); | ||
| } |
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,76 @@ | ||
| namespace Mailtrap.ApiTokens.Models; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents API token details. | ||
| /// </summary> | ||
| public sealed record ApiToken | ||
| { | ||
| /// <summary> | ||
| /// Gets the API token identifier. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// API token identifier. | ||
| /// </value> | ||
| [JsonPropertyName("id")] | ||
| [JsonPropertyOrder(1)] | ||
| [JsonRequired] | ||
| public long Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the API token display name. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// API token display name. | ||
| /// </value> | ||
| [JsonPropertyName("name")] | ||
| [JsonPropertyOrder(2)] | ||
| public string Name { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the last 4 characters of the token. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Last 4 characters of the token. The full token value is only returned on create or reset. | ||
| /// </value> | ||
| [JsonPropertyName("last_4_digits")] | ||
| [JsonPropertyOrder(3)] | ||
| public string Last4Digits { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the user or token that created this API token. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Creator name or <see langword="null"/> if not available. | ||
| /// </value> | ||
| [JsonPropertyName("created_by")] | ||
| [JsonPropertyOrder(4)] | ||
| public string? CreatedBy { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the date and time when the API token expires. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Expiration date and time, or <see langword="null"/> if the token does not expire. | ||
| /// </value> | ||
| [JsonPropertyName("expires_at")] | ||
| [JsonPropertyOrder(5)] | ||
| public DateTimeOffset? ExpiresAt { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource accesses granted to this API token. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Collection of resource accesses. | ||
| /// </value> | ||
| [JsonPropertyName("resources")] | ||
| [JsonPropertyOrder(6)] | ||
| [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] | ||
| public IList<ApiTokenAccess> Resources { get; } = []; | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/Mailtrap.Abstractions/ApiTokens/Models/ApiTokenAccess.cs
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,42 @@ | ||
| namespace Mailtrap.ApiTokens.Models; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents an access entry granted to an API token for a specific resource. | ||
| /// </summary> | ||
| public sealed record ApiTokenAccess | ||
| { | ||
| /// <summary> | ||
| /// Gets the resource type. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Resource type. | ||
| /// </value> | ||
| [JsonPropertyName("resource_type")] | ||
| [JsonPropertyOrder(1)] | ||
| public ResourceType Type { get; set; } = ResourceType.Unknown; | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource identifier. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Resource identifier. | ||
| /// </value> | ||
| [JsonPropertyName("resource_id")] | ||
| [JsonPropertyOrder(2)] | ||
| [JsonRequired] | ||
| public long Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource access level. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Access level for resource. | ||
| /// </value> | ||
| [JsonPropertyName("access_level")] | ||
| [JsonPropertyOrder(3)] | ||
| public AccessLevel AccessLevel { get; set; } = AccessLevel.Indeterminate; | ||
| } |
96 changes: 96 additions & 0 deletions
96
src/Mailtrap.Abstractions/ApiTokens/Requests/ApiTokenAccessRequest.cs
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,96 @@ | ||
| namespace Mailtrap.ApiTokens.Requests; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents an access entry to grant to an API token for a specific resource. | ||
| /// </summary> | ||
| public sealed record ApiTokenAccessRequest : IValidatable | ||
| { | ||
| /// <summary> | ||
| /// Gets the resource type. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Resource type. | ||
| /// </value> | ||
| [JsonPropertyName("resource_type")] | ||
| [JsonPropertyOrder(1)] | ||
| public ResourceType ResourceType { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource identifier. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Resource identifier. | ||
| /// </value> | ||
| [JsonPropertyName("resource_id")] | ||
| [JsonPropertyOrder(2)] | ||
| public long ResourceId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource access level. | ||
| /// </summary> | ||
| /// | ||
| /// <value> | ||
| /// Access level for resource. Allowed values: <see cref="AccessLevel.Viewer"/> or <see cref="AccessLevel.Admin"/>. | ||
| /// </value> | ||
| [JsonPropertyName("access_level")] | ||
| [JsonPropertyOrder(3)] | ||
| public AccessLevel AccessLevel { get; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Primary instance constructor. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="resourceType"> | ||
| /// Type of the resource to grant access to. | ||
| /// </param> | ||
| /// | ||
| /// <param name="resourceId"> | ||
| /// ID of the resource to grant access to. | ||
| /// </param> | ||
| /// | ||
| /// <param name="accessLevel"> | ||
| /// Access level for the resource. Allowed values: <see cref="AccessLevel.Viewer"/> or <see cref="AccessLevel.Admin"/>. | ||
| /// </param> | ||
| /// | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// When <paramref name="resourceType"/> is <see langword="null"/>. | ||
| /// </exception> | ||
| /// | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// When <paramref name="resourceId"/> is less than or equal to zero, | ||
| /// or <paramref name="accessLevel"/> is not <see cref="AccessLevel.Viewer"/> or <see cref="AccessLevel.Admin"/>. | ||
| /// </exception> | ||
| public ApiTokenAccessRequest( | ||
| ResourceType resourceType, | ||
| long resourceId, | ||
| AccessLevel accessLevel) | ||
| { | ||
| Ensure.NotNull(resourceType, nameof(resourceType)); | ||
| Ensure.GreaterThanZero(resourceId, nameof(resourceId)); | ||
|
|
||
| if (accessLevel is not AccessLevel.Viewer and not AccessLevel.Admin) | ||
| { | ||
| throw new ArgumentOutOfRangeException( | ||
| nameof(accessLevel), | ||
| accessLevel, | ||
| "Allowed values are Viewer or Admin"); | ||
| } | ||
|
|
||
| ResourceType = resourceType; | ||
| ResourceId = resourceId; | ||
| AccessLevel = accessLevel; | ||
| } | ||
|
|
||
|
|
||
| /// <inheritdoc/> | ||
| public ValidationResult Validate() | ||
| { | ||
| return ApiTokenAccessRequestValidator.Instance | ||
| .Validate(this) | ||
| .ToMailtrapValidationResult(); | ||
| } | ||
| } |
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)