iron_mailer 0.0.7 → 0.0.8
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.
- data/lib/iron_mailer/send_email.rb +26 -7
- data/lib/iron_mailer/version.rb +1 -1
- data/payload.json +23 -0
- data/spec/iron_mailer/send_email_spec.rb +18 -12
- metadata +3 -2
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            require 'iron_cache'
         | 
| 2 2 | 
             
            class IronMailer::SendEmail
         | 
| 3 | 
            -
              attr_reader  :iron_mq_client, :iron_cache_client, :queue, :cache, :debug
         | 
| 3 | 
            +
              attr_reader  :iron_mq_client, :iron_cache_client, :queue, :cache, :debug, :delivery_method, :delivery_method_settings
         | 
| 4 4 |  | 
| 5 5 | 
             
              def initialize(options={})    
         | 
| 6 6 | 
             
                @iron_mq_client = IronMQ::Client.new(options['iron_mq'])
         | 
| @@ -9,14 +9,33 @@ class IronMailer::SendEmail | |
| 9 9 |  | 
| 10 10 | 
             
                @cache = @iron_cache_client.cache(options['iron_cache']['cache_name'])
         | 
| 11 11 | 
             
                @debug = options['debug']
         | 
| 12 | 
            -
             | 
| 12 | 
            +
             | 
| 13 13 | 
             
                  if options['delivery_method'].is_a?(Hash)
         | 
| 14 14 | 
             
                    delivery_method_hash = options['delivery_method']
         | 
| 15 | 
            -
                     | 
| 15 | 
            +
                    params = delivery_method_hash.values.first.clone
         | 
| 16 | 
            +
                    params.keys.each do |key|
         | 
| 17 | 
            +
                      params[(key.to_sym rescue key) || key] = params.delete(key)
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                    
         | 
| 20 | 
            +
                    @delivery_method=delivery_method_hash.keys.first.to_sym
         | 
| 21 | 
            +
                    @delivery_method_settings = params
         | 
| 16 22 | 
             
                  else
         | 
| 17 | 
            -
                    delivery_method | 
| 23 | 
            +
                    @delivery_method=options['delivery_method'].to_sym          
         | 
| 24 | 
            +
                    @delivery_method_settings={}
         | 
| 18 25 | 
             
                  end
         | 
| 19 | 
            -
             | 
| 26 | 
            +
             | 
| 27 | 
            +
                # Mail.defaults do
         | 
| 28 | 
            +
                #   if options['delivery_method'].is_a?(Hash)
         | 
| 29 | 
            +
                #     delivery_method_hash = options['delivery_method']
         | 
| 30 | 
            +
                #     params = delivery_method_hash.values.first.clone
         | 
| 31 | 
            +
                #     params.keys.each do |key|
         | 
| 32 | 
            +
                #       params[(key.to_sym rescue key) || key] = params.delete(key)
         | 
| 33 | 
            +
                #     end
         | 
| 34 | 
            +
                #     delivery_method delivery_method_hash.keys.first.to_sym, params
         | 
| 35 | 
            +
                #   else
         | 
| 36 | 
            +
                #     delivery_method options['delivery_method'].to_sym          
         | 
| 37 | 
            +
                #   end
         | 
| 38 | 
            +
                # end
         | 
| 20 39 | 
             
              end
         | 
| 21 40 |  | 
| 22 41 | 
             
              def split_email(source_email)
         | 
| @@ -32,7 +51,7 @@ class IronMailer::SendEmail | |
| 32 51 | 
             
                      cc source_email.cc
         | 
| 33 52 | 
             
                    end
         | 
| 34 53 | 
             
                    reply_to source_email.reply_to
         | 
| 35 | 
            -
                    
         | 
| 54 | 
            +
                    date source_email.date
         | 
| 36 55 | 
             
                    html_part do
         | 
| 37 56 | 
             
                      content_type  'text/html; charset=UTF-8'
         | 
| 38 57 | 
             
                      body source_email.html_part.body.to_s
         | 
| @@ -65,8 +84,8 @@ class IronMailer::SendEmail | |
| 65 84 | 
             
                    mails = self.split_email(source_email)
         | 
| 66 85 |  | 
| 67 86 | 
             
                    mails.each do |mail|
         | 
| 87 | 
            +
                      mail.delivery_method self.delivery_method, self.delivery_method_settings
         | 
| 68 88 | 
             
                      mail.deliver
         | 
| 69 | 
            -
                    
         | 
