chatterbox-email 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rob Sanheim
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.
@@ -0,0 +1,18 @@
1
+ = chatterbox-email
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Rob Sanheim. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "chatterbox-email"
7
+ gem.summary = %Q{Send emails via chatterbox}
8
+ gem.description = %Q{Send emails via chatterbox - see chatterbox main project for details}
9
+ gem.email = "rsanheim@gmail.com"
10
+ gem.homepage = "http://github.com/rsanheim/chatterbox-email"
11
+ gem.authors = ["Rob Sanheim"]
12
+ gem.add_development_dependency "spicycode-micronaut"
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'micronaut/rake_task'
20
+ Micronaut::RakeTask.new(:examples) do |examples|
21
+ examples.pattern = 'examples/**/*_example.rb'
22
+ examples.ruby_opts << '-Ilib -Iexamples'
23
+ end
24
+
25
+ Micronaut::RakeTask.new(:rcov) do |examples|
26
+ examples.pattern = 'examples/**/*_example.rb'
27
+ examples.rcov_opts = '-Ilib -Iexamples'
28
+ examples.rcov = true
29
+ end
30
+
31
+ task :examples => :check_dependencies
32
+
33
+ task :default => :examples
34
+
35
+ task :release => [:default, "gemcutter:release"]
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ if File.exist?('VERSION')
40
+ version = File.read('VERSION')
41
+ else
42
+ version = ""
43
+ end
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "chatterbox-email #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,44 @@
1
+ require 'example_helper'
2
+
3
+ describe Chatterbox::Email do
4
+ include Chatterbox
5
+
6
+ describe "creation" do
7
+ it "is wired with valid options" do
8
+ lambda {
9
+ Chatterbox::Email.deliver(valid_options)
10
+ }.should_not raise_error
11
+ end
12
+
13
+ it "returns TMail::Mail instance" do
14
+ result = Chatterbox::Email.deliver(valid_options)
15
+ result.should be_instance_of(TMail::Mail)
16
+ end
17
+ end
18
+
19
+ describe "validations" do
20
+ it "should require :message" do
21
+ lambda {
22
+ Email.deliver(:config => { :from => "foo", :to => "foo"})
23
+ }.should raise_error(ArgumentError, /Must configure with a :message/)
24
+ end
25
+
26
+ it "should require :message => :summary" do
27
+ lambda {
28
+ Email.deliver(:message => {}, :config => { :from => "foo", :to => "foo"})
29
+ }.should raise_error(ArgumentError, /Must provide :summary in the :message/)
30
+ end
31
+
32
+ it "should require :to" do
33
+ lambda {
34
+ Email.deliver(:message => {:summary => ""}, :config => { :from => "anyone" })
35
+ }.should raise_error(ArgumentError, /Must provide :to in the :config/)
36
+ end
37
+
38
+ it "should require from address" do
39
+ lambda {
40
+ Email.deliver(:message => {:summary => ""}, :config => { :to => "anyone"})
41
+ }.should raise_error(ArgumentError, /Must provide :from in the :config/)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,56 @@
1
+ require 'example_helper'
2
+
3
+ describe Chatterbox::Mailer do
4
+ before { ActionMailer::Base.delivery_method = :test }
5
+ include Chatterbox
6
+
7
+ describe "wiring the email" do
8
+ it "should set subject to the summary" do
9
+ email = Mailer.create_message(valid_options.merge(:message => { :summary => "check this out"}))
10
+ email.subject.should == "check this out"
11
+ end
12
+
13
+ it "should not require a body (for emails that are subject only)" do
14
+ email = Mailer.create_message(valid_options.merge(:message => { :body => nil}))
15
+ email.body.should be_blank # not nil for some reason -- ActionMailer provides an empty string somewhere
16
+ end
17
+
18
+ it "should set body to the body" do
19
+ email = Mailer.create_message(valid_options.merge(:message => { :body => "here is my body"}))
20
+ email.body.should == "here is my body"
21
+ end
22
+
23
+ it "should set from" do
24
+ email = Mailer.create_message(valid_options.merge(:config => { :from => ["from@example.com"] }))
25
+ email.from.should == ["from@example.com"]
26
+ end
27
+ end
28
+
29
+ describe "content type" do
30
+ it "can be set" do
31
+ Mailer.create_message(valid_options.merge(:config => { :content_type => "text/html"})).content_type.should == "text/html"
32
+ end
33
+
34
+ it "should default to text/plain" do
35
+ Mailer.create_message(valid_options).content_type.should == "text/plain"
36
+ end
37
+ end
38
+
39
+ [:to, :cc, :bcc, :reply_to].each do |field|
40
+ describe "when configuring the #{field} field that takes one or many email addresses" do
41
+ it "should allow setting a single address" do
42
+ email = Mailer.create_message(valid_options.merge(:config => { field => "joe@exmaple.com"}))
43
+ email.send(field).should == ["joe@exmaple.com"]
44
+ end
45
+
46
+ it "should allow setting multiple addresses" do
47
+ email = Mailer.create_message(valid_options.merge(:config => { field => ["joe@example.com", "frank@example.com"]}))
48
+ email.send(field).should == ["joe@example.com", "frank@example.com"]
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ # content_type - Specify the content type of the message. Defaults to text/plain.
56
+ # headers - Specify additional hea
@@ -0,0 +1,30 @@
1
+ gem 'spicycode-micronaut'
2
+ require 'micronaut'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+
8
+ require 'chatterbox'
9
+ require 'chatterbox/email'
10
+
11
+ ActionMailer::Base.delivery_method = :test
12
+
13
+ def not_in_editor?
14
+ !(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM'))
15
+ end
16
+
17
+ def valid_options(overrides = {})
18
+ options = {
19
+ :message => { :summary => "here is a message" },
20
+ :config => {
21
+ :to => "joe@example.com",
22
+ :from => "someone@here.com"
23
+ }
24
+ }.merge(overrides)
25
+ end
26
+
27
+ Micronaut.configure do |c|
28
+ c.color_enabled = not_in_editor?
29
+ c.filter_run :focused => true
30
+ end
@@ -0,0 +1,52 @@
1
+ require 'chatterbox'
2
+ require 'chatterbox/mailer'
3
+
4
+ module Chatterbox
5
+ class Email
6
+
7
+ def self.deliver(options = {})
8
+ new(options).deliver
9
+ end
10
+
11
+ attr_reader :options
12
+
13
+ def initialize(options = {})
14
+ @options = options
15
+ validate_options
16
+ end
17
+
18
+ def deliver
19
+ Mailer.deliver_message(options)
20
+ end
21
+
22
+ private
23
+
24
+ def validate_options
25
+ require_message
26
+ require_message_keys(:summary)
27
+
28
+ require_config
29
+ require_config_keys(:to, :from)
30
+ end
31
+
32
+ def require_message
33
+ raise(ArgumentError, "Must configure with a :message") unless options.key?(:message)
34
+ end
35
+
36
+ def require_config
37
+ raise(ArgumentError, "Must configure with a :config") unless options.key?(:config)
38
+ end
39
+
40
+ def require_config_keys(*keys)
41
+ Array(keys).each do |key|
42
+ raise(ArgumentError, "Must provide #{key.inspect} in the :config") unless options[:config].key?(key)
43
+ end
44
+ end
45
+
46
+ def require_message_keys(*keys)
47
+ Array(keys).each do |key|
48
+ raise(ArgumentError, "Must provide #{key.inspect} in the :message") unless options[:message].key?(key)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ require 'actionmailer'
2
+
3
+ module Chatterbox
4
+ class Mailer < ActionMailer::Base
5
+ self.template_root = File.join(File.dirname(__FILE__), *%w[views])
6
+
7
+ def self.reloadable?() false end
8
+
9
+ def message(data={})
10
+ data = data.dup.symbolize_keys
11
+
12
+ content_type data[:config][:content_type] || "text/plain"
13
+
14
+ recipients data[:config][:to]
15
+ from data[:config][:from]
16
+
17
+ reply_to data[:config][:reply_to] if data[:config][:reply_to]
18
+ bcc data[:config][:bcc] if data[:config][:bcc]
19
+ cc data[:config][:cc] if data[:config][:cc]
20
+
21
+ subject data[:message][:summary]
22
+ body data[:message][:body] if data[:message][:body]
23
+ end
24
+
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chatterbox-email
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Sanheim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: spicycode-micronaut
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Send emails via chatterbox - see chatterbox main project for details
26
+ email: rsanheim@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - examples/chatterbox/email_example.rb
42
+ - examples/chatterbox/mailer_example.rb
43
+ - examples/example_helper.rb
44
+ - lib/chatterbox/email.rb
45
+ - lib/chatterbox/mailer.rb
46
+ - lib/chatterbox/views/chatterbox/mailer/message.erb
47
+ has_rdoc: true
48
+ homepage: http://github.com/rsanheim/chatterbox-email
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Send emails via chatterbox
75
+ test_files:
76
+ - examples/chatterbox/email_example.rb
77
+ - examples/chatterbox/mailer_example.rb
78
+ - examples/example_helper.rb