Class: Cloudflare::EmailService::Client

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

Overview

HTTP client for the Cloudflare Email Service send endpoint.

client = Cloudflare::EmailService::Client.new(
  account_id: "...", api_token: "..."
)
client.send_email(from: "a@x.com", to: "b@y.com",
                  subject: "Hi", text: "Hello")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id: nil, api_token: nil, api_base: nil, open_timeout: nil, timeout: nil) ⇒ Client

Returns a new instance of Client.

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cloudflare/email_service/client.rb', line 19

def initialize(account_id: nil, api_token: nil, api_base: nil,
               open_timeout: nil, timeout: nil)
  config = EmailService.configuration
  @account_id =  || config.
  @api_token = api_token || config.api_token
  @api_base = api_base || config.api_base
  @open_timeout = open_timeout || config.open_timeout
  @timeout = timeout || config.timeout

  raise ConfigurationError, "no account_id configured" if @account_id.to_s.empty?
  raise ConfigurationError, "no api_token configured" if @api_token.to_s.empty?
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



17
18
19
# File 'lib/cloudflare/email_service/client.rb', line 17

def 
  @account_id
end

#api_baseObject (readonly)

Returns the value of attribute api_base.



17
18
19
# File 'lib/cloudflare/email_service/client.rb', line 17

def api_base
  @api_base
end

#api_tokenObject (readonly)

Returns the value of attribute api_token.



17
18
19
# File 'lib/cloudflare/email_service/client.rb', line 17

def api_token
  @api_token
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



17
18
19
# File 'lib/cloudflare/email_service/client.rb', line 17

def open_timeout
  @open_timeout
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



17
18
19
# File 'lib/cloudflare/email_service/client.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#deliver(message) ⇒ Response

Sends a pre-built Message.

Returns:



41
42
43
# File 'lib/cloudflare/email_service/client.rb', line 41

def deliver(message)
  post(send_uri, message.validate!.to_h)
end

#send_email(**kwargs) ⇒ Response

Builds and sends a message. Accepts the same keyword arguments as Message#initialize.

Returns:



35
36
37
# File 'lib/cloudflare/email_service/client.rb', line 35

def send_email(**kwargs)
  deliver(Message.new(**kwargs))
end