| 70 89 | 
             
                      self.cache.put(mail.message_id, self.extract_cache_info(mail).to_json)
         | 
| 71 90 | 
             
                    end
         | 
| 72 91 | 
             
                    message.delete
         | 
    
        data/lib/iron_mailer/version.rb
    CHANGED
    
    
    
        data/payload.json
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "debug": "true", 
         | 
| 3 | 
            +
                "delivery_method": {
         | 
| 4 | 
            +
                    "smtp": {
         | 
| 5 | 
            +
                        "address": "smtp.sendgrid.net", 
         | 
| 6 | 
            +
                        "authentication": "plain", 
         | 
| 7 | 
            +
                        "domain": "teamdriveaway.com", 
         | 
| 8 | 
            +
                        "password": "trucking2006", 
         | 
| 9 | 
            +
                        "port": 587, 
         | 
| 10 | 
            +
                        "user_name": "teamdriveaway"
         | 
| 11 | 
            +
                    }
         | 
| 12 | 
            +
                }, 
         | 
| 13 | 
            +
                "iron_cache": {
         | 
| 14 | 
            +
                    "cache_name": "development_email_cache", 
         | 
| 15 | 
            +
                    "project_id": "50a79df0a6498073e700560c", 
         | 
| 16 | 
            +
                    "token": "6P0Hr8umXZruKzS3SbKF1vuu1E8"
         | 
| 17 | 
            +
                }, 
         | 
| 18 | 
            +
                "iron_mq": {
         | 
| 19 | 
            +
                    "project_id": "511fb1f0d429792c50001158", 
         | 
| 20 | 
            +
                    "queue_name": "development_mail_queue", 
         | 
| 21 | 
            +
                    "token": "xv0iMDhbPB2xN5EaDH8CK4jAdQs"
         | 
| 22 | 
            +
                }
         | 
| 23 | 
            +
            }
         | 
| @@ -25,7 +25,8 @@ describe IronMailer::SendEmail do | |
| 25 25 |  | 
| 26 26 | 
             
                it "should allow setting of a test delivery_method" do
         | 
| 27 27 | 
             
                  IronMailer::SendEmail.new(@options.merge('delivery_method'=>'test'))
         | 
| 28 | 
            -
                   | 
| 28 | 
            +
                  @send_email.delivery_method.should == :smtp
         | 
| 29 | 
            +
                  @send_email.delivery_method_settings.class.should == Hash
         | 
| 29 30 | 
             
                end
         | 
| 30 31 |  | 
| 31 32 | 
             
                describe "iron_mq_client" do
         | 
| @@ -56,34 +57,38 @@ describe IronMailer::SendEmail do | |
| 56 57 | 
             
                    @send_email.cache.name.should == @options['iron_cache']['cache_name']
         | 
| 57 58 | 
             
                  end
         | 
| 58 59 | 
             
                end
         | 
| 59 | 
            -
             | 
| 60 | 
            +
                
         | 
| 61 | 
            +
                it "should set delivery_method" do
         | 
| 62 | 
            +
                   @send_email.delivery_method.should == @options['delivery_method'].keys.first.to_sym
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
                
         | 
| 60 65 | 
             
                describe "smtp_config" do
         | 
| 61 66 | 
             
                  it "should assign the address" do
         | 
| 62 | 
            -
                     | 
| 67 | 
            +
                    @send_email.delivery_method_settings[:address].should == @options['delivery_method']['smtp']['address']
         | 
| 63 68 | 
             
                  end
         | 
| 64 69 |  | 
| 65 70 | 
             
                  it "should assign the port" do
         | 
| 66 | 
            -
                     | 
| 71 | 
            +
                    @send_email.delivery_method_settings[:port] == @options['delivery_method']['smtp']['port']
         | 
| 67 72 | 
             
                  end
         | 
| 68 73 |  | 
| 69 74 | 
             
                  it "should assign the domain" do
         | 
| 70 | 
            -
                     | 
| 75 | 
            +
                    @send_email.delivery_method_settings[:domain] == @options['delivery_method']['smtp']['domain']
         | 
| 71 76 | 
             
                  end
         | 
| 72 77 |  | 
| 73 78 | 
             
                  it "should assign the user_name" do
         | 
| 74 | 
            -
                     | 
| 79 | 
            +
                    @send_email.delivery_method_settings[:user_name] == @options['delivery_method']['smtp']['user_name']
         | 
