-
Notifications
You must be signed in to change notification settings - Fork 7
Add Suppressions API #73
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
Changes from all commits
c5b5a18
b2a0f2b
2aaa54c
7110c1d
f5a944a
d2e34e2
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,40 @@ | ||
require 'mailtrap' | ||
|
||
account_id = 3229 | ||
client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
suppressions = Mailtrap::SuppressionsAPI.new(account_id, 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 | ||
suppressions.list | ||
# => | ||
# [ | ||
# #<struct Mailtrap::Suppression | ||
# id="64d71bf3-1276-417b-86e1-8e66f138acfe", | ||
# type="unsubscription", | ||
# created_at="2024-12-26T09:40:44.161Z", | ||
# email="recipient@example.com", | ||
# sending_stream="transactional", | ||
# domain_name="example.com", | ||
# message_bounce_category="", | ||
# message_category="Welcome email", | ||
# message_client_ip="123.123.123.123", | ||
# message_created_at="2024-12-26T07:10:00.889Z", | ||
# message_esp_response="", | ||
# message_esp_server_type="", | ||
# message_outgoing_ip="1.1.1.1", | ||
# message_recipient_mx_name="Other Providers", | ||
# message_sender_email="hello@sender.com", | ||
# message_subject="Welcome!"> | ||
# ] | ||
|
||
# Get suppressions for the email | ||
list = suppressions.list(email: 'recipient@example.com') | ||
|
||
# Delete a suppression | ||
suppressions.delete(list.first.id) | ||
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 | ||
Comment on lines
+27
to
+29
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 | 🟠 Major 🧩 Analysis chainReturn type mismatch in docs vs implementation; validate input YARD says “return nil” but the method returns whatever client.delete returns. Either return nil explicitly or update the doc. Also guard against blank IDs. - # @return nil
+ # @return [nil] Always nil on success
# @!macro api_errors
def delete(suppression_id)
- client.delete("#{base_path}/#{suppression_id}")
+ raise ArgumentError, 'suppression_id is required' if suppression_id.to_s.empty?
+ client.delete("#{base_path}/#{suppression_id}")
+ nil
end If you prefer surfacing the HTTP response (e.g., status/boolean), update the YARD return type instead and keep the current behavior. 🏁 Script executed: #!/bin/bash
echo "SuppressionsApi delete method docs and implementation:"
rg -nP -C2 "(#.*@return|def delete)" lib/mailtrap/suppressions_api.rb
echo -e "\nOther API delete methods:"
rg -nP -C3 "def delete" -g "lib/mailtrap/*_api.rb"
echo -e "\nClient.delete method:"
rg -nP -C2 "def delete" -g "lib/mailtrap/*client*.rb" Length of output: 2985 🏁 Script executed: #!/bin/bash
# Locate base_delete implementation to verify its behavior
rg -nP "def base_delete" -g "lib/mailtrap/**/*.rb" -C5 Length of output: 649 🏁 Script executed: #!/bin/bash
# Show class definition of SuppressionsApi
rg -nC3 "class SuppressionsApi" -g "lib/mailtrap/suppressions_api.rb" Length of output: 0 Update YARD @return to match actual return value
🤖 Prompt for AI Agents
|
||
|
||
private | ||
|
||
def base_path | ||
"/api/accounts/#{account_id}/suppressions" | ||
end | ||
end | ||
end |
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.
Guard against empty list before delete
list.first can be nil and raise NoMethodError on .id.
📝 Committable suggestion
🤖 Prompt for AI Agents