Sha256: c91ce78436a5b0a4f58453e60788cbde6ddc041245414c09508569daac39fa8e

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

module ActionTexter
  class WhitelistProxyDelivery
    class BlockedDelivery < StandardError; end
    attr_reader :delivery_method, :whitelist

    def initialize(config = {})
      @delivery_method = config[:delivery_method]
      @whitelist = config[:whitelist]
      raise ArgumentError, "you must specify config.action_texter.whitelist_proxy_settings to contain a :delivery_method" unless @delivery_method
      raise ArgumentError, "you must specify config.action_texter.whitelist_proxy_settings to contain a :whitelist" unless @whitelist
    end

    def deliver(message)
      raise BlockedDelivery if blocked?(message.to)

      real_delivery_method.deliver(message)
    end

    protected

    def blocked?(to)
      !whitelist.include?(to.to_s)
    end

    def real_delivery_method
      @real_delivery_method ||= begin
        settings = ActionTexter::Base.send(:"#{self.delivery_method}_settings")
        ActionTexter::Base.delivery_methods[self.delivery_method].new(settings)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actiontexter-0.1.0 lib/action_texter/whitelist_proxy_delivery.rb