| 75 80 | 
             
                  end
         | 
| 76 81 |  | 
| 77 82 | 
             
                  it "should assign the password" do
         | 
| 78 | 
            -
                     | 
| 83 | 
            +
                    @send_email.delivery_method_settings[:password] == @options['delivery_method']['smtp']['password']
         | 
| 79 84 | 
             
                  end
         | 
| 80 85 |  | 
| 81 86 | 
             
                  it "should assign the authentication" do
         | 
| 82 | 
            -
                     | 
| 87 | 
            +
                    @send_email.delivery_method_settings[:authentication] == @options['delivery_method']['smtp']['authentication']
         | 
| 83 88 | 
             
                  end
         | 
| 84 89 |  | 
| 85 90 | 
             
                  it "should assign enable_starttls_auto" do
         | 
| 86 | 
            -
                     | 
| 91 | 
            +
                    @send_email.delivery_method_settings[:enable_starttls_auto] == @options['delivery_method']['smtp']['enable_starttls_auto']
         | 
| 87 92 | 
             
                  end
         | 
| 88 93 | 
             
                end
         | 
| 89 94 |  | 
| @@ -92,7 +97,7 @@ describe IronMailer::SendEmail do | |
| 92 97 | 
             
              def test_config
         | 
| 93 98 | 
             
                @iron_mq_config = JSON.parse(File.read('spec/config/iron_mq.json'))
         | 
| 94 99 | 
             
                @iron_cache_config = JSON.parse(File.read('spec/config/iron_cache.json'))
         | 
| 95 | 
            -
                {'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=> | 
| 100 | 
            +
                {'iron_mq'=>@iron_mq_config, 'iron_cache'=>@iron_cache_config.merge('cache_name'=>"test_email_cache"), 'delivery_method'=>'test', 'debug'=>false}
         | 
| 96 101 | 
             
              end
         | 
| 97 102 |  | 
| 98 103 | 
             
              def test_email(other_tos=[])
         | 
| @@ -147,13 +152,14 @@ describe IronMailer::SendEmail do | |
| 147 152 |  | 
| 148 153 | 
             
                it "should call deliver with on the results of split_email" do
         | 
| 149 154 | 
             
                  @test_email=test_email
         | 
| 155 | 
            +
                  @test_email.stub(:message_id).and_return(Time.now.to_f.to_s)
         | 
| 150 156 | 
             
                  @send_email.stub(:split_email).and_return([@test_email])
         | 
| 151 157 | 
             
                  @test_email.should_receive(:deliver)
         | 
| 152 158 | 
             
                  @execute.call
         | 
| 153 159 | 
             
                end
         | 
| 154 160 |  | 
| 155 161 | 
             
                it "should add the message back to the queue if there's an error " do
         | 
| 156 | 
            -
                  @send_email.queue.clear
         | 
| 162 | 
            +
                  @send_email.queue.clear if @send_email.cache.size > 0
         | 
| 157 163 | 
             
                  email = test_email
         | 
| 158 164 | 
             
                  email.to.clear
         | 
| 159 165 | 
             
                  class ErrorMailer
         | 
| @@ -211,7 +217,7 @@ describe IronMailer::SendEmail do | |
| 211 217 | 
             
                  @send_email.extract_cache_info(@test_email)['content'].should == @test_email.text_part.body.to_s
         | 
| 212 218 | 
             
                end
         | 
| 213 219 | 
             
              end
         | 
| 214 | 
            -
             | 
| 220 | 
            +
              
         | 
| 215 221 | 
             
              describe "split_email" do
         | 
| 216 222 | 
             
                before(:each) do
         | 
| 217 223 | 
             
                  @send_email = IronMailer::SendEmail.new(test_config)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: iron_mailer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.8
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-08- | 
| 12 | 
            +
            date: 2013-08-07 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         | 
| @@ -141,6 +141,7 @@ files: | |
| 141 141 | 
             
            - lib/iron_mailer/mq_mailer.rb
         | 
| 142 142 | 
             
            - lib/iron_mailer/send_email.rb
         | 
| 143 143 | 
             
            - lib/iron_mailer/version.rb
         | 
| 144 | 
            +
            - payload.json
         | 
| 144 145 | 
             
            - spec/iron_mailer/mq_mailer_spec.rb
         | 
| 145 146 | 
             
            - spec/iron_mailer/send_email_spec.rb
         | 
| 146 147 | 
             
            homepage: ''
         |