Skip to content

Commit 183af30

Browse files
committed
fix rubocop errors, updated Maitrap::Client#initialize
1 parent 5814deb commit 183af30

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

lib/mailtrap/client.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ def initialize( # rubocop:disable Metrics/ParameterLists
3737
sandbox: false,
3838
inbox_id: nil
3939
)
40-
raise ArgumentError, 'api_key is required' if api_key.nil?
41-
raise ArgumentError, 'api_port is required' if api_port.nil?
42-
raise ArgumentError, 'bulk mode is not applicable for sandbox API' if sandbox && bulk
40+
validate_args!(api_key, api_port, bulk, sandbox, inbox_id)
4341

4442
api_host ||= select_api_host(bulk:, sandbox:)
45-
raise ArgumentError, 'inbox_id is required for sandbox API' if sandbox && inbox_id.nil?
4643

4744
@api_key = api_key
4845
@api_host = api_host
@@ -215,5 +212,12 @@ def json_response(body)
215212
def compact_with_empty_arrays(hash)
216213
hash.reject { |_, v| v.nil? || (v.is_a?(Array) && v.empty?) }
217214
end
215+
216+
def validate_args!(api_key, api_port, bulk, sandbox, inbox_id)
217+
raise ArgumentError, 'api_key is required' if api_key.nil?
218+
raise ArgumentError, 'api_port is required' if api_port.nil?
219+
raise ArgumentError, 'bulk mode is not applicable for sandbox API' if bulk && sandbox
220+
raise ArgumentError, 'inbox_id is required for sandbox API' if sandbox && inbox_id.nil?
221+
end
218222
end
219223
end

spec/fixtures/vcr_cassettes/Mailtrap_Client/_send_batch/in_bulk_mode/successfully_sends_a_batch_of_emails.yml renamed to spec/fixtures/vcr_cassettes/Mailtrap_Client/_send_batch/when_in_bulk_mode/successfully_sends_a_batch_of_emails.yml

File renamed without changes.

spec/fixtures/vcr_cassettes/Mailtrap_Client/_send_batch/in_sandbox_mode/successfully_sends_a_batch_of_emails.yml renamed to spec/fixtures/vcr_cassettes/Mailtrap_Client/_send_batch/when_in_sandbox_mode/successfully_sends_a_batch_of_emails.yml

File renamed without changes.

spec/mailtrap/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def stub_post(path, status, body)
300300
end
301301
end
302302

303-
context 'in bulk mode' do
303+
context 'when in bulk mode' do
304304
let(:client) { described_class.new(api_key:, bulk: true) }
305305

306306
it 'successfully sends a batch of emails', :vcr do
@@ -317,7 +317,7 @@ def stub_post(path, status, body)
317317
end
318318
end
319319

320-
context 'in sandbox mode' do
320+
context 'when in sandbox mode' do
321321
let(:client) { described_class.new(api_key:, sandbox: true, inbox_id: 3_809_768) }
322322

323323
it 'successfully sends a batch of emails', :vcr do

0 commit comments

Comments
 (0)