Skip to content

Commit

Permalink
moved Mailgun::Base.submit to Mailgun.submit
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information
HashNuke committed Nov 18, 2011
1 parent 6a469d9 commit 754dd23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
31 changes: 16 additions & 15 deletions lib/mailgun/base.rb
Expand Up @@ -30,23 +30,24 @@ def base_url
def mailboxes
@mailboxes ||= Mailgun::Mailbox.new(self)
end
# Submits the API call to the Mailgun server
def self.submit(method, url, parameters={})
begin
return JSON(RestClient.send(method, url, parameters))
rescue => e
error_message = nil
if e.http_body
begin
error_message = JSON(e.http_body)["message"]
rescue
raise e
end
raise Mailgun::Error.new(error_message)
end


# Submits the API call to the Mailgun server
def self.submit(method, url, parameters={})
begin
return JSON(RestClient.send(method, url, parameters))
rescue => e
error_message = nil
if e.http_body
begin
error_message = JSON(e.http_body)["message"]
rescue
raise e
end
raise e
raise Mailgun::Error.new(error_message)
end
raise e
end
end
end
8 changes: 4 additions & 4 deletions lib/mailgun/mailbox.rb
Expand Up @@ -9,7 +9,7 @@ def initialize(mailgun)
# List all mailboxes for a given domain
# * domain the domain for which all mailboxes will listed
def list(domain)
response = Mailgun::Base.submit :get, mailbox_url(domain)
response = Mailgun.submit :get, mailbox_url(domain)

if response
response["items"].collect {|item| item["mailbox"]}
Expand All @@ -19,7 +19,7 @@ def list(domain)

# Creates a mailbox on the Mailgun server with the given password
def create(address, password)
Mailgun::Base.submit :post, mailbox_url(address.split("@").last), :mailbox => address,
Mailgun.submit :post, mailbox_url(address.split("@").last), :mailbox => address,
:password => password
end

Expand All @@ -28,15 +28,15 @@ def create(address, password)
def update_password(address, password)
mailbox_name, domain = address.split("@")

Mailgun::Base.submit :put, mailbox_url(domain, mailbox_name), :password => password
Mailgun.submit :put, mailbox_url(domain, mailbox_name), :password => password
end


# Destroys the mailbox
def destroy(address)
mailbox_name, domain = address.split("@")

Mailgun::Base.submit :delete, mailbox_url(domain, mailbox_name)
Mailgun.submit :delete, mailbox_url(domain, mailbox_name)
end


Expand Down

0 comments on commit 754dd23

Please sign in to comment.