Class: Smtp2go::Smtp2goClient
- Inherits:
-
Object
- Object
- Smtp2go::Smtp2goClient
- Defined in:
- lib/smtp2go/core.rb
Overview
Ruby Library for interacting with the smtp2go API
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Client to handle API interfacing.
-
#send_endpoint ⇒ Object
readonly
Client to handle API interfacing.
Instance Method Summary collapse
-
#initialize ⇒ Smtp2goClient
constructor
A new instance of Smtp2goClient.
-
#send(sender:, recipients:, subject:, text: nil, html: nil) ⇒ Smtp2goResponse
Response object.
Constructor Details
#initialize ⇒ Smtp2goClient
Returns a new instance of Smtp2goClient.
11 12 13 14 15 16 |
# File 'lib/smtp2go/core.rb', line 11 def initialize @api_key = ENV['SMTP2GO_API_KEY'] @headers = HEADERS @send_endpoint = SEND_ENDPOINT raise Smtp2goAPIKeyException unless @api_key end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Client to handle API interfacing
10 11 12 |
# File 'lib/smtp2go/core.rb', line 10 def headers @headers end |
#send_endpoint ⇒ Object (readonly)
Client to handle API interfacing
10 11 12 |
# File 'lib/smtp2go/core.rb', line 10 def send_endpoint @send_endpoint end |
Instance Method Details
#send(sender:, recipients:, subject:, text: nil, html: nil) ⇒ Smtp2goResponse
Returns response object.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smtp2go/core.rb', line 24 def send(sender:, recipients:, subject:, text: nil, html: nil) raise Smtp2goParameterException unless [html, text].any? payload = { api_key: @api_key, sender: sender, to: recipients, subject: subject, text_body: text, html_body: html } response = HTTParty.post( @send_endpoint, body: JSON.dump(payload), headers: @headers ) Smtp2goResponse.new response end |