Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/contacts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
contact_lists.list
# => [#<struct Mailtrap::ContactList id=1, name="Test List">]

# Filter contact lists by name (case-insensitive prefix match)
contact_lists.list(search: 'news')
# => [#<struct Mailtrap::ContactList id=2, name="Newsletter">]

# Update contact list
contact_lists.update(list.id, name: 'Test List Updated')
# => #<struct Mailtrap::ContactList id=1, name="Test List Updated">
Expand Down
8 changes: 6 additions & 2 deletions lib/mailtrap/contact_lists_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContactList>] 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
Expand Down
15 changes: 15 additions & 0 deletions spec/mailtrap/contact_lists_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading