-
Notifications
You must be signed in to change notification settings - Fork 5
Suppressions Api #52
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
sarco3t
wants to merge
2
commits into
railsware:main
Choose a base branch
from
sarco3t:suppressions-api
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
Suppressions Api #52
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,16 @@ | ||
require 'mailtrap' | ||
|
||
client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
suppressions = Mailtrap::SuppressionsAPI.new 3229, client | ||
|
||
# Set your API credentials as environment variables | ||
# export MAILTRAP_API_KEY='your-api-key' | ||
# export MAILTRAP_ACCOUNT_ID=your-account-id | ||
# | ||
# suppressions = Mailtrap::SuppressionsAPI.new | ||
|
||
# Get all suppressions | ||
list = suppressions.list | ||
|
||
# Delete a suppression | ||
suppressions.delete(list.first.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add nil check before accessing list.first. The code assumes the suppressions list is not empty, which could cause a NoMethodError if no suppressions exist. -suppressions.delete(list.first.id)
+suppressions.delete(list.first.id) if list.any? 🤖 Prompt for AI Agents
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mailtrap | ||
class BaseAPI | ||
attr_reader :account_id, :client | ||
|
||
# @param account_id [Integer] The account ID | ||
# @param client [Mailtrap::Client] The client instance | ||
# @raise [ArgumentError] If account_id is nil | ||
def initialize(account_id = ENV.fetch('MAILTRAP_ACCOUNT_ID'), client = Mailtrap::Client.new) | ||
raise ArgumentError, 'account_id is required' if account_id.nil? | ||
|
||
@account_id = account_id | ||
@client = client | ||
end | ||
|
||
private | ||
|
||
def validate_options!(options, supported_options) | ||
invalid_options = options.keys - supported_options | ||
return if invalid_options.empty? | ||
|
||
raise ArgumentError, "invalid options are given: #{invalid_options}, supported_options: #{supported_options}" | ||
end | ||
|
||
def build_entity(options, response_class) | ||
response_class.new(options.slice(*response_class.members)) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mailtrap | ||
# Data Transfer Object for Suppression | ||
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/f8144826d885a-list-and-search-suppressions | ||
# @attr_reader id [String] The suppression UUID | ||
# @attr_reader type [String] The suppression type | ||
# @attr_reader created_at [String] The creation timestamp | ||
# @attr_reader email [String] The email address | ||
# @attr_reader sending_stream [String] The sending stream | ||
# @attr_reader domain_name [String, nil] The domain name | ||
# @attr_reader message_bounce_category [String, nil] The bounce category | ||
# @attr_reader message_category [String, nil] The message category | ||
# @attr_reader message_client_ip [String, nil] The client IP | ||
# @attr_reader message_created_at [String, nil] The message creation timestamp | ||
# @attr_reader message_esp_response [String, nil] The ESP response | ||
# @attr_reader message_esp_server_type [String, nil] The ESP server type | ||
# @attr_reader message_outgoing_ip [String, nil] The outgoing IP | ||
# @attr_reader message_recipient_mx_name [String, nil] The recipient MX name | ||
# @attr_reader message_sender_email [String, nil] The sender email | ||
# @attr_reader message_subject [String, nil] The message subject | ||
Suppression = Struct.new( | ||
:id, | ||
:type, | ||
:created_at, | ||
:email, | ||
:sending_stream, | ||
:domain_name, | ||
:message_bounce_category, | ||
:message_category, | ||
:message_client_ip, | ||
:message_created_at, | ||
:message_esp_response, | ||
:message_esp_server_type, | ||
:message_outgoing_ip, | ||
:message_recipient_mx_name, | ||
:message_sender_email, | ||
:message_subject, | ||
keyword_init: true | ||
) do | ||
# @return [Hash] The suppression attributes as a hash | ||
def to_h | ||
super.compact | ||
end | ||
end | ||
end |
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'suppression' | ||
|
||
module Mailtrap | ||
class SuppressionsAPI < BaseAPI | ||
# Lists all suppressions for the account | ||
# @param email [String] Email address to filter suppressions (optional) | ||
# @return [Array<Suppression>] Array of suppression objects | ||
# @!macro api_errors | ||
def list(email: nil) | ||
query_params = {} | ||
query_params[:email] = email if email | ||
|
||
response = client.get(base_path, query_params) | ||
response.map { |suppression| build_entity(suppression, Suppression) } | ||
end | ||
|
||
# Deletes a suppression | ||
# @param suppression_id [String] The suppression UUID | ||
# @return nil | ||
# @!macro api_errors | ||
def delete(suppression_id) | ||
client.delete("#{base_path}/#{suppression_id}") | ||
end | ||
|
||
private | ||
|
||
def base_path | ||
"/api/accounts/#{account_id}/suppressions" | ||
end | ||
end | ||
end |
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.
🛠️ Refactor suggestion
Remove hardcoded credentials from example.
The example contains hardcoded API credentials which could be accidentally committed or copied by users. Consider using placeholder text or environment variables by default.
📝 Committable suggestion
🤖 Prompt for AI Agents