Class: Mailersend::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mailersend/client.rb

Overview

Inits the client.

Instance Method Summary collapse

Constructor Details

#initialize(api_token = ENV.fetch('MAILERSEND_API_TOKEN', nil)) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/mailersend/client.rb', line 14

def initialize(api_token = ENV.fetch('MAILERSEND_API_TOKEN', nil))
  raise ArgumentError, 'API token is not provided' if api_token.nil?

  @api_token = api_token
end

Instance Method Details

#httpObject



20
21
22
23
24
25
26
# File 'lib/mailersend/client.rb', line 20

def http
  HTTP
    .timeout(connect: 15, read: 30)
    .auth("Bearer #{@api_token}")
    .headers('User-Agent' => "MailerSend-client-ruby/#{Mailersend::VERSION}",
             'Accept' => 'application/json')
end