mail-madmimi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.arcconfig ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "project_id": "mail-madmimi",
3
+ "conduit_uri": "http://phabricator.tagview.com.br",
4
+ "load": [
5
+ "libphutil/src"
6
+ ],
7
+ "base": "git:merge-base(origin/master)"
8
+ }
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: bundle exec rspec spec
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mail-mad_mimi.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mail-madmimi (0.0.1)
5
+ actionmailer (>= 4.0.0)
6
+ httparty (~> 0.13.0)
7
+ mail (>= 2.5.4)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (4.0.3)
13
+ actionpack (= 4.0.3)
14
+ mail (~> 2.5.4)
15
+ actionpack (4.0.3)
16
+ activesupport (= 4.0.3)
17
+ builder (~> 3.1.0)
18
+ erubis (~> 2.7.0)
19
+ rack (~> 1.5.2)
20
+ rack-test (~> 0.6.2)
21
+ activesupport (4.0.3)
22
+ i18n (~> 0.6, >= 0.6.4)
23
+ minitest (~> 4.2)
24
+ multi_json (~> 1.3)
25
+ thread_safe (~> 0.1)
26
+ tzinfo (~> 0.3.37)
27
+ atomic (1.1.14)
28
+ builder (3.1.4)
29
+ diff-lcs (1.2.5)
30
+ erubis (2.7.0)
31
+ httparty (0.13.0)
32
+ json (~> 1.8)
33
+ multi_xml (>= 0.5.2)
34
+ i18n (0.6.9)
35
+ json (1.8.1)
36
+ mail (2.5.4)
37
+ mime-types (~> 1.16)
38
+ treetop (~> 1.4.8)
39
+ mime-types (1.25.1)
40
+ minitest (4.7.5)
41
+ multi_json (1.8.4)
42
+ multi_xml (0.5.5)
43
+ polyglot (0.3.4)
44
+ rack (1.5.2)
45
+ rack-test (0.6.2)
46
+ rack (>= 1.0)
47
+ rspec (2.14.1)
48
+ rspec-core (~> 2.14.0)
49
+ rspec-expectations (~> 2.14.0)
50
+ rspec-mocks (~> 2.14.0)
51
+ rspec-core (2.14.7)
52
+ rspec-expectations (2.14.5)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.14.5)
55
+ thread_safe (0.1.3)
56
+ atomic
57
+ treetop (1.4.15)
58
+ polyglot
59
+ polyglot (>= 0.3.1)
60
+ tzinfo (0.3.38)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ mail-madmimi!
67
+ rspec (~> 2.14.1)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Guilherme Otranto Aulicino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ mail-madmimi
2
+ ==============
3
+ [![Build Status](https://travis-ci.org/guilherme-otran/mail-madmimi.png?branch=master)](https://travis-ci.org/guilherme-otran/mail-madmimi)
4
+ [![Dependency Status](https://gemnasium.com/guilherme-otran/mail-madmimi.png)](https://gemnasium.com/guilherme-otran/mail-madmimi)
5
+
6
+ Integration of Mad Mimi with ActionMailer (Tested with Rails 4)
7
+
8
+ ## Gemfile
9
+ gem "mail-madmimi"
10
+
11
+ ## Config
12
+ environments/production.rb, and/or development.rb if you want use it
13
+
14
+ config.action_mailer.delivery_method = :mad_mimi
15
+ config.action_mailer.mad_mimi_settings = {
16
+ :username => "someuser@example.org",
17
+ :api_key => "123456789012347890"
18
+ }
19
+
20
+ You might enable this inside production.rb / development
21
+ Remember, the MadMimi API uses HTTP POST requests that may fail
22
+
23
+ config.action_mailer.raise_delivery_errors = true
24
+
25
+ ## Mailers
26
+
27
+ Inside the mailer you can put the promotion_name [required for Mad Mimi]:
28
+
29
+ mail to: the_email_addresses, promotion_name: 'Promo 1', track_links: :off
30
+
31
+ 1. Required params
32
+ * to [String]
33
+ * promotion_name [String]
34
+ * view to be rendered [only html format supported]
35
+
36
+ 2. Optional params
37
+ ** Use only :on or :off for boolean params **
38
+ * subject [String]
39
+ The subject of the message, if this is omitted, Action Mailer will ask the Rails I18n class for a translated :subject in the scope of [mailer_scope, action_name] or if this is missing, will translate the humanized version of the action_name
40
+ * bcc [String]
41
+ * check_suppressed [:on or :off]
42
+ Checks if the recipient is suppressed and does not send if so (default: :off)
43
+ WARNING: This parameter must still be included if the transactional email includes an unsubscribe link.
44
+ * track_links [:on or :off]
45
+ Enable or disable link tracking in HTML promotions (default: :on).
46
+ * hidden [:on or :off]
47
+ Creates the promotion as a hidden promotion so as not to clutter up your web interface (default: :off).
48
+ * skip_placeholders [:on or :off]
49
+ If you would like Mimi to ignore any {placeholders} you can add this optional parameter (default: :off).
50
+ * remove_unsubscribe [:on or :off]
51
+ If you created the promotion using custom HTML on the website and would like Mimi to remove the unsubscribe link (default: :off).
52
+
53
+
54
+ ## Mailer view
55
+ And don't forget to place the mimi macros inside the view:
56
+
57
+ You must include either the [[tracking_beacon]] or [[peek_image]] macro (they are aliases). This is used for tracking opens.
58
+
59
+ You can also include a [[confirmation_link]] macro in the body of the mail. When it is used, the audience member you’re sending to will be suppressed until they click on the confirmation link in the mail.
60
+
61
+ ---
62
+ # That's all you need :)
@@ -0,0 +1,64 @@
1
+ require 'httparty'
2
+
3
+ module Mail
4
+ module Madmimi
5
+ class Sender
6
+ class MadmimiError < StandardError; end
7
+ attr_accessor :settings
8
+
9
+ include ::HTTParty
10
+ base_uri 'https://api.madmimi.com'
11
+
12
+ def initialize(settings = {})
13
+ unless settings[:username] && settings[:api_key]
14
+ raise MadmimiError, "Missing username or api_key"
15
+ end
16
+
17
+ self.settings = settings
18
+ end
19
+
20
+ def deliver!(mail)
21
+ resp = self.class.post '/mailer', body: email_post_body(mail)
22
+ parse_response(resp)
23
+ end
24
+
25
+ def parse_response(resp)
26
+ case resp.headers["status"]
27
+ when 200..299 then resp.parsed_response
28
+ else raise MadmimiError.new "status=#{resp.headers["status"]}; " + resp.parsed_response
29
+ end
30
+ end
31
+
32
+ def email_post_body(mail)
33
+ options = settings.merge(
34
+ recipients: mail[:to].to_s.gsub(",", ";"),
35
+ promotion_name: mail[:promotion_name].to_s,
36
+ subject: mail.subject.to_s,
37
+ raw_html: html_data(mail).to_s
38
+ )
39
+
40
+ options.merge!(from: mail[:from].to_s) unless mail[:from].to_s.empty?
41
+ options.merge!(bcc: mail[:bcc].to_s) unless mail[:bcc].to_s.empty?
42
+
43
+ boolean_params = [:check_suppressed, :track_links, :hidden,
44
+ :skip_placeholders, :remove_unsubscribe]
45
+
46
+ boolean_params.each do |param|
47
+ options.merge!(param => mail[param].to_s) unless mail[param].to_s.empty?
48
+ end
49
+
50
+ options
51
+ end
52
+
53
+ def html_data(mail)
54
+ html_data = mail.find_first_mime_type('text/html')
55
+
56
+ if html_data
57
+ html_data.body
58
+ else
59
+ mail.mime_type == 'text/html' ? mail.body : nil
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Mail
2
+ module Madmimi
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'mail/madmimi/version'
2
+ require 'mail/madmimi/sender'
3
+
4
+ module Mail
5
+ module Madmimi
6
+ ActionMailer::Base.add_delivery_method :mad_mimi, Mail::Madmimi::Sender
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mail/madmimi/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mail-madmimi"
8
+ s.version = Mail::Madmimi::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Guilherme Otranto"]
11
+ s.email = ["guilherme_otran@hotmail.com"]
12
+ s.summary = "A Mad Mimi Mail delivery for ActionMailer, Rails 4."
13
+ s.description = "ActionMailer send method for madmimi api"
14
+ s.homepage = "https://github.com/guilherme-otran/madmimi-rails4"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # This gem will work with 1.9.3 or greater...
22
+ s.required_ruby_version = '>= 1.9.3'
23
+ s.add_runtime_dependency "httparty", "~> 0.13.0"
24
+ s.add_runtime_dependency "mail", ">= 2.5.4"
25
+ s.add_runtime_dependency "actionmailer", ">= 4.0.0"
26
+ s.add_development_dependency "rspec", "~> 2.14.1"
27
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::Madmimi::Sender do
4
+ let(:valid_settings) { { username: "none@example.com", api_key: "1234567890" } }
5
+ let(:mimi_sender) { described_class.new valid_settings }
6
+ let(:email_basic_options) { { to: "somebody@example.org", promotion_name: "Promo", subject: "Hi" } }
7
+ let(:email) { TestMailer.test_mail(email_basic_options) }
8
+
9
+ context "Create without api key or username" do
10
+ it "raises an error" do
11
+ expect { described_class.new }.to raise_error Mail::Madmimi::Sender::MadmimiError
12
+ end
13
+ end
14
+
15
+ describe "#email_post_body" do
16
+ context "return a hash with mimi required attributes" do
17
+ it "promotion_name" do
18
+ mimi_sender.email_post_body(email)[:promotion_name].should == "Promo"
19
+ end
20
+
21
+ it "recipients" do
22
+ mimi_sender.email_post_body(email)[:recipients].should == "somebody@example.org"
23
+ end
24
+
25
+ it "raw_html" do
26
+ mimi_sender.email_post_body(email)[:raw_html].should == "Oi :P"
27
+ end
28
+
29
+ it "subject" do
30
+ mimi_sender.email_post_body(email)[:subject].should == "Hi"
31
+ end
32
+ end
33
+
34
+ context "optional string attributes" do
35
+ [:from, :bcc].each do |attribute|
36
+ it "include the #{attribute}" do
37
+ my_mail_options = email_basic_options.merge(attribute => attribute.to_s)
38
+ my_email = TestMailer.test_mail(my_mail_options)
39
+ mimi_sender.email_post_body(my_email)[attribute].should == attribute.to_s
40
+ end
41
+
42
+ it "not include #{attribute}" do
43
+ mimi_sender.email_post_body(email).should_not have_key(attribute)
44
+ end
45
+ end
46
+ end
47
+
48
+ context "optional boolean params" do
49
+ booleans = [:check_suppressed, :track_links, :hidden,
50
+ :skip_placeholders, :remove_unsubscribe]
51
+
52
+ booleans.each do |attribute|
53
+ [:on, :off].each do |boolean|
54
+ it "include the #{attribute} with #{boolean}" do
55
+ my_mail_options = email_basic_options.merge(attribute => boolean)
56
+ my_email = TestMailer.test_mail(my_mail_options)
57
+ mimi_sender.email_post_body(my_email)[attribute].should == boolean.to_s
58
+ end
59
+ end
60
+
61
+ it "not include #{attribute}" do
62
+ mimi_sender.email_post_body(email).should_not have_key(attribute)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#parse_response" do
69
+ context "Received a ok response" do
70
+ let(:ok_reponse) { CorrectResponse.new }
71
+
72
+ it { mimi_sender.parse_response(ok_reponse).should == "1234567890" }
73
+ end
74
+
75
+ context "Received a non ok response" do
76
+ let(:invalid_response) { IncorrectResponse.new }
77
+
78
+ it "raises an error" do
79
+ expect { mimi_sender.parse_response(invalid_response) }
80
+ .to raise_error Mail::Madmimi::Sender::MadmimiError
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#deliver!" do
86
+ it "posted the email" do
87
+ Mail::Madmimi::Sender.should_receive(:post).and_return(CorrectResponse.new)
88
+ mimi_sender.deliver!(email)
89
+ end
90
+
91
+ it "posted with correct path" do
92
+ Mail::Madmimi::Sender.should_receive(:post)
93
+ .with('/mailer', anything)
94
+ .and_return(CorrectResponse.new)
95
+ mimi_sender.deliver!(email)
96
+ end
97
+
98
+ it "posted with correct body" do
99
+ Mail::Madmimi::Sender.should_receive(:post)
100
+ .with(anything, body: mimi_sender.email_post_body(email))
101
+ .and_return(CorrectResponse.new)
102
+ mimi_sender.deliver!(email)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::Madmimi, "ActionMailer load process" do
4
+ it "registers as delivery method" do
5
+ ActionMailer::Base.delivery_methods[:mad_mimi].should == Mail::Madmimi::Sender
6
+ end
7
+ end
8
+
9
+ describe Mail::Madmimi, "ActionMailer integration process" do
10
+ let(:email) { TestMailer.test_mail(promotion_name: "Bla", to: "hi@hi.com") }
11
+ let(:valid_settings) { { username: "none@example.com", api_key: "1234567890" } }
12
+
13
+ before do
14
+ ActionMailer::Base.delivery_method = :mad_mimi
15
+ ActionMailer::Base.mad_mimi_settings = valid_settings
16
+ end
17
+
18
+ it "Madmimi::Sender instance receives the mail to send after delivering it" do
19
+ Mail::Madmimi::Sender.any_instance.should_receive(:deliver!).with(email)
20
+ email.deliver
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ require 'action_mailer'
2
+ require 'mail/madmimi'
3
+
4
+ class TestMailer < ActionMailer::Base
5
+ def test_mail(params_to_test)
6
+ mail(params_to_test) do |format|
7
+ format.html { render(text: "Oi :P") }
8
+ end
9
+ end
10
+ end
11
+
12
+ class CorrectResponse
13
+ def headers
14
+ { "status" => 200 }
15
+ end
16
+
17
+ def parsed_response
18
+ # Transaction ID
19
+ "1234567890"
20
+ end
21
+ end
22
+
23
+ class IncorrectResponse
24
+ def headers
25
+ { "status" => 403 }
26
+ end
27
+
28
+ def parsed_response
29
+ "Not authorized"
30
+ end
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail-madmimi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guilherme Otranto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.13.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.13.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mail
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.4
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: actionmailer
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 4.0.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.14.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.14.1
78
+ description: ActionMailer send method for madmimi api
79
+ email:
80
+ - guilherme_otran@hotmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .arcconfig
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE
91
+ - README.md
92
+ - lib/mail/madmimi.rb
93
+ - lib/mail/madmimi/sender.rb
94
+ - lib/mail/madmimi/version.rb
95
+ - mail-madmimi.gemspec
96
+ - spec/mail/madmimi/sender_spec.rb
97
+ - spec/mail/madmimi_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/guilherme-otran/madmimi-rails4
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.9.3
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: A Mad Mimi Mail delivery for ActionMailer, Rails 4.
123
+ test_files:
124
+ - spec/mail/madmimi/sender_spec.rb
125
+ - spec/mail/madmimi_spec.rb
126
+ - spec/spec_helper.rb