Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ General:
- API Tokens API – [`api_tokens_api.rb`](examples/api_tokens_api.rb)
- Billing API – [`billing_api.rb`](examples/billing_api.rb)
- Permissions API – [`permissions_api.rb`](examples/permissions_api.rb)
- Sub Accounts API (list, create, delete) – [`sub_accounts_api.rb`](examples/sub_accounts_api.rb)
- Templates API (experimental) – [`templates_api.rb`](examples/templates_api.rb)
- Email Templates API – [`email_templates_api.rb`](examples/email_templates_api.rb)
- Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
Expand Down
6 changes: 5 additions & 1 deletion examples/sub_accounts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
# => [#<struct Mailtrap::SubAccount id=12345, name="Development Team Account">, ...]

# Create a new sub account
sub_accounts.create(name: 'New Team Account')
sub_account = sub_accounts.create(name: 'New Team Account')
# => #<struct Mailtrap::SubAccount id=12347, name="New Team Account">

# Delete the sub account
sub_accounts.delete(sub_account.id)
# => nil
13 changes: 13 additions & 0 deletions lib/mailtrap/sub_accounts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def create(options)
base_create(options)
end

# Permanently deletes a sub account under the organization
#
# Requires organization admin permissions. The deletion is permanent
# and removes all data of the sub account. Deleting the last sub account also deletes the organization.
# A repeated call for the same sub account returns a 404 error.
# Rate limit: 10 requests per minute per organization.
# @param sub_account_id [Integer] The sub account ID
# @return nil
# @!macro api_errors
def delete(sub_account_id)
base_delete(sub_account_id)
end

private

def base_path
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.

24 changes: 24 additions & 0 deletions spec/mailtrap/sub_accounts_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,28 @@
end
end
end

describe '#delete' do
subject(:delete) { sub_accounts_api.delete(sub_account_id) }

# Deletes a sub account the example creates itself. When the cassette is re-recorded against
# the live API, no existing sub account gets deleted, and the organization keeps its accounts.
let(:sub_account_id) { sub_accounts_api.create(name: 'SDK Delete Test Sub Account').id }

it 'returns nil on success' do
expect(delete).to be_nil
end

context 'when sub account does not exist' do
let(:sub_account_id) { -1 }

it 'raises not found error' do
expect { delete }.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
end
Loading