mailgun 0.5 → 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/Gemfile +1 -3
 - data/README.md +145 -124
 - data/lib/mailgun.rb +1 -0
 - data/lib/mailgun/base.rb +18 -13
 - data/lib/mailgun/bounce.rb +14 -15
 - data/lib/mailgun/complaint.rb +20 -19
 - data/lib/mailgun/list.rb +14 -24
 - data/lib/mailgun/list/member.rb +25 -29
 - data/lib/mailgun/log.rb +6 -9
 - data/lib/mailgun/mailbox.rb +20 -20
 - data/lib/mailgun/{mail.rb → message.rb} +13 -5
 - data/lib/mailgun/route.rb +2 -2
 - data/lib/mailgun/unsubscribe.rb +13 -17
 - data/mailgun.gemspec +4 -1
 - data/spec/bounce_spec.rb +19 -12
 - data/spec/complaint_spec.rb +70 -23
 - data/spec/list/member_spec.rb +33 -22
 - data/spec/list/message_spec.rb +40 -0
 - data/spec/list_spec.rb +18 -18
 - data/spec/log_spec.rb +6 -3
 - data/spec/mailbox_spec.rb +23 -17
 - data/spec/route_spec.rb +39 -16
 - data/spec/unsubscribe_spec.rb +31 -21
 - metadata +42 -19
 
    
        data/lib/mailgun/list.rb
    CHANGED
    
    | 
         @@ -1,22 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailgun
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              # Mailing List functionality
         
     | 
| 
      
 4 
     | 
    
         
            +
              # Refer http://documentation.mailgun.net/api-mailinglists.html for optional parameters
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              class MailingList
         
     | 
| 
       3 
7 
     | 
    
         
             
                # Used internally, called from Mailgun::Base
         
     | 
| 
       4 
8 
     | 
    
         
             
                def initialize(mailgun)
         
     | 
| 
       5 
9 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
       6 
10 
     | 
    
         
             
                end
         
     | 
| 
       7 
     | 
    
         
            -
                
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                ## List functionality
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                # TODO add default domain functionality for the address names of lists
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                # List all mailing lists 
         
     | 
| 
       14 
     | 
    
         
            -
                def all
         
     | 
| 
       15 
     | 
    
         
            -
                  response = Mailgun.submit :get, list_url
         
     | 
| 
       16 
11 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
      
 12 
     | 
    
         
            +
                # List all mailing lists
         
     | 
| 
      
 13 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 14 
     | 
    
         
            +
                  response = Mailgun.submit(:get, list_url, options)["items"] || []
         
     | 
| 
       20 
15 
     | 
    
         
             
                end
         
     | 
| 
       21 
16 
     | 
    
         | 
| 
       22 
17 
     | 
    
         
             
                # List a single mailing list by a given address
         
     | 
| 
         @@ -25,21 +20,16 @@ module Mailgun 
     | 
|
| 
       25 
20 
     | 
    
         
             
                end
         
     | 
| 
       26 
21 
     | 
    
         | 
| 
       27 
22 
     | 
    
         
             
                # Create a mailing list with a given address
         
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
                def create(address, name=nil, description=nil)
         
     | 
| 
      
 23 
     | 
    
         
            +
                def create(address, options={})
         
     | 
| 
       30 
24 
     | 
    
         
             
                	params = {:address => address}
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                	params[:description] = description if description
         
     | 
| 
       33 
     | 
    
         
            -
                  Mailgun.submit :post, list_url, params
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Mailgun.submit :post, list_url, params.merge(options)
         
     | 
| 
       34 
26 
     | 
    
         
             
                end
         
     | 
| 
       35 
27 
     | 
    
         | 
| 
       36 
28 
     | 
    
         
             
                # Update a mailing list with a given address
         
     | 
| 
       37 
29 
     | 
    
         
             
                # with an optional new address, name or description
         
     | 
