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


39
40
41
42
# File 'lib/mail_room/delivery/postback.rb', line 39

def initialize(delivery_options)
  puts 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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mail_room/delivery/postback.rb', line 46

def deliver(message)
  connection = Faraday.new

  if @delivery_options.token_auth?
    connection.token_auth @delivery_options.token
  elsif @delivery_options.basic_auth?
    connection.basic_auth(
      @delivery_options.username,
      @delivery_options.password
    )
  end

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

  @delivery_options.logger.info({ delivery_method: 'Postback', action: 'message pushed', url: @delivery_options.url })
  true
end