Class: Resend::Client

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

Constant Summary collapse

BASE_URL =
"https://api.klotty.com/".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/resend/client.rb', line 12

def initialize(api_key)
  raise ArgumentError.new("API Key is not a string") unless api_key.is_a?(String)
  @api_key = api_key
  @timeout = nil
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#send_email(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/resend/client.rb', line 18

def send_email(params)
  validate!(params)

  options = {
    headers: {
      'Content-Type' => 'application/json',
      "Accept" => "application/json",
      "User-Agent" => "ruby:#{Resend::VERSION}",
      "Authorization" => "Bearer #{@api_key}",
    },
    body: params.to_json
  }

  resp = HTTParty.post("#{BASE_URL}/email", options)
  resp.transform_keys!(&:to_sym)
  if not resp[:error].nil?
    handle_error!(resp[:error])
  end
  resp
end