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
6 changes: 6 additions & 0 deletions examples/inboxes_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
# Reset SMTP credentials of the inbox
inboxes.reset_credentials(inbox.id)

# Turn the email address of the inbox on/off
inboxes.toggle_email_username(inbox.id)

# Reset username of email address per inbox
Comment thread
IgorDobryn marked this conversation as resolved.
inboxes.reset_email_username(inbox.id)

# Delete unbox list
inboxes.delete(inbox.id)
18 changes: 18 additions & 0 deletions lib/mailtrap/inboxes_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ def reset_credentials(inbox_id)
handle_response(response)
end

# Turn the email address of the inbox on/off
Comment thread
IgorDobryn marked this conversation as resolved.
# @param inbox_id [Integer] The Inbox identifier
# @return [Inbox] Updated Inbox object
# @!macro api_errors
def toggle_email_username(inbox_id)
response = client.patch("#{base_path}/#{inbox_id}/toggle_email_username")
handle_response(response)
end

# Reset username of email address per inbox
Comment thread
IgorDobryn marked this conversation as resolved.
# @param inbox_id [Integer] The Inbox identifier
# @return [Inbox] Updated Inbox object
# @!macro api_errors
def reset_email_username(inbox_id)
response = client.patch("#{base_path}/#{inbox_id}/reset_email_username")
handle_response(response)
end

private

def wrap_request(options)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions spec/mailtrap/inboxes_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,57 @@
end
end

describe '#toggle_email_username' do
subject(:toggle_email_username) { inboxes_api.toggle_email_username(inbox_id) }

let(:inbox_id) { 4_578_672 }

it 'returns Inbox object' do
expect(toggle_email_username).to be_a(Mailtrap::Inbox)
expect(toggle_email_username).to have_attributes(
id: inbox_id,
email_username_enabled: true
Comment thread
IgorDobryn marked this conversation as resolved.
)
end

context 'when inbox does not exist' do
let(:inbox_id) { -1 }

it 'raises not found error' do
expect { toggle_email_username }.to raise_error do |error|
expect(error).to be_a(Mailtrap::Error)
expect(error.message).to include('Not Found')
expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true
end
end
end
end

describe '#reset_email_username' do
subject(:reset_email_username) { inboxes_api.reset_email_username(inbox_id) }

let(:inbox_id) { 4_578_672 }

it 'returns Inbox object' do
expect(reset_email_username).to have_attributes(
id: inbox_id,
email_username: '1234abcd'
)
Comment thread
IgorDobryn marked this conversation as resolved.
end

context 'when inbox does not exist' do
let(:inbox_id) { -1 }

it 'raises not found error' do
expect { reset_email_username }.to raise_error do |error|
expect(error).to be_a(Mailtrap::Error)
expect(error.message).to include('Not Found')
expect(error.messages.any? { |msg| msg.include?('Not Found') }).to be true
end
end
end
end

describe '#delete' do
subject(:delete) { inboxes_api.delete(inbox_id) }

Expand Down
Loading