elastic_email_rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +23 -0
- data/lib/elastic_email/client.rb +19 -0
- data/lib/elastic_email/deliverer.rb +80 -0
- data/lib/elastic_email/error.rb +8 -0
- data/lib/elastic_email/version.rb +3 -0
- data/lib/elastic_email_rails.rb +6 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf62f93cd0a341f41207eaf50eaed04adadf1a5e
|
4
|
+
data.tar.gz: bc6b762317b2d2fd7de573419329ed1ce54fc189
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa893d5ae02d1546936e732d1b4d515d52b33d6041c83ff163ec9278a0dc33406621c5472bee99365e62e9bc0895b95aa1338e927b150a67ee509b24a2eba833
|
7
|
+
data.tar.gz: 9414006816e9462167e120800c4d93af025a57b4316a73ff5f6d669abf5777e391b17b1cb5c12d4b00dc80abc4c750949de2a29e56106046c5f4ca9abe3546fe
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Zaez Inovacao Digital
|
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,23 @@
|
|
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 = 'ElasticEmailRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
19
|
+
require 'rspec/core/rake_task'
|
20
|
+
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
22
|
+
|
23
|
+
task default: :spec
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ElasticEmail
|
4
|
+
class Client
|
5
|
+
|
6
|
+
def send_message(options)
|
7
|
+
Net::HTTP.post_form(elastic_email_uri, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def elastic_email_uri
|
11
|
+
URI.parse(elastic_email_send_url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def elastic_email_send_url
|
15
|
+
'http://api.elasticemail.com/mailer/send'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module ElasticEmail
|
2
|
+
class Deliverer
|
3
|
+
|
4
|
+
attr_accessor :settings
|
5
|
+
|
6
|
+
def initialize(settings)
|
7
|
+
self.settings = settings
|
8
|
+
end
|
9
|
+
|
10
|
+
def username
|
11
|
+
self.settings[:username]
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_key
|
15
|
+
self.settings[:api_key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver!(rails_message)
|
19
|
+
response = elastic_email_client.send_message build_elastic_email_message_for(rails_message)
|
20
|
+
response_body = response.body
|
21
|
+
if response.code == '200' and response_body.match('^[0-9|a-f]{8}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{4}-[0-9|a-f]{12}$').present?
|
22
|
+
rails_message.message_id = response_body
|
23
|
+
else
|
24
|
+
raise Error.new(response_body)
|
25
|
+
end
|
26
|
+
response
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_elastic_email_message_for(rails_message)
|
32
|
+
elastic_email_message = build_basic_elastic_email_message_for rails_message
|
33
|
+
remove_empty_values elastic_email_message
|
34
|
+
|
35
|
+
elastic_email_message
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_basic_elastic_email_message_for(rails_message)
|
39
|
+
elastic_email_message = {
|
40
|
+
username: username,
|
41
|
+
api_key: api_key,
|
42
|
+
from: rails_message[:from].formatted,
|
43
|
+
to: rails_message[:to].formatted,
|
44
|
+
subject: rails_message.subject,
|
45
|
+
body_text: extract_text(rails_message),
|
46
|
+
body_html: extract_html(rails_message)
|
47
|
+
}
|
48
|
+
|
49
|
+
elastic_email_message[:reply_to] = rails_message[:reply_to].formatted if rails_message[:reply_to].present?
|
50
|
+
|
51
|
+
return elastic_email_message
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_html(rails_message)
|
55
|
+
if rails_message.html_part
|
56
|
+
rails_message.html_part.body.decoded
|
57
|
+
else
|
58
|
+
rails_message.content_type =~ /text\/html/ ? rails_message.body.decoded : nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract_text(rails_message)
|
63
|
+
if rails_message.multipart?
|
64
|
+
rails_message.text_part ? rails_message.text_part.body.decoded : nil
|
65
|
+
else
|
66
|
+
rails_message.content_type =~ /text\/plain/ ? rails_message.body.decoded : nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def remove_empty_values(elastic_email_message)
|
71
|
+
elastic_email_message.delete_if { |key, value| value.nil? }
|
72
|
+
end
|
73
|
+
|
74
|
+
def elastic_email_client
|
75
|
+
@elastic_email_client ||= Client.new
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
ActionMailer::Base.add_delivery_method :elastic_email, ElasticEmail::Deliverer
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elastic_email_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zaez Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.13
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.13
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.14.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.14.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.13
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.13
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
description: An adapter for using Elastic Email with Rails and Action Mailer
|
70
|
+
email:
|
71
|
+
- contato@zaez.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- Rakefile
|
78
|
+
- lib/elastic_email/client.rb
|
79
|
+
- lib/elastic_email/deliverer.rb
|
80
|
+
- lib/elastic_email/error.rb
|
81
|
+
- lib/elastic_email/version.rb
|
82
|
+
- lib/elastic_email_rails.rb
|
83
|
+
homepage: https://github.com/zaeznet/elastic_email_rails/
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.4.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Rails Action Mailer adapter for Elastic Email
|
107
|
+
test_files: []
|