Class: UtoboEmail::Client

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

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.email.utobo.com/v1"
SDK_VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, base_url: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/utobo_email/client.rb', line 12

def initialize(api_key = nil, base_url: nil)
  @api_key = api_key || ENV["UTOBO_EMAIL_API_KEY"] || ENV["UTOBO_MAIL_API_KEY"]
  raise ArgumentError, <<~MSG.strip if @api_key.nil? || @api_key.empty?
    Missing API key. Pass it to UtoboEmail.new("av_live_...") or set UTOBO_EMAIL_API_KEY.
  MSG

  @base_url = base_url || ENV["UTOBO_EMAIL_BASE_URL"] || ENV["UTOBO_MAIL_BASE_URL"] || DEFAULT_BASE_URL
  @emails = Emails.new(self)
end

Instance Attribute Details

#emailsObject (readonly)

Returns the value of attribute emails.



10
11
12
# File 'lib/utobo_email/client.rb', line 10

def emails
  @emails
end

Instance Method Details

#get(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
# File 'lib/utobo_email/client.rb', line 32

def get(path)
  uri = URI("#{@base_url}#{path}")
  req = Net::HTTP::Get.new(uri)
  set_headers(req)
  execute(uri, req)
end

#post(path, body) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
28
29
# File 'lib/utobo_email/client.rb', line 23

def post(path, body)
  uri = URI("#{@base_url}#{path}")
  req = Net::HTTP::Post.new(uri)
  set_headers(req)
  req.body = JSON.generate(body)
  execute(uri, req)
end