Class: Mailtrap::Client
- Inherits:
-
Object
- Object
- Mailtrap::Client
- Defined in:
- lib/mailtrap/client.rb
Constant Summary collapse
- SENDING_API_HOST =
'send.api.mailtrap.io'
- BULK_SENDING_API_HOST =
'bulk.api.mailtrap.io'
- SANDBOX_API_HOST =
'sandbox.api.mailtrap.io'
- API_PORT =
443
Instance Attribute Summary collapse
-
#api_host ⇒ Object
readonly
Returns the value of attribute api_host.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_port ⇒ Object
readonly
Returns the value of attribute api_port.
-
#bulk ⇒ Object
readonly
Returns the value of attribute bulk.
-
#inbox_id ⇒ Object
readonly
Returns the value of attribute inbox_id.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
Instance Method Summary collapse
-
#initialize(api_key: ENV.fetch('MAILTRAP_API_KEY'), api_host: nil, api_port: API_PORT, bulk: false, sandbox: false, inbox_id: nil) ⇒ Client
constructor
Initializes a new Mailtrap::Client instance.
- #send(mail) ⇒ Object
Constructor Details
#initialize(api_key: ENV.fetch('MAILTRAP_API_KEY'), api_host: nil, api_port: API_PORT, bulk: false, sandbox: false, inbox_id: nil) ⇒ Client
Initializes a new Mailtrap::Client instance.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mailtrap/client.rb', line 27 def initialize( # rubocop:disable Metrics/ParameterLists api_key: ENV.fetch('MAILTRAP_API_KEY'), api_host: nil, api_port: API_PORT, bulk: false, sandbox: false, inbox_id: nil ) raise ArgumentError, 'api_key is required' if api_key.nil? raise ArgumentError, 'api_port is required' if api_port.nil? api_host ||= select_api_host(bulk: bulk, sandbox: sandbox) raise ArgumentError, 'inbox_id is required for sandbox API' if sandbox && inbox_id.nil? @api_key = api_key @api_host = api_host @api_port = api_port @bulk = bulk @sandbox = sandbox @inbox_id = inbox_id end |
Instance Attribute Details
#api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def api_host @api_host end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def api_key @api_key end |
#api_port ⇒ Object (readonly)
Returns the value of attribute api_port.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def api_port @api_port end |
#bulk ⇒ Object (readonly)
Returns the value of attribute bulk.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def bulk @bulk end |
#inbox_id ⇒ Object (readonly)
Returns the value of attribute inbox_id.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def inbox_id @inbox_id end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
14 15 16 |
# File 'lib/mailtrap/client.rb', line 14 def sandbox @sandbox end |
Instance Method Details
#send(mail) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/mailtrap/client.rb', line 49 def send(mail) raise ArgumentError, 'should be Mailtrap::Mail::Base object' unless mail.is_a? Mail::Base request = post_request(request_url, mail.to_json) response = http_client.request(request) handle_response(response) end |