slactionmailer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +31 -0
- data/lib/slactionmailer.rb +5 -0
- data/lib/slactionmailer/core_ext.rb +9 -0
- data/lib/slactionmailer/delivery_method.rb +25 -0
- data/lib/slactionmailer/message.rb +43 -0
- data/lib/slactionmailer/railtie.rb +9 -0
- data/lib/slactionmailer/version.rb +3 -0
- data/lib/tasks/slactionmailer_tasks.rake +4 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef19c66ebf41c763d9eb157d97651b8a49f3d4b6
|
4
|
+
data.tar.gz: 00f8d027900dbed746f6ac1d5614da9a70145828
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ea62d575dd461ad7504bb9371e3fbd419dd3ee64c261f59efe3b0cf37d2dc914d4e536bc54e7425ab1aef49211e6a2814e90a6b4024248a7d43d07659eee7f7
|
7
|
+
data.tar.gz: b5a8551e5af2a3aeac426deaa53969e552b25b54fc544b36217c4d0666f40edce27db9a358ecbfc391f07025a29717fe8960f3a1604f6bf5cbdcb4f9d8c99f3d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Lee
|
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/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Slactionmailer'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
|
26
|
+
desc "Run RSpec"
|
27
|
+
RSpec::Core::RakeTask.new do |t|
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
task default: :spec
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'slack-notifier'
|
2
|
+
|
3
|
+
String.class_eval do
|
4
|
+
def to_channel
|
5
|
+
notifier = Slack::Notifier.new "https://hooks.slack.com/services/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", channel: "#rubberduck", username: "SlactionMailer"
|
6
|
+
notifier.ping "Test"
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SlactionMailer
|
2
|
+
class DeliveryMethod
|
3
|
+
class InvalidOption < StandardError; end
|
4
|
+
|
5
|
+
attr_accessor :settings
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
raise InvalidOption, 'ENV["SLACK_WEBHOOK_URL"]is required to send messages' if options[:webhook].nil?
|
9
|
+
raise InvalidOption, 'ENV["SLACK_CHANNEL"]is required to send messages' if options[:channel].nil?
|
10
|
+
raise InvalidOption, 'ENV["SLACK_USERNAME"]is required to send messages' if options[:username].nil?
|
11
|
+
self.settings = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver!(mail)
|
15
|
+
notifier = Slack::Notifier.new settings[:webhook], channel: settings[:channel], username: settings[:username]
|
16
|
+
if settings.key?(:template)
|
17
|
+
message = Message.new(mail, :template => settings[:template])
|
18
|
+
else
|
19
|
+
message = Message.new(mail)
|
20
|
+
end
|
21
|
+
notifier.ping message.result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
|
4
|
+
module SlactionMailer
|
5
|
+
class Message < ERB
|
6
|
+
|
7
|
+
def initialize(mail, options = {})
|
8
|
+
@mail = mail
|
9
|
+
@template = options.fetch(:template, self.class.template)
|
10
|
+
super(@template)
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
@mail.text_part.body.decoded
|
15
|
+
end
|
16
|
+
|
17
|
+
def from
|
18
|
+
@from ||= Array(@mail['from']).join(", ")
|
19
|
+
end
|
20
|
+
|
21
|
+
def to
|
22
|
+
@to ||= Array(@mail['to']).join(", ")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.template
|
26
|
+
"Subject: <%= @mail.subject %>
|
27
|
+
From: <%= from %>
|
28
|
+
To: <%= to %>
|
29
|
+
|
30
|
+
<%= body %>"
|
31
|
+
end
|
32
|
+
|
33
|
+
def result
|
34
|
+
super(binding)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.to_template(mail)
|
38
|
+
@mail = mail
|
39
|
+
mail.to_s
|
40
|
+
#"#{ @mail.subject }\nFrom: #{ @mail.from } To: #{ @mail.to }\n #{ @mail.body }"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SlactionMailer
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "letter_opener.add_delivery_method" do
|
4
|
+
ActiveSupport.on_load :action_mailer do
|
5
|
+
ActionMailer::Base.add_delivery_method :slack, SlactionMailer::DeliveryMethod, :webhook => ENV["SLACK_WEBHOOK_URL"], :channel => ENV["SLACK_CHANNEL"], :username => ENV["SLACK_USERNAME"]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slactionmailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Gillentine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slack-notifier
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mail
|
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: sqlite3
|
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: Want to send the emails generated by your Ruby on Rails application to
|
84
|
+
a Slack channel? Now you can!
|
85
|
+
email:
|
86
|
+
- lee@fishburd.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- MIT-LICENSE
|
92
|
+
- Rakefile
|
93
|
+
- lib/slactionmailer.rb
|
94
|
+
- lib/slactionmailer/core_ext.rb
|
95
|
+
- lib/slactionmailer/delivery_method.rb
|
96
|
+
- lib/slactionmailer/message.rb
|
97
|
+
- lib/slactionmailer/railtie.rb
|
98
|
+
- lib/slactionmailer/version.rb
|
99
|
+
- lib/tasks/slactionmailer_tasks.rake
|
100
|
+
homepage: https://github.com/geetotes/slactionmailer
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.6
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: A drop in replacement for ActionMailer that sends your emails to a Slack
|
124
|
+
channel
|
125
|
+
test_files: []
|