File tree Expand file tree Collapse file tree 4 files changed +41
-5
lines changed Expand file tree Collapse file tree 4 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 11
11
12
12
# Get all suppressions
13
13
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
+
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
+ # ]
14
33
15
34
# Delete a suppression
16
35
suppressions . delete ( list . first . id )
Original file line number Diff line number Diff line change @@ -64,8 +64,8 @@ def base_delete(id)
64
64
client . delete ( "#{ base_path } /#{ id } " )
65
65
end
66
66
67
- def base_list
68
- response = client . get ( base_path )
67
+ def base_list ( query_params = { } )
68
+ response = client . get ( base_path , query_params )
69
69
response . map { |item | handle_response ( item ) }
70
70
end
71
71
Original file line number Diff line number Diff line change 6
6
module Mailtrap
7
7
class SuppressionsAPI
8
8
include BaseAPI
9
+
10
+ self . response_class = Suppression
11
+
9
12
# Lists all suppressions for the account
10
13
# @param email [String] Email address to filter suppressions (optional)
11
14
# @return [Array<Suppression>] Array of suppression objects
@@ -14,8 +17,7 @@ def list(email: nil)
14
17
query_params = { }
15
18
query_params [ :email ] = email if email
16
19
17
- response = client . get ( base_path , query_params )
18
- response . map { |suppression | build_entity ( suppression , Suppression ) }
20
+ base_list ( query_params )
19
21
end
20
22
21
23
# Deletes a suppression
@@ -29,7 +31,7 @@ def delete(suppression_id)
29
31
private
30
32
31
33
def base_path
32
- "/api/accounts/#{ @ account_id} /suppressions"
34
+ "/api/accounts/#{ account_id } /suppressions"
33
35
end
34
36
end
35
37
end
Original file line number Diff line number Diff line change 67
67
expect ( response . first ) . to have_attributes ( expected_attributes )
68
68
end
69
69
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
+
70
85
it 'raises error when unauthorized' do
71
86
stub_request ( :get , "#{ base_url } /suppressions" )
72
87
. to_return (
You can’t perform that action at this time.
0 commit comments