Skip to content

Commit 4bef8e8

Browse files
committed
updated suppresions base_path method
1 parent 3d0d0da commit 4bef8e8

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

examples/suppressions_api.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111

1212
# Get all suppressions
1313
list = suppressions.list
14+
# =>
15+
# [
16+
# Mailtrap::Suppression.new(
17+
# id: "64d71bf3-1276-417b-86e1-8e66f138acfe",
18+
# type: "unsubscription",
19+
# created_at: "2024-12-26T09:40:44.161Z",
20+
# email: "[email protected]",
21+
# sending_stream: "transactional",
22+
# domain_name: "sender.com",
23+
# message_bounce_category: nil,
24+
# message_category: "Welcome email",
25+
# message_client_ip: "123.123.123.123",
26+
# message_created_at: "2024-12-26T07:10:00.889Z",
27+
# message_outgoing_ip: "1.1.1.1",
28+
# message_recipient_mx_name: "Other Providers",
29+
# message_sender_email: "[email protected]",
30+
# message_subject: "Welcome!"
31+
# )
32+
# ]
1433

1534
# Delete a suppression
1635
suppressions.delete(list.first.id)

lib/mailtrap/base_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def base_delete(id)
6464
client.delete("#{base_path}/#{id}")
6565
end
6666

67-
def base_list
68-
response = client.get(base_path)
67+
def base_list(query_params = {})
68+
response = client.get(base_path, query_params)
6969
response.map { |item| handle_response(item) }
7070
end
7171

lib/mailtrap/suppressions_api.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
module Mailtrap
77
class SuppressionsAPI
88
include BaseAPI
9+
10+
self.response_class = Suppression
11+
912
# Lists all suppressions for the account
1013
# @param email [String] Email address to filter suppressions (optional)
1114
# @return [Array<Suppression>] Array of suppression objects
@@ -14,8 +17,7 @@ def list(email: nil)
1417
query_params = {}
1518
query_params[:email] = email if email
1619

17-
response = client.get(base_path, query_params)
18-
response.map { |suppression| build_entity(suppression, Suppression) }
20+
base_list(query_params)
1921
end
2022

2123
# Deletes a suppression
@@ -29,7 +31,7 @@ def delete(suppression_id)
2931
private
3032

3133
def base_path
32-
"/api/accounts/#{@account_id}/suppressions"
34+
"/api/accounts/#{account_id}/suppressions"
3335
end
3436
end
3537
end

spec/mailtrap/suppressions_api_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@
6767
expect(response.first).to have_attributes(expected_attributes)
6868
end
6969

70+
it 'returns suppressions filtered by email' do
71+
72+
stub_request(:get, "#{base_url}/suppressions?email=#{email}")
73+
.to_return(
74+
status: 200,
75+
body: [expected_attributes].to_json,
76+
headers: { 'Content-Type' => 'application/json' }
77+
)
78+
79+
response = suppressions.list(email:)
80+
expect(response).to all(be_a(Mailtrap::Suppression))
81+
expect(response.length).to eq(1)
82+
expect(response.first).to have_attributes(expected_attributes)
83+
end
84+
7085
it 'raises error when unauthorized' do
7186
stub_request(:get, "#{base_url}/suppressions")
7287
.to_return(

0 commit comments

Comments
 (0)