Sha256: 252cedcc2e15681737139913fccfcfc0dcae20a50695eb91b375224f087112b3

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

require 'faraday'

module MailRoom
  module Delivery
    # Postback Delivery method
    # @author Tony Pitale
    class Postback
      Options = Struct.new(:delivery_url, :delivery_token) do
        def initialize(mailbox)
          delivery_url = mailbox.delivery_url || mailbox.delivery_options[:delivery_url]
          delivery_token = mailbox.delivery_token || mailbox.delivery_options[:delivery_token]

          super(delivery_url, delivery_token)
        end
      end

      # Build a new delivery, hold the delivery options
      # @param [MailRoom::Delivery::Postback::Options]
      def initialize(delivery_options)
        @delivery_options = delivery_options
      end

      # deliver the message using Faraday to the configured delivery_options url
      # @param message [String] the email message as a string, RFC822 format
      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mail_room-0.9.1 lib/mail_room/delivery/postback.rb
mail_room-0.9.0 lib/mail_room/delivery/postback.rb
mail_room-0.8.1 lib/mail_room/delivery/postback.rb
mail_room-0.8.0 lib/mail_room/delivery/postback.rb
mail_room-0.7.0 lib/mail_room/delivery/postback.rb
mail_room-0.6.1 lib/mail_room/delivery/postback.rb
mail_room-0.6.0 lib/mail_room/delivery/postback.rb
mail_room-0.5.2 lib/mail_room/delivery/postback.rb
mail_room-0.5.1 lib/mail_room/delivery/postback.rb
mail_room-0.5.0 lib/mail_room/delivery/postback.rb
mail_room-0.4.2 lib/mail_room/delivery/postback.rb
mail_room-0.4.1 lib/mail_room/delivery/postback.rb
mail_room-0.4.0 lib/mail_room/delivery/postback.rb