Class: Cloudflare::EmailService::Client
- Inherits:
-
Object
- Object
- Cloudflare::EmailService::Client
- 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
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#deliver(message) ⇒ Response
Sends a pre-built Message.
-
#initialize(account_id: nil, api_token: nil, api_base: nil, open_timeout: nil, timeout: nil) ⇒ Client
constructor
A new instance of Client.
-
#send_email(**kwargs) ⇒ Response
Builds and sends a message.
Constructor Details
#initialize(account_id: nil, api_token: nil, api_base: nil, open_timeout: nil, timeout: nil) ⇒ Client
Returns a new instance of Client.
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 = account_id || config.account_id @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_id ⇒ Object (readonly)
Returns the value of attribute account_id.
17 18 19 |
# File 'lib/cloudflare/email_service/client.rb', line 17 def account_id @account_id end |
#api_base ⇒ Object (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_token ⇒ Object (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_timeout ⇒ Object (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 |
#timeout ⇒ Object (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.
41 42 43 |
# File 'lib/cloudflare/email_service/client.rb', line 41 def deliver() post(send_uri, .validate!.to_h) end |
#send_email(**kwargs) ⇒ Response
Builds and sends a message. Accepts the same keyword arguments as Message#initialize.
35 36 37 |
# File 'lib/cloudflare/email_service/client.rb', line 35 def send_email(**kwargs) deliver(Message.new(**kwargs)) end |