hato-plugin-mail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5487627d1c2f1e6f7dcc3ba0295d92165ccf507
4
+ data.tar.gz: 21a2c80efd0b83249f26b6c10025c6729c12c9bd
5
+ SHA512:
6
+ metadata.gz: 25eca61b9f304daecf33fc5cf4c2391c61d21d0382158dda8b003ae96005cf25757f96fe489a4e55a79d73d12c29d9b78da5e1a11acd4d010991cfb9863790b0
7
+ data.tar.gz: 02b9cd00a7d5fdb3191c036fae72edcf81e0dfb4d85883676ecd0c02e398048ce51b4f88b6f1ebc995cc1c52b154628e3598056050259f9cc687cbe1e7cb32bb
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
7
+ - rbx-19mode
8
+ - jruby-19mode
9
+ - jruby-head
10
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hato-plugin-ikachan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kentaro Kuribayashi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Hato::Plugin::Mail [![BuildStatus](https://secure.travis-ci.org/kentaro/hato-plugin-mail.png)](http://travis-ci.org/kentaro/hato-plugin-mail)
2
+
3
+ This plugin provides a method to send messages via mail.
4
+
5
+ ## Configuration
6
+
7
+ ```ruby
8
+ Hato::Config.define do
9
+ api_key 'test'
10
+ host '0.0.0.0'
11
+ port 9699
12
+
13
+ # ...
14
+
15
+ tag 'test' do
16
+ plugin 'Mail' do
17
+ smtp address: 'smtp.example.com',
18
+ port: 587,
19
+ domain: 'example',
20
+ user_name: 'hato',
21
+ password: 'password',
22
+ enable_ssl: true
23
+
24
+ subject_template = <<EOS
25
+ [<%= args[:tag] %>] Notification
26
+ EOS
27
+ body_template = <<EOS
28
+ You've got a message:
29
+
30
+ <%= args[:message] %>
31
+ EOS
32
+
33
+ message from: 'hato@example.com',
34
+ to: [
35
+ 'foo@example.com',
36
+ 'bar@example.com',
37
+ ],
38
+ subject_template: subject_template,
39
+ body_template: body_template
40
+ end
41
+ end
42
+
43
+ # ...
44
+ end
45
+ ```
46
+
47
+ ## Installation
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ gem 'hato-plugin-mail'
52
+
53
+ And then execute:
54
+
55
+ $ bundle
56
+
57
+ Or install it yourself as:
58
+
59
+ $ gem install hato-plugin-mail
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
68
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ spec.ruby_opts = %w[-w]
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hato/plugin/mail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hato-plugin-mail"
8
+ spec.version = Hato::Plugin::Mail::VERSION
9
+ spec.authors = ["Kentaro Kuribayashi"]
10
+ spec.email = ["kentarok@gmail.com"]
11
+ spec.description = %q{Hato plugin to send messages via email}
12
+ spec.summary = %q{Hato plugin to send messages via email}
13
+ spec.homepage = "https://github.com/kentaro/hato-plugin-mail"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = '>= 1.9.2'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "hato"
24
+ spec.add_dependency "mail"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ end
30
+
@@ -0,0 +1,54 @@
1
+ require 'hato/plugin'
2
+ require 'hato/plugin/mail/version'
3
+
4
+ require 'erb'
5
+ require 'mail'
6
+
7
+ module Hato
8
+ module Plugin
9
+ class Mail < Base
10
+ def notify(args)
11
+ if smtp_opts = config.smtp
12
+ ::Mail.defaults do
13
+ delivery_method :smtp, (
14
+ smtp_opts.to_hash.keys.inject({}) { |opts, key|
15
+ opts[key.to_sym] = smtp_opts.send(key.to_sym)
16
+ opts
17
+ }
18
+ )
19
+ end
20
+ end
21
+
22
+ to_addresses = config.message['to']
23
+ to_addresses = [to_addresses] if to_addresses.is_a?(String)
24
+
25
+ to_addresses.each do |to_address|
26
+ send_mail(to_address, args)
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def send_mail(to_address, args)
33
+ mail = {
34
+ from: config.message['from'],
35
+ subject: render(config.message['subject_template'], args),
36
+ body: render(config.message['body_template'], args),
37
+ }
38
+
39
+ ::Mail.deliver do
40
+ from mail[:from]
41
+ to to_address
42
+ subject mail[:subject]
43
+ body mail[:body]
44
+ end
45
+ end
46
+
47
+ def render(template, args)
48
+ erb = ERB.new(template)
49
+ erb.result(binding).chomp
50
+ end
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,10 @@
1
+ require 'hato/plugin'
2
+
3
+ module Hato
4
+ module Plugin
5
+ class Mail < Base
6
+ VERSION = "0.0.1"
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,78 @@
1
+ require_relative '../../../spec_helper'
2
+ require 'hato/config'
3
+
4
+ describe Hato::Plugin::Mail do
5
+ before {
6
+ ::Mail.defaults { delivery_method :test }
7
+ ::Mail::TestMailer.deliveries.clear
8
+ }
9
+
10
+ describe '#notify' do
11
+ context 'arguments' do
12
+ context 'mail address' do
13
+ context 'when channel is passed as a string' do
14
+ subject {
15
+ described_class.new(
16
+ Hato::Config::Plugin.new('Mail') {
17
+ message from: 'hato@example.com',
18
+ to: 'foo@example.com',
19
+ subject_template: 'subject',
20
+ body_template: 'body'
21
+ }
22
+ )
23
+ }
24
+ before {
25
+ subject.notify(tag: 'test', message: 'test')
26
+ }
27
+
28
+ it {
29
+ expect(::Mail::TestMailer.deliveries.length).to be == 1
30
+ }
31
+ end
32
+
33
+ context 'when channel is passed as an array' do
34
+ subject {
35
+ described_class.new(
36
+ Hato::Config::Plugin.new('Mail') {
37
+ message from: 'hato@example.com',
38
+ to: %w[foo@example.com bar@example.com],
39
+ subject_template: 'subject',
40
+ body_template: 'body'
41
+ }
42
+ )
43
+ }
44
+ before {
45
+ subject.notify(tag: 'test', message: 'test')
46
+ }
47
+
48
+ it {
49
+ expect(::Mail::TestMailer.deliveries.length).to be == 2
50
+ }
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'template' do
56
+ subject {
57
+ described_class.new(
58
+ Hato::Config::Plugin.new('Mail') {
59
+ message from: 'hato@example.com',
60
+ to: 'foo@example.com',
61
+ subject_template: '[<%= args[:tag] %>] notification',
62
+ body_template: 'message: <%= args[:message] %>'
63
+ }
64
+ )
65
+ }
66
+ before {
67
+ subject.notify(tag: 'test', message: 'test')
68
+ }
69
+
70
+ it {
71
+ mail = ::Mail::TestMailer.deliveries.first
72
+ expect(mail.subject).to be == '[test] notification'
73
+ expect(mail.body.decoded).to be == 'message: test'
74
+ }
75
+ end
76
+ end
77
+ end
78
+
@@ -0,0 +1,4 @@
1
+ require_relative '../lib/hato/plugin/mail'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hato-plugin-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Kuribayashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hato
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mail
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Hato plugin to send messages via email
84
+ email:
85
+ - kentarok@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - hato-plugin-mail.gemspec
97
+ - lib/hato/plugin/mail.rb
98
+ - lib/hato/plugin/mail/version.rb
99
+ - spec/lib/hato/plugin/mail_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/kentaro/hato-plugin-mail
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: 1.9.2
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Hato plugin to send messages via email
125
+ test_files:
126
+ - spec/lib/hato/plugin/mail_spec.rb
127
+ - spec/spec_helper.rb