From b6bd44803e726be70d0123c84324b4e112782255 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Thu, 9 Jul 2026 12:18:16 +0200 Subject: [PATCH 1/2] MT-22678: Add search filter to contact lists listing --- README.md | 2 +- examples/contacts_api.rb | 4 ++++ lib/mailtrap/contact_lists_api.rb | 8 ++++++-- spec/mailtrap/contact_lists_api_spec.rb | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7a9318..3009968 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Email Sandbox (Testing): Contact management: -- Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb) +- Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb) (contact lists support filtering by name via `list(search:)`) General: diff --git a/examples/contacts_api.rb b/examples/contacts_api.rb index b50f496..2753263 100644 --- a/examples/contacts_api.rb +++ b/examples/contacts_api.rb @@ -24,6 +24,10 @@ contact_lists.list # => [#] +# Filter contact lists by name (case-insensitive prefix match) +contact_lists.list(search: 'news') +# => [#] + # Update contact list contact_lists.update(list.id, name: 'Test List Updated') # => # diff --git a/lib/mailtrap/contact_lists_api.rb b/lib/mailtrap/contact_lists_api.rb index 90c48da..783ef89 100644 --- a/lib/mailtrap/contact_lists_api.rb +++ b/lib/mailtrap/contact_lists_api.rb @@ -49,10 +49,14 @@ def delete(list_id) end # Lists all contact lists for the account + # @param search [String] Filters contact lists by name (case-insensitive prefix match) # @return [Array] Array of contact list objects # @!macro api_errors - def list - base_list + def list(search: nil) + query_params = {} + query_params[:search] = search unless search.nil? + + base_list(query_params) end private diff --git a/spec/mailtrap/contact_lists_api_spec.rb b/spec/mailtrap/contact_lists_api_spec.rb index 3d5d44d..447acfb 100644 --- a/spec/mailtrap/contact_lists_api_spec.rb +++ b/spec/mailtrap/contact_lists_api_spec.rb @@ -25,6 +25,21 @@ expect(response.length).to eq(2) expect(response.first).to have_attributes(id: 1, name: 'List 1') end + + it 'filters contact lists by name' do + stub = stub_request(:get, "#{base_url}/contacts/lists") + .with(query: { search: 'news' }) + .to_return( + status: 200, + body: [{ 'id' => 2, 'name' => 'Newsletter' }].to_json, + headers: { 'Content-Type' => 'application/json' } + ) + + response = client.list(search: 'news') + expect(stub).to have_been_requested + expect(response.length).to eq(1) + expect(response.first).to have_attributes(id: 2, name: 'Newsletter') + end end describe '#get' do From 6612bc55249bea8800ecd9f6edee1282aa90b700 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Fri, 10 Jul 2026 10:23:59 +0200 Subject: [PATCH 2/2] MT-22678: Drop search filter call-out from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3009968..b7a9318 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Email Sandbox (Testing): Contact management: -- Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb) (contact lists support filtering by name via `list(search:)`) +- Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb) General: