-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Suppressions Api #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 | ||
# => | ||
# [ | ||
# Mailtrap::Suppression.new( | ||
# id: "64d71bf3-1276-417b-86e1-8e66f138acfe", | ||
# type: "unsubscription", | ||
# created_at: "2024-12-26T09:40:44.161Z", | ||
# email: "[email protected]", | ||
# sending_stream: "transactional", | ||
# domain_name: "sender.com", | ||
# message_bounce_category: nil, | ||
# message_category: "Welcome email", | ||
# message_client_ip: "123.123.123.123", | ||
# message_created_at: "2024-12-26T07:10:00.889Z", | ||
# message_outgoing_ip: "1.1.1.1", | ||
# message_recipient_mx_name: "Other Providers", | ||
# message_sender_email: "[email protected]", | ||
# message_subject: "Welcome!" | ||
# ) | ||
# ] | ||
|
||
# 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
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'base_api' | ||
require_relative 'suppression' | ||
|
||
module Mailtrap | ||
class SuppressionsAPI | ||
include BaseAPI | ||
|
||
self.response_class = Suppression | ||
|
||
# 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 | ||
|
||
base_list(query_params) | ||
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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