Class: MailerLite::Client

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

Overview

Inits the client.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



16
17
18
# File 'lib/mailerlite/client.rb', line 16

def initialize(api_token = ENV.fetch('MAILERLITE_API_TOKEN', nil))
  @api_token = api_token
end

Instance Method Details

#headersObject



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

def headers
  {
    'User-Agent' => "MailerLite-client-ruby/#{MailerLite::VERSION}",
    'Accept' => 'application/json',
    'Content-type' => 'application/json'
  }
end

#httpObject



28
29
30
31
32
33
# File 'lib/mailerlite/client.rb', line 28

def http
  HTTP
    .timeout(connect: 15, read: 30)
    .auth("Bearer #{@api_token}")
    .headers(headers)
end