lib/multi_mail/mailgun/sender.rb in multi_mail-0.1.0 vs lib/multi_mail/mailgun/sender.rb in multi_mail-0.1.1

- old
+ new

@@ -1,7 +1,5 @@ -require 'multi_mail/mailgun/message' - module MultiMail module Sender # Mailgun's outgoing mail sender. class Mailgun include MultiMail::Sender::Base @@ -12,10 +10,12 @@ # Initializes a Mailgun outgoing email sender. # # @param [Hash] options required and optional arguments # @option options [String] :api_key a Mailgun API key + # @option options [String] :domain the Mailgun email domain + # @see http://documentation.mailgun.com/api-intro.html#base-url def initialize(options = {}) super @api_key = settings.delete(:api_key) @domain = settings.delete(:domain) end @@ -60,20 +60,20 @@ response = connection.post("https://api.mailgun.net/v2/#{domain}/messages", message) case response.status when 401 raise InvalidAPIKey, response.body - when 400 + when 400, 404 body = JSON.load(response.body) case body['message'] when "'from' parameter is missing" raise MissingSender, body['message'] when "'to' parameter is missing" raise MissingRecipients, body['message'] when "Need at least one of 'text' or 'html' parameters specified" raise MissingBody, body['message'] else - raise InvalidMessage, body['message'] + raise InvalidRequest, body['message'] end when 200 body = JSON.load(response.body) else raise response.body