lib/mailgun/client.rb in mailgun-ruby-1.1.5 vs lib/mailgun/client.rb in mailgun-ruby-1.1.6

- old
+ new

@@ -1,6 +1,7 @@ require 'mailgun/chains' +require 'mailgun/suppressions' require 'mailgun/exceptions/exceptions' module Mailgun # A Mailgun::Client object is used to communicate with the Mailgun API. It is a # wrapper around RestClient so you don't have to worry about the HTTP aspect @@ -42,18 +43,26 @@ # @return [Boolean] Is the client set in test mode? def test_mode? @test_mode end + # Provides a store of all the emails sent in test mode so you can check them. + # + # @return [Hash] + def self.deliveries + @@deliveries ||= [] + end + # Simple Message Sending # # @param [String] working_domain This is the domain you wish to send from. # @param [Hash] data This should be a standard Hash # containing required parameters for the requested resource. # @return [Mailgun::Response] A Mailgun::Response object. def send_message(working_domain, data) if test_mode? then + Mailgun::Client.deliveries << data return Response.from_hash( { :body => '{"id": "test-mode-mail@localhost", "message": "Queued. Thank you."}', :code => 200, } @@ -137,9 +146,17 @@ def delete(resource_path) response = @http_client[resource_path].delete Response.new(response) rescue => err raise communication_error err + end + + # Constructs a Suppressions client for the given domain. + # + # @param [String] domain Domain which suppressions requests will be made for + # @return [Mailgun::Suppressions] + def suppressions(domain) + Suppressions.new(self, domain) end private # Converts MIME string to file for easy uploading to API