| 
       38 
     | 
    
         
            -
                def update(address, new_address,  
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                	params[:description] = description if description
         
     | 
| 
       42 
     | 
    
         
            -
                  Mailgun.submit :put, list_url(address), params
         
     | 
| 
      
 30 
     | 
    
         
            +
                def update(address, new_address, options={})
         
     | 
| 
      
 31 
     | 
    
         
            +
                  params = {:address => new_address}
         
     | 
| 
      
 32 
     | 
    
         
            +
                  Mailgun.submit :put, list_url(address), params.merge(options)
         
     | 
| 
       43 
33 
     | 
    
         
             
                end		
         
     | 
| 
       44 
34 
     | 
    
         | 
| 
       45 
35 
     | 
    
         
             
                # Deletes a mailing list with a given address
         
     | 
| 
         @@ -55,5 +45,5 @@ module Mailgun 
     | 
|
| 
       55 
45 
     | 
    
         
             
                  "#{@mailgun.base_url}/lists#{'/' + address if address}"
         
     | 
| 
       56 
46 
     | 
    
         
             
                end
         
     | 
| 
       57 
47 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
       59 
49 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mailgun/list/member.rb
    CHANGED
    
    | 
         @@ -1,56 +1,52 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailgun
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
      
 2 
     | 
    
         
            +
              # List Member functionality
         
     | 
| 
      
 3 
     | 
    
         
            +
              # Refer Mailgun docs for optional params
         
     | 
| 
      
 4 
     | 
    
         
            +
              class MailingList::Member
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       3 
6 
     | 
    
         
             
                # Used internally, called from Mailgun::Base
         
     | 
| 
       4 
     | 
    
         
            -
                def initialize(mailgun)
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize(mailgun, address)
         
     | 
| 
       5 
8 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @address = address
         
     | 
| 
       6 
10 
     | 
    
         
             
                end
         
     | 
| 
       7 
     | 
    
         
            -
                
         
     | 
| 
       8 
     | 
    
         
            -
                ## List Member functionality
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
                # List all mailing list members
         
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  response = Mailgun.submit :get, list_member_url(address)
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  if response
         
     | 
| 
       16 
     | 
    
         
            -
                    response["items"].collect {|item| item["address"]}
         
     | 
| 
       17 
     | 
    
         
            -
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 14 
     | 
    
         
            +
                  response = Mailgun.submit(:get, list_member_url, options)["items"]
         
     | 
| 
       18 
15 
     | 
    
         
             
                end
         
     | 
| 
       19 
16 
     | 
    
         | 
| 
       20 
17 
     | 
    
         
             
                # List a single mailing list member by a given address
         
     | 
| 
       21 
     | 
    
         
            -
                def find( 
     | 
| 
       22 
     | 
    
         
            -
                  Mailgun.submit :get, list_member_url( 
     | 
| 
      
 18 
     | 
    
         
            +
                def find(member_address)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Mailgun.submit :get, list_member_url(member_address)
         
     | 
| 
       23 
20 
     | 
    
         
             
                end
         
     | 
| 
       24 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       25 
23 
     | 
    
         
             
                # Adds a mailing list member with a given address
         
     | 
| 
       26 
     | 
    
         
            -
                #  
     | 
| 
       27 
     | 
    
         
            -
                def add( 
     | 
| 
       28 
     | 
    
         
            -
                  params = {:address => member_address 
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
                  params[:vars] = vars unless vars.empty?
         
     | 
| 
       31 
     | 
    
         
            -
                  Mailgun.submit :post, list_member_url(address), params
         
     | 
| 
      
 24 
     | 
    
         
            +
                # NOTE Use create instead of add?
         
     | 
| 
      
 25 
     | 
    
         
            +
                def add(member_address, options={})
         
     | 
| 
      
 26 
     | 
    
         
            +
                  params = {:address => member_address}
         
     | 
| 
      
 27 
     | 
    
         
            +
                  Mailgun.submit :post, list_member_url, params.merge(options)
         
     | 
| 
       32 
28 
     | 
    
         
             
                end
         
     | 
| 
       33 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
                # TODO add spec?
         
     | 
| 
      
 31 
     | 
    
         
            +
                alias_method :create, :add
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
       34 
33 
     | 
    
         
             
                # Update a mailing list member with a given address
         
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
                  params[:name] = name if name
         
     | 
| 
       39 
     | 
    
         
            -
                  params[:vars] = vars unless vars.empty?
         
     | 
| 
       40 
     | 
    
         
            -
                  Mailgun.submit :put, list_member_url(address, member_address), params
         
     | 
| 
      
 34 
     | 
    
         
            +
                def update(member_address, options={})
         
     | 
| 
      
 35 
     | 
    
         
            +
                  params = {:address => member_address}
         
     | 
| 
      
 36 
     | 
    
         
            +
                  Mailgun.submit :put, list_member_url(member_address), params.merge(options)
         
     | 
| 
       41 
37 
     | 
    
         
             
                end   
         
     | 
| 
       42 
38 
     | 
    
         | 
| 
       43 
39 
     | 
    
         
             
                # Deletes a mailing list member with a given address
         
     | 
| 
       44 
     | 
    
         
            -
                def remove( 
     | 
| 
       45 
     | 
    
         
            -
                  Mailgun.submit :delete, list_member_url( 
     | 
| 
      
 40 
     | 
    
         
            +
                def remove(member_address)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Mailgun.submit :delete, list_member_url(member_address)
         
     | 
| 
       46 
42 
     | 
    
         
             
                end
         
     | 
| 
       47 
43 
     | 
    
         | 
| 
       48 
44 
     | 
    
         | 
| 
       49 
45 
     | 
    
         
             
                private
         
     | 
| 
       50 
46 
     | 
    
         | 
| 
       51 
47 
     | 
    
         
             
                # Helper method to generate the proper url for Mailgun mailbox API calls
         
     | 
| 
       52 
     | 
    
         
            -
                def list_member_url( 
     | 
| 
       53 
     | 
    
         
            -
                  "#{@mailgun.base_url}/lists#{'/' + address}/members#{'/' + member_address if member_address}"
         
     | 
| 
      
 48 
     | 
    
         
            +
                def list_member_url(member_address=nil)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  "#{@mailgun.base_url}/lists#{'/' + @address}/members#{'/' + member_address if member_address}"
         
     | 
| 
       54 
50 
     | 
    
         
             
                end
         
     | 
| 
       55 
51 
     | 
    
         | 
| 
       56 
52 
     | 
    
         
             
              end
         
     | 
    
        data/lib/mailgun/log.rb
    CHANGED
    
    | 
         @@ -1,25 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailgun
         
     | 
| 
       2 
2 
     | 
    
         
             
            	class Log
         
     | 
| 
       3 
3 
     | 
    
         
             
                # Used internally, called from Mailgun::Base
         
     | 
| 
       4 
     | 
    
         
            -
                def initialize(mailgun)
         
     | 
| 
      
 4 
     | 
    
         
            +
                def initialize(mailgun, domain)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @domain = domain
         
     | 
| 
       6 
7 
     | 
    
         
             
                end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
                # List all logs for a given domain
         
     | 
| 
       9 
10 
     | 
    
         
             
                # * domain the domain for which all complaints will listed
         
     | 
| 
       10 
     | 
    
         
            -
                def list( 
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  if response
         
     | 
| 
       14 
     | 
    
         
            -
                    response["items"].collect {|item| item["message"]}
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Mailgun.submit(:get, log_url, options)
         
     | 
| 
       16 
13 
     | 
    
         
             
                end
         
     | 
| 
       17 
14 
     | 
    
         | 
| 
       18 
15 
     | 
    
         
             
                private
         
     | 
| 
       19 
16 
     | 
    
         | 
| 
       20 
17 
     | 
    
         
             
                # Helper method to generate the proper url for Mailgun complaints API calls
         
     | 
| 
       21 
     | 
    
         
            -
                def log_url 
     | 
| 
       22 
     | 
    
         
            -
                  "#{@mailgun.base_url}/#{domain}/log"
         
     | 
| 
      
 18 
     | 
    
         
            +
                def log_url
         
     | 
| 
      
 19 
     | 
    
         
            +
                  "#{@mailgun.base_url}/#{@domain}/log"
         
     | 
| 
       23 
20 
     | 
    
         
             
                end
         
     | 
| 
       24 
21 
     | 
    
         | 
| 
       25 
22 
     | 
    
         
             
            	end
         
     | 
    
        data/lib/mailgun/mailbox.rb
    CHANGED
    
    | 
         @@ -2,49 +2,49 @@ module Mailgun 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Mailbox
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
                # Used internally, called from Mailgun::Base
         
     | 
| 
       5 
     | 
    
         
            -
                def initialize(mailgun)
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(mailgun, domain)
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @domain  = domain
         
     | 
| 
       7 
8 
     | 
    
         
             
                end
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                # List all mailboxes for a given domain
         
     | 
| 
       10 
11 
     | 
    
         
             
                # * domain the domain for which all mailboxes will listed
         
     | 
| 
       11 
     | 
    
         
            -
                def list( 
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                  if response
         
     | 
| 
       15 
     | 
    
         
            -
                    response["items"].collect {|item| item["mailbox"]}
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 13 
     | 
    
         
            +
                  Mailgun.submit(:get, mailbox_url, options)["items"]
         
     | 
| 
       17 
14 
     | 
    
         
             
                end
         
     | 
| 
       18 
15 
     | 
    
         | 
| 
       19 
16 
     | 
    
         | 
| 
       20 
17 
     | 
    
         
             
                # Creates a mailbox on the Mailgun server with the given password
         
     | 
| 
       21 
     | 
    
         
            -
                def create( 
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
                   
     | 
| 
      
 18 
     | 
    
         
            +
                def create(mailbox_name, password)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  address = "#{mailbox_name}@#{@domain}"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  Mailgun.submit(
         
     | 
| 
      
 21 
     | 
    
         
            +
                    :post,
         
     | 
| 
      
 22 
     | 
    
         
            +
                    mailbox_url,
         
     | 
| 
      
 23 
     | 
    
         
            +
                    {
         
     | 
| 
      
 24 
     | 
    
         
            +
                      :mailbox => address,
         
     | 
| 
      
 25 
     | 
    
         
            +
                      :password => password
         
     | 
| 
      
 26 
     | 
    
         
            +
                    }
         
     | 
| 
      
 27 
     | 
    
         
            +
                  )
         
     | 
| 
       24 
28 
     | 
    
         
             
                end
         
     | 
| 
       25 
29 
     | 
    
         | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
31 
     | 
    
         
             
                # Sets the password for a mailbox
         
     | 
| 
       28 
     | 
    
         
            -
                def update_password( 
     | 
| 
       29 
     | 
    
         
            -
                  mailbox_name,  
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  Mailgun.submit :put, mailbox_url(domain, mailbox_name), :password => password
         
     | 
| 
      
 32 
     | 
    
         
            +
                def update_password(mailbox_name, password)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Mailgun.submit :put, mailbox_url(mailbox_name), :password => password
         
     | 
| 
       32 
34 
     | 
    
         
             
                end
         
     | 
| 
       33 
35 
     | 
    
         | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
37 
     | 
    
         
             
                # Destroys the mailbox
         
     | 
| 
       36 
     | 
    
         
            -
                def destroy( 
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  Mailgun.submit :delete,  mailbox_url(domain, mailbox_name)
         
     | 
| 
      
 38 
     | 
    
         
            +
                def destroy(mailbox_name)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Mailgun.submit :delete, mailbox_url(mailbox_name)
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                private
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                # Helper method to generate the proper url for Mailgun mailbox API calls
         
     | 
| 
       46 
     | 
    
         
            -
                def mailbox_url( 
     | 
| 
       47 
     | 
    
         
            -
                  "#{@mailgun.base_url}/#{domain}/mailboxes#{'/' + mailbox_name if mailbox_name}"
         
     | 
| 
      
 46 
     | 
    
         
            +
                def mailbox_url(mailbox_name=nil)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  "#{@mailgun.base_url}/#{@domain}/mailboxes#{'/' + mailbox_name if mailbox_name}"
         
     | 
| 
       48 
48 
     | 
    
         
             
                end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailgun
         
     | 
| 
       2 
     | 
    
         
            -
              class  
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                def initialize(mailgun)
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Message
         
     | 
| 
      
 3 
     | 
    
         
            +
                def initialize(mailgun, domain)
         
     | 
| 
       5 
4 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
      
 5 
     | 
    
         
            +
                  @domain  = domain
         
     | 
| 
       6 
6 
     | 
    
         
             
                end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                # send email
         
     | 
| 
       9 
     | 
    
         
            -
                def send_email()
         
     | 
| 
       10 
     | 
    
         
            -
                  #  
     | 
| 
      
 9 
     | 
    
         
            +
                def send_email(parameters={})
         
     | 
| 
      
 10 
     | 
    
         
            +
                  # options:
         
     | 
| 
       11 
11 
     | 
    
         
             
                  # :from, :to, :cc, :bcc, :subject, :text, :html 
         
     | 
| 
       12 
12 
     | 
    
         
             
                  # :with_attachment
         
     | 
| 
       13 
13 
     | 
    
         
             
                  # :with_attachments
         
     | 
| 
         @@ -15,6 +15,14 @@ module Mailgun 
     | 
|
| 
       15 
15 
     | 
    
         
             
                  # :in_test_mode BOOL. override the @use_test_mode setting
         
     | 
| 
       16 
16 
     | 
    
         
             
                  # :tags to add tags to the email
         
     | 
| 
       17 
17 
     | 
    
         
             
                  # :track BOOL
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Mailgun.submit(:post, messages_url, parameters)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                #private
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # Helper method to generate the proper url for Mailgun message API calls
         
     | 
| 
      
 24 
     | 
    
         
            +
                def messages_url
         
     | 
| 
      
 25 
     | 
    
         
            +
                  "#{@mailgun.base_url}/#{@domain}/messages"
         
     | 
| 
       18 
26 
     | 
    
         
             
                end
         
     | 
| 
       19 
27 
     | 
    
         
             
              end
         
     | 
| 
       20 
28 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mailgun/route.rb
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ module Mailgun 
     | 
|
| 
       5 
5 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
       6 
6 
     | 
    
         
             
                end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                def list( 
     | 
| 
       9 
     | 
    
         
            -
                  Mailgun.submit(:get, route_url,  
     | 
| 
      
 8 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 9 
     | 
    
         
            +
                  Mailgun.submit(:get, route_url, options)["items"] || []
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                def find(route_id)
         
     | 
    
        data/lib/mailgun/unsubscribe.rb
    CHANGED
    
    | 
         @@ -1,37 +1,33 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailgun
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Unsubscribe
         
     | 
| 
       3 
3 
     | 
    
         
             
                # Used internally, called from Mailgun::Base
         
     | 
| 
       4 
     | 
    
         
            -
                def initialize(mailgun)
         
     | 
| 
      
 4 
     | 
    
         
            +
                def initialize(mailgun, domain)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  @mailgun = mailgun
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @domain  = domain
         
     | 
| 
       6 
7 
     | 
    
         
             
                end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                # List all unsubscribes for  
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                  response = Mailgun.submit :get, unsubscribe_url(domain)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  if response
         
     | 
| 
       14 
     | 
    
         
            -
                    response["items"].collect {|item| item["address"]}
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
                # List all unsubscribes for the domain
         
     | 
| 
      
 10 
     | 
    
         
            +
                def list(options={})
         
     | 
| 
      
 11 
     | 
    
         
            +
                  Mailgun.submit(:get, unsubscribe_url, options)["items"]
         
     | 
| 
       16 
12 
     | 
    
         
             
                end
         
     | 
| 
       17 
13 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                def find( 
     | 
| 
       19 
     | 
    
         
            -
                  Mailgun.submit :get, unsubscribe_url( 
     | 
| 
      
 14 
     | 
    
         
            +
                def find(email)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  Mailgun.submit :get, unsubscribe_url(email)
         
     | 
| 
       20 
16 
     | 
    
         
             
                end
         
     | 
| 
       21 
17 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                def add(email,  
     | 
| 
       23 
     | 
    
         
            -
                  Mailgun.submit :post, unsubscribe_url 
     | 
| 
      
 18 
     | 
    
         
            +
                def add(email, tag='*')
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Mailgun.submit :post, unsubscribe_url, {:address => email, :tag => tag}
         
     | 
| 
       24 
20 
     | 
    
         
             
                end
         
     | 
| 
       25 
21 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                def remove( 
     | 
| 
       27 
     | 
    
         
            -
                  Mailgun.submit :delete, unsubscribe_url( 
     | 
| 
      
 22 
     | 
    
         
            +
                def remove(email)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Mailgun.submit :delete, unsubscribe_url(email)
         
     | 
| 
       28 
24 
     | 
    
         
             
                end
         
     | 
| 
       29 
25 
     | 
    
         | 
| 
       30 
26 
     | 
    
         
             
                private
         
     | 
| 
       31 
27 
     | 
    
         | 
| 
       32 
28 
     | 
    
         
             
                # Helper method to generate the proper url for Mailgun unsubscribe API calls
         
     | 
| 
       33 
     | 
    
         
            -
                def unsubscribe_url( 
     | 
| 
       34 
     | 
    
         
            -
                  "#{@mailgun.base_url}/#{domain}/unsubscribes#{'/' + address if address}"
         
     | 
| 
      
 29 
     | 
    
         
            +
                def unsubscribe_url(address=nil)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  "#{@mailgun.base_url}/#{@domain}/unsubscribes#{'/' + address if address}"
         
     | 
| 
       35 
31 
     | 
    
         
             
                end
         
     | 
| 
       36 
32 
     | 
    
         | 
| 
       37 
33 
     | 
    
         
             
              end
         
     | 
    
        data/mailgun.gemspec
    CHANGED
    
    | 
         @@ -12,8 +12,11 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       12 
12 
     | 
    
         
             
              gem.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         
     | 
| 
       13 
13 
     | 
    
         
             
              gem.name          = "mailgun"
         
     | 
| 
       14 
14 
     | 
    
         
             
              gem.require_paths = ["lib"]
         
     | 
| 
       15 
     | 
    
         
            -
              gem.version       = "0. 
     | 
| 
      
 15 
     | 
    
         
            +
              gem.version       = "0.6"
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              gem.add_dependency(%q<rest-client>, [">= 0"])
         
     | 
| 
       18 
18 
     | 
    
         
             
              gem.add_dependency(%q<multimap>, [">= 0"])
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              gem.add_development_dependency(%q<rspec>, [">= 2"])
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.add_development_dependency(%q<debugger>, [">= 0"])
         
     | 
| 
       19 
22 
     | 
    
         
             
            end
         
     | 
    
        data/spec/bounce_spec.rb
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ describe Mailgun::Bounce do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              before :each do
         
     | 
| 
       6 
6 
     | 
    
         
             
                @mailgun = Mailgun({:api_key => "api-key"})		# used to get the default values
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                @ 
     | 
| 
      
 8 
     | 
    
         
            +
                @sample = {
         
     | 
| 
       9 
9 
     | 
    
         
             
                  :email  => "test@sample.mailgun.org",
         
     | 
| 
       10 
10 
     | 
    
         
             
                  :name   => "test",
         
     | 
| 
       11 
11 
     | 
    
         
             
                  :domain => "sample.mailgun.org"
         
     | 
| 
         @@ -15,32 +15,39 @@ describe Mailgun::Bounce do 
     | 
|
| 
       15 
15 
     | 
    
         
             
              describe "list bounces" do
         
     | 
| 
       16 
16 
     | 
    
         
             
                it "should make a GET request with the right params" do
         
     | 
| 
       17 
17 
     | 
    
         
             
                  sample_response = "{\"items\": [{\"size_bytes\": 0,  \"mailbox\": \"postmaster@bsample.mailgun.org\" }  ]}"
         
     | 
| 
       18 
     | 
    
         
            -
                   
     | 
| 
      
 18 
     | 
    
         
            +
                  bounces_url = @mailgun.bounces(@sample[:domain]).send(:bounce_url)
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  Mailgun.should_receive(:submit).
         
     | 
| 
      
 21 
     | 
    
         
            +
                    with(:get, bounces_url, {}).
         
     | 
| 
      
 22 
     | 
    
         
            +
                    and_return(sample_response)
         
     | 
| 
       19 
23 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                  @mailgun.bounces 
     | 
| 
      
 24 
     | 
    
         
            +
                  @mailgun.bounces(@sample[:domain]).list
         
     | 
| 
       21 
25 
     | 
    
         
             
                end
         
     | 
| 
       22 
26 
     | 
    
         
             
              end
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
              describe "find bounces" do
         
     | 
| 
       25 
29 
     | 
    
         
             
                it "should make a GET request with correct params to find given email address" do
         
     | 
| 
       26 
30 
     | 
    
         
             
                  sample_response = "{\"items\": [{\"size_bytes\": 0,  \"mailbox\": \"postmaster@bsample.mailgun.org\" }  ]}"
         
     | 
| 
       27 
     | 
    
         
            -
                   
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  . 
     | 
| 
      
 31 
     | 
    
         
            +
                  bounces_url = @mailgun.bounces(@sample[:domain]).send(:bounce_url, @sample[:email])
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  Mailgun.should_receive(:submit).
         
     | 
| 
      
 34 
     | 
    
         
            +
                    with(:get, bounces_url).
         
     | 
| 
      
 35 
     | 
    
         
            +
                    and_return(sample_response)
         
     | 
| 
       30 
36 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                  @mailgun.bounces 
     | 
| 
      
 37 
     | 
    
         
            +
                  @mailgun.bounces(@sample[:domain]).find(@sample[:email])
         
     | 
| 
       32 
38 
     | 
    
         
             
                end
         
     | 
| 
       33 
39 
     | 
    
         
             
              end
         
     | 
| 
       34 
40 
     | 
    
         | 
| 
       35 
41 
     | 
    
         
             
              describe "add bounces" do
         
     | 
| 
       36 
42 
     | 
    
         
             
                it "should make a POST request with correct params to add a given email address" do
         
     | 
| 
       37 
     | 
    
         
            -
                  #sample_response = "{\"message\"=>\"Address has been added to the bounces table\", \"address\"=>\"#{@bounce_options[:email]}\"}"
         
     | 
| 
       38 
43 
     | 
    
         
             
                  sample_response = "{\"items\": [{\"size_bytes\": 0,  \"mailbox\": \"postmaster@bsample.mailgun.org\" }  ]}"
         
     | 
| 
       39 
     | 
    
         
            -
                   
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                  . 
     | 
| 
      
 44 
     | 
    
         
            +
                  bounces_url = @mailgun.bounces(@sample[:domain]).send(:bounce_url)
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  Mailgun.should_receive(:submit).
         
     | 
| 
      
 47 
     | 
    
         
            +
                    with(:post, bounces_url, {:address => @sample[:email]} ).
         
     | 
| 
      
 48 
     | 
    
         
            +
                    and_return(sample_response)
         
     | 
| 
       42 
49 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                  @mailgun.bounces 
     | 
| 
      
 50 
     | 
    
         
            +
                  @mailgun.bounces(@sample[:domain]).add(@sample[:email])
         
     | 
| 
       44 
51 
     | 
    
         
             
                end
         
     | 
| 
       45 
52 
     | 
    
         
             
              end
         
     | 
| 
       46 
53 
     | 
    
         | 
    
        data/spec/complaint_spec.rb
    CHANGED
    
    | 
         @@ -3,9 +3,9 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Mailgun::Complaint do
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @mailgun = Mailgun({:api_key => "api-key"}) 
     | 
| 
      
 6 
     | 
    
         
            +
                @mailgun = Mailgun({:api_key => "api-key"})
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                @ 
     | 
| 
      
 8 
     | 
    
         
            +
                @sample = {
         
     | 
| 
       9 
9 
     | 
    
         
             
                  :email  => "test@sample.mailgun.org",
         
     | 
| 
       10 
10 
     | 
    
         
             
                  :name   => "test",
         
     | 
| 
       11 
11 
     | 
    
         
             
                  :domain => "sample.mailgun.org"
         
     | 
| 
         @@ -14,42 +14,89 @@ describe Mailgun::Complaint do 
     | 
|
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
              describe "list complaints" do
         
     | 
| 
       16 
16 
     | 
    
         
             
                it "should make a GET request with the right params" do
         
     | 
| 
       17 
     | 
    
         
            -
                  sample_response =  
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
                  sample_response = <<EOF
         
     | 
| 
      
 18 
     | 
    
         
            +
            {
         
     | 
| 
      
 19 
     | 
    
         
            +
              "total_count": 1,
         
     | 
| 
      
 20 
     | 
    
         
            +
              "items": [
         
     | 
| 
      
 21 
     | 
    
         
            +
                  {
         
     | 
| 
      
 22 
     | 
    
         
            +
                      "count": 2,
         
     | 
| 
      
 23 
     | 
    
         
            +
                      "created_at": "Tue, 15 Nov 2011 08:25:11 GMT",
         
     | 
| 
      
 24 
     | 
    
         
            +
                      "address": "romanto@profista.com"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  }
         
     | 
| 
      
 26 
     | 
    
         
            +
              ]
         
     | 
| 
      
 27 
     | 
    
         
            +
            }
         
     | 
| 
      
 28 
     | 
    
         
            +
            EOF
         
     | 
| 
       19 
29 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                  @mailgun.complaints 
     | 
| 
      
 30 
     | 
    
         
            +
                  complaints_url = @mailgun.complaints(@sample[:domain]).send(:complaint_url)
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  Mailgun.should_receive(:submit).
         
     | 
| 
      
 33 
     | 
    
         
            +
                    with(:get, complaints_url, {}).
         
     | 
| 
      
 34 
     | 
    
         
            +
                    and_return(sample_response)
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  @mailgun.complaints(@sample[:domain]).list
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              describe "add complaint" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                it "should make a POST request with correct params to add a given email address to complaint from a tag" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  sample_response = <<EOF
         
     | 
| 
      
 44 
     | 
    
         
            +
            {
         
     | 
| 
      
 45 
     | 
    
         
            +
              "message": "Address has been added to the complaints table",
         
     | 
| 
      
 46 
     | 
    
         
            +
              "address": "#{@sample[:email]}"
         
     | 
| 
      
 47 
     | 
    
         
            +
            }
         
     | 
| 
      
 48 
     | 
    
         
            +
            EOF
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  complaints_url = @mailgun.complaints(@sample[:domain]).send(:complaint_url)
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  Mailgun.should_receive(:submit)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    .with(:post, complaints_url, {:address => @sample[:email]})
         
     | 
| 
      
 54 
     | 
    
         
            +
                    .and_return(sample_response)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  @mailgun.complaints(@sample[:domain]).add(@sample[:email])
         
     | 
| 
       21 
57 
     | 
    
         
             
                end
         
     | 
| 
       22 
58 
     | 
    
         
             
              end
         
     | 
| 
       23 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       24 
61 
     | 
    
         
             
              describe "find complaint" do
         
     | 
| 
       25 
62 
     | 
    
         
             
                it "should make a GET request with the right params to find given email address" do
         
     | 
| 
       26 
     | 
    
         
            -
                  sample_response =  
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
      
 63 
     | 
    
         
            +
                  sample_response = <<EOF
         
     | 
| 
      
 64 
     | 
    
         
            +
            {
         
     | 
| 
      
 65 
     | 
    
         
            +
              "complaint": {
         
     | 
| 
      
 66 
     | 
    
         
            +
                  "count": 2,
         
     | 
| 
      
 67 
     | 
    
         
            +
                  "created_at": "Tue, 15 Nov 2011 08:25:11 GMT",
         
     | 
| 
      
 68 
     | 
    
         
            +
                  "address": "romanto@profista.com"
         
     | 
| 
      
 69 
     | 
    
         
            +
              }
         
     | 
| 
      
 70 
     | 
    
         
            +
            }
         
     | 
| 
      
 71 
     | 
    
         
            +
            EOF
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  complaints_url = @mailgun.complaints(@sample[:domain]).send(:complaint_url, @sample[:email])
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                  Mailgun.should_receive(:submit)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    .with(:get, complaints_url)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    .and_return(sample_response)
         
     | 
| 
       30 
78 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                  @mailgun.complaints 
     | 
| 
      
 79 
     | 
    
         
            +
                  @mailgun.complaints(@sample[:domain]).find(@sample[:email])
         
     | 
| 
       32 
80 
     | 
    
         
             
                end
         
     | 
| 
       33 
81 
     | 
    
         
             
              end
         
     | 
| 
       34 
82 
     | 
    
         | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
       35 
84 
     | 
    
         
             
              describe "delete complaint" do
         
     | 
| 
       36 
85 
     | 
    
         
             
                it "should make a DELETE request with correct params to remove a given email address" do
         
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
                  sample_response = <<EOF
         
     | 
| 
      
 87 
     | 
    
         
            +
            {
         
     | 
| 
      
 88 
     | 
    
         
            +
                "message": "Complaint event has been removed",
         
     | 
| 
      
 89 
     | 
    
         
            +
                "address": "#{@sample[:email]}"}"
         
     | 
| 
      
 90 
     | 
    
         
            +
            }
         
     | 
| 
      
 91 
     | 
    
         
            +
            EOF
         
     | 
| 
       41 
92 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
                  @mailgun.complaints 
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
                  complaints_url = @mailgun.complaints(@sample[:domain]).send(:complaint_url, @sample[:email])
         
     | 
| 
       45 
94 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
              describe "add complaint" do
         
     | 
| 
       47 
     | 
    
         
            -
                it "should make a POST request with correct params to add a given email address to complaint from a tag" do
         
     | 
| 
       48 
     | 
    
         
            -
                  response_message = "{\"message\"=>\"Address has been added to the complaints table\", \"address\"=>\"#{@complaint_options[:email]}\"}"
         
     | 
| 
       49 
95 
     | 
    
         
             
                  Mailgun.should_receive(:submit)
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 96 
     | 
    
         
            +
                    .with(:delete, complaints_url)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    .and_return(sample_response)
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                  @mailgun.complaints(@sample[:domain]).destroy(@sample[:email])
         
     | 
| 
       53 
100 
     | 
    
         
             
                end
         
     | 
| 
       54 
101 
     | 
    
         
             
              end
         
     | 
| 
       55 
102 
     | 
    
         |