Class: Mailkite::DeliveryMethod
- Inherits:
-
Object
- Object
- Mailkite::DeliveryMethod
- Defined in:
- lib/mailkite/delivery_method.rb
Defined Under Namespace
Classes: UnsupportedFeatureError
Constant Summary collapse
- HANDLED_HEADERS =
Top-level headers the conversion consumes, plus the structural headers that only describe the MIME document (the API composes its own MIME). Anything else raises UnsupportedFeatureError — POST /v1/send takes no custom headers.
%w[ from to cc bcc subject reply-to in-reply-to date message-id mime-version content-type content-transfer-encoding ].freeze
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#deliver!(mail) ⇒ Object
Deliver a Mail::Message via POST /v1/send.
-
#initialize(settings = {}) ⇒ DeliveryMethod
constructor
settings: api_key (falls back to ENV), optional base_url, or bring your own
client— anything withsend(message)(e.g. a Mailkite::Client, or a stub in tests).
Constructor Details
#initialize(settings = {}) ⇒ DeliveryMethod
settings: api_key (falls back to ENV), optional
base_url, or bring your own client — anything with send(message)
(e.g. a Mailkite::Client, or a stub in tests). Takes precedence over
api_key.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mailkite/delivery_method.rb', line 38 def initialize(settings = {}) require "mail" # lazy — only delivery-method users need the mail gem @settings = settings @client = settings[:client] return if @client api_key = settings[:api_key] || ENV["MAILKITE_API_KEY"] if api_key.nil? || api_key.empty? raise ArgumentError, "MailKite API key missing — pass api_key: in mailkite_settings or set MAILKITE_API_KEY" end @client = Client.new(api_key, settings[:base_url] || DEFAULT_BASE_URL) end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
32 33 34 |
# File 'lib/mailkite/delivery_method.rb', line 32 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
Deliver a Mail::Message via POST /v1/send. Returns the API response hash ({ "id" => …, "status" => … }); API failures raise Mailkite::Error.
53 54 55 |
# File 'lib/mailkite/delivery_method.rb', line 53 def deliver!(mail) @client.send(payload_for(mail)) end |