pling-actionmailer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ .rspec
4
+ .rvmrc
5
+ .yardoc/
6
+ doc/
7
+ Gemfile.lock
8
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - ruby-head
3
+ - 1.9.2
4
+ - 1.8.7
5
+ - ree
6
+ - jruby
7
+ - rbx
8
+ - rbx-2.0.0pre
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pling.gemspec
4
+ gemspec
5
+
6
+ gem 'pling', :path => '../pling'
7
+
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'growl_notify' if RUBY_PLATFORM =~ /darwin/
11
+ gem 'rdiscount', ">= 1.6.8", :platform => :ruby
data/Guardfile ADDED
@@ -0,0 +1,4 @@
1
+ guard 'rspec', :version => 2, :all_on_start => true, :all_after_pass => true do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 flinc AG
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Pling Gateway to ActionMailer
2
+
3
+ ## Requirements
4
+
5
+ * [Pling](https://github.com/flinc/pling)
6
+
7
+ ## Install
8
+
9
+ gem 'pling-actionmailer', :require => 'pling/gateways/action_mailer'
10
+
11
+ ## Usage
12
+
13
+
14
+
15
+
16
+ ## Build Status
17
+
18
+ pling-actionmailer is on [Travis](http://travis-ci.org/flinc/pling-actionmailer) running the specs on Ruby 1.8.7, Ruby Enterprise Edition, Ruby 1.9.2, Ruby HEAD, JRuby, Rubinius and Rubinius 2.
19
+
20
+
21
+ ## Known issues
22
+
23
+ See [the issue tracker on GitHub](https://github.com/flinc/pling-actionmailer/issues).
24
+
25
+
26
+ ## Repository
27
+
28
+ See [the repository on GitHub](https://github.com/flinc/pling-actionmailer) and feel free to fork it!
29
+
30
+
31
+ ## Contributors
32
+
33
+ See a list of all contributors on [GitHub](https://github.com/flinc/pling-actionmailer/contributors). Thanks a lot everyone!
34
+
35
+
36
+ ## Copyright
37
+
38
+ Copyright (c) 2011 [flinc AG](https://flinc.org/). See LICENSE for details.SE for details.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'yard'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ YARD::Rake::YardocTask.new(:doc)
9
+
10
+ task :default => :spec
11
+
12
+ desc "Open an irb session"
13
+ task :console do
14
+ sh "bundle exec irb -rubygems -I lib -r pling/gateway/action_mailer.rb"
15
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html>
4
+ <head>
5
+ <style type="text/css">
6
+ body { font-family: sans-serif; }
7
+ </style>
8
+ </head>
9
+ <body>
10
+ <%= @message.content %>
11
+ </body>
12
+ </html>
@@ -0,0 +1 @@
1
+ <%= @message.content %>
@@ -0,0 +1,48 @@
1
+ require 'pling'
2
+ require 'action_mailer'
3
+
4
+ module Pling
5
+ module Gateway
6
+ class ActionMailer < Base
7
+ class Mailer < ::ActionMailer::Base
8
+ append_view_path File.expand_path('../../../../app/views', __FILE__)
9
+
10
+ def pling_message(message, device, configuration)
11
+ @message, @device, @configuration = message, device, configuration
12
+
13
+ use_text = configuration.delete(:text)
14
+ use_html = configuration.delete(:html)
15
+
16
+ mail(configuration.merge(:to => device.identifier)) do |format|
17
+ format.text { render 'pling/mailer/pling_message' } if use_text
18
+ format.html { render 'pling/mailer/pling_message' } if use_html
19
+ end
20
+ end
21
+ end
22
+
23
+ handles :email, :mail, :actionmailer
24
+
25
+ def initialize(configuration)
26
+ setup_configuration(configuration, :require => [:from])
27
+ end
28
+
29
+ def deliver(message, device)
30
+ message = Pling._convert(message, :message)
31
+ device = Pling._convert(device, :device)
32
+
33
+ mailer = configuration[:mailer] || Pling::Gateway::ActionMailer::Mailer
34
+ mailer.pling_message(message, device, configuration).deliver
35
+ end
36
+
37
+ private
38
+
39
+ def default_configuration
40
+ {
41
+ :html => true,
42
+ :text => true
43
+ }
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "pling-actionmailer"
5
+ s.version = "0.1.0"
6
+ s.authors = ["benedikt", "t6d", "fabrik42"]
7
+ s.email = ["benedikt@synatic.net", "me@t6d.de", "fabrik42@gmail.com"]
8
+ s.homepage = "http://flinc.github.com/pling-actionmailer"
9
+ s.summary = %q{Pling Gateway to ActionMailer}
10
+ s.description = %q{Pling Gateway to ActionMailer}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_runtime_dependency "pling", "~> 0.0"
18
+ s.add_runtime_dependency "actionmailer", "~> 3.0"
19
+
20
+ s.add_development_dependency "rspec", "~> 2.7"
21
+ s.add_development_dependency "yard", ">= 0.7"
22
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pling::Gateway::ActionMailer::Mailer do
4
+ subject { described_class }
5
+
6
+ let(:message) { Pling::Message.new('Hello from Pling') }
7
+ let(:device) { Pling::Device.new(:identifier => 'DEVICEIDENTIFIER', :type => :email) }
8
+ let(:mail) { described_class.pling_message(message, device, configuration) }
9
+ let(:configuration) do
10
+ {
11
+ :from => 'random@example.com',
12
+ :html => true,
13
+ :text => true
14
+ }
15
+ end
16
+
17
+ specify { described_class.ancestors =~ ActionMailer::Base }
18
+
19
+ describe '.pling_message' do
20
+
21
+ it 'should return an instance of Mail::Message' do
22
+ subject.pling_message(message, device, configuration).should be_kind_of(Mail::Message)
23
+ end
24
+
25
+ context '{ :html => true, :text => true }' do
26
+ subject { described_class.pling_message(message, device, configuration) }
27
+
28
+ its(:mime_type) { should eq('multipart/alternative') }
29
+ it { should have(2).parts }
30
+
31
+ specify { subject.parts.map(&:mime_type) =~ ['multipart/alternative', 'text/plain'] }
32
+ end
33
+
34
+ context '{ :html => false, :text => true }' do
35
+ subject { described_class.pling_message(message, device, configuration.merge(:html => false, :text => true)) }
36
+
37
+ its(:mime_type) { should eq('text/plain') }
38
+ its(:body) { should eq('Hello from Pling') }
39
+ end
40
+
41
+ context '{ :html => true, :text => false }' do
42
+ subject { described_class.pling_message(message, device, configuration.merge(:html => true, :text => false)) }
43
+
44
+ its(:mime_type) { should eq('text/html') }
45
+ its(:body) { should =~ /<html>(.*)Hello from Pling(.*)<\/html>/m }
46
+ end
47
+
48
+ it 'should use device.identifier as recipient' do
49
+ mail.to.should include('DEVICEIDENTIFIER')
50
+ end
51
+
52
+ it 'should use sender from the configuration' do
53
+ mail.from.should include('random@example.com')
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pling::Gateway::ActionMailer do
4
+
5
+ let(:valid_configuration) do
6
+ { :from => 'random@example.com' }
7
+ end
8
+
9
+ let(:message) { Pling::Message.new('Hello from Pling') }
10
+ let(:device) { Pling::Device.new(:identifier => 'DEVICEIDENTIFIER', :type => :email) }
11
+
12
+ let(:mail) { mock(:deliver => true) }
13
+
14
+ before do
15
+ Pling::Gateway::ActionMailer::Mailer.stub(:pling_message => mail)
16
+ end
17
+
18
+ it 'should handle various action mailer related device types' do
19
+ Pling::Gateway::ActionMailer.handled_types.should =~ [:mail, :email, :actionmailer]
20
+ end
21
+
22
+ context 'when created with an invalid configuration' do
23
+ [:from].each do |attribute|
24
+ it "should raise an error when :#{attribute} is missing" do
25
+ configuration = valid_configuration
26
+ configuration.delete(attribute)
27
+ expect { Pling::Gateway::ActionMailer.new(configuration) }.to raise_error(ArgumentError, /:#{attribute} is missing/)
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'when created with a valid configuration' do
33
+ it 'should pass the full configuration to the mailer' do
34
+ configuration = valid_configuration.merge({ :something => true })
35
+ gateway = Pling::Gateway::ActionMailer.new(configuration)
36
+
37
+ Pling::Gateway::ActionMailer::Mailer.
38
+ should_receive(:pling_message).
39
+ with(anything, anything, hash_including(configuration)).and_return(mail)
40
+
41
+ gateway.deliver(message, device)
42
+ end
43
+ end
44
+
45
+ describe '#deliver' do
46
+ subject { Pling::Gateway::ActionMailer.new(valid_configuration) }
47
+
48
+ it 'should raise an error if no message is given' do
49
+ expect { subject.deliver(nil, device) }.to raise_error
50
+ end
51
+
52
+ it 'should raise an error the device is given' do
53
+ expect { subject.deliver(message, nil) }.to raise_error
54
+ end
55
+
56
+ it 'should call #to_pling_message on the given message' do
57
+ message.should_receive(:to_pling_message).and_return(message)
58
+ subject.deliver(message, device)
59
+ end
60
+
61
+ it 'should call #to_pling_device on the given device' do
62
+ device.should_receive(:to_pling_device).and_return(device)
63
+ subject.deliver(message, device)
64
+ end
65
+
66
+ it 'should try to deliver the given message' do
67
+ Pling::Gateway::ActionMailer::Mailer.
68
+ should_receive(:pling_message).
69
+ with(message, device, hash_including(valid_configuration)).
70
+ and_return(mail)
71
+
72
+ subject.deliver(message, device)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ require 'pling/gateway/action_mailer'
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
+
10
+ ActionMailer::Base.delivery_method = :test
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pling-actionmailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - benedikt
9
+ - t6d
10
+ - fabrik42
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-10-21 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: pling
18
+ requirement: &70329444843100 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '0.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70329444843100
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionmailer
29
+ requirement: &70329444842560 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70329444842560
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &70329444841800 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.7'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70329444841800
49
+ - !ruby/object:Gem::Dependency
50
+ name: yard
51
+ requirement: &70329444841320 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0.7'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70329444841320
60
+ description: Pling Gateway to ActionMailer
61
+ email:
62
+ - benedikt@synatic.net
63
+ - me@t6d.de
64
+ - fabrik42@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - Guardfile
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - app/views/pling/mailer/pling_message.html.erb
77
+ - app/views/pling/mailer/pling_message.text.erb
78
+ - lib/pling/gateway/action_mailer.rb
79
+ - pling-actionmailer.gemspec
80
+ - spec/pling/gateway/action_mailer/mailer_spec.rb
81
+ - spec/pling/gateway/action_mailer_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: http://flinc.github.com/pling-actionmailer
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.10
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Pling Gateway to ActionMailer
107
+ test_files:
108
+ - spec/pling/gateway/action_mailer/mailer_spec.rb
109
+ - spec/pling/gateway/action_mailer_spec.rb
110
+ - spec/spec_helper.rb
111
+ has_rdoc: