Skip to content

Instantly share code, notes, and snippets.

@temochka
Created May 4, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save temochka/1b228d60e76431ae6714 to your computer and use it in GitHub Desktop.
Save temochka/1b228d60e76431ae6714 to your computer and use it in GitHub Desktop.
class EmailBatch
attr_reader :messages
delegate :<<, to: :messages
def initialize(messages = [])
@messages = messages
end
def deliver_now
messages.each { |msg| Mail.inform_interceptors(msg) }
result = client.deliver_messages(messages)
messages.each { |msg| Mail.inform_observers(msg) }
result
end
def deliver_later
fail NotImplementedError, 'Delayed delivery is not implemented for batches.'
end
private
def client
Postmark::ApiClient.new(config[:api_key] || config[:api_token], config)
end
def config
ActionMailer::Base.postmark_settings
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment