Class: MailRoom::Delivery::Postback

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/delivery/postback.rb

Overview

Postback Delivery method

Author:

  • Tony Pitale

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initialize(delivery_options) ⇒ Postback

Build a new delivery, hold the delivery options



19
20
21
# File 'lib/mail_room/delivery/postback.rb', line 19

def initialize(delivery_options)
  @delivery_options = delivery_options
end

Instance Method Details

#deliver(message) ⇒ Object

deliver the message using Faraday to the configured delivery_options url

Parameters:

  • message (String)

    the email message as a string, RFC822 format



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mail_room/delivery/postback.rb', line 25

def deliver(message)
  connection = Faraday.new
  connection.token_auth @delivery_options.delivery_token

  connection.post do |request|
    request.url @delivery_options.delivery_url
    request.body = message
    # request.options[:timeout] = 3
    # request.headers['Content-Type'] = 'text/plain'
  end

  true
end