emmy-extends 0.1.16 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/emmy_extends/em_http_request/adapter.rb +1 -0
- data/lib/emmy_extends/remailer/connection.rb +21 -0
- data/lib/emmy_extends/remailer/operation.rb +71 -0
- data/lib/emmy_extends/remailer/request/email.rb +9 -0
- data/lib/emmy_extends/remailer/request/options.rb +14 -0
- data/lib/emmy_extends/remailer/request.rb +24 -0
- data/lib/emmy_extends/remailer/response.rb +13 -0
- data/lib/emmy_extends/remailer.rb +14 -0
- data/lib/emmy_extends/thin/rackup.em +1 -1
- data/lib/emmy_extends/version.rb +1 -1
- data/spec/remailer_spec.rb +26 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a6f69f0941e54acfcd890f332fb090d94c0a1b
|
4
|
+
data.tar.gz: c0fac984497be6ae193848e2f94d7a1826658d50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abbe5770d657006bd11916db991c3b01984c74f0841b1b96ee9115e193aac28bbc4e1120c99148f739049efa0e534589e594010b5ba67e7b7411c441bae964c
|
7
|
+
data.tar.gz: 45337b8049768051e36530c219b27dc308bb3352209783e5b32d151175136d2c36d2129f8dc9d10cdbb975580cd0d5a1529cc21efde05b5275175c0969d50e8c
|
data/Gemfile
CHANGED
@@ -53,6 +53,7 @@ module EmmyExtends
|
|
53
53
|
|
54
54
|
elsif form
|
55
55
|
form_encoded = form.is_a?(String) ? form : URI.encode_www_form(form)
|
56
|
+
# rfc3986
|
56
57
|
body_text = form_encoded.gsub(/([!'()*]+)/m) { '%'+$1.unpack('H2'*$1.bytesize).join('%').upcase }
|
57
58
|
|
58
59
|
headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Remailer::Connection < ::Remailer::SMTP::Client
|
3
|
+
using EventObject
|
4
|
+
|
5
|
+
attr_accessor :operation
|
6
|
+
events :connect, :error, :disconnect
|
7
|
+
|
8
|
+
def initialize(op)
|
9
|
+
@operation = op
|
10
|
+
options = op.request.options.serializable_hash
|
11
|
+
options[:on_connect] = lambda { |*a| self.connect!(*a) }
|
12
|
+
options[:on_error] = lambda { |*a| self.error!(*a) }
|
13
|
+
options[:on_disconnect] = lambda { |*a| self.disconnect!(*a) }
|
14
|
+
options[:close] = true
|
15
|
+
|
16
|
+
super(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
#<<<
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Remailer::Operation
|
3
|
+
using EventObject
|
4
|
+
|
5
|
+
attr_accessor :request
|
6
|
+
attr_accessor :response
|
7
|
+
attr_accessor :connection
|
8
|
+
attr_accessor :completed
|
9
|
+
events :success, :error
|
10
|
+
|
11
|
+
def initialize(req)
|
12
|
+
@request = req
|
13
|
+
@completed = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
@connection ||= EmmyMachine.connect(*self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_emails
|
21
|
+
raise "no emails to send" if request.emails.empty?
|
22
|
+
|
23
|
+
request.emails.each_with_index do |email, index|
|
24
|
+
if index.zero?
|
25
|
+
connection.send_email(email.from, email.to, email.content) do |status|
|
26
|
+
@response = Remailer::Response.new(status)
|
27
|
+
success!(response, self, connection) unless completed
|
28
|
+
end
|
29
|
+
else
|
30
|
+
connection.send_email(email.from, email.to, email.content)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sync
|
36
|
+
Fiber.sync do |fiber|
|
37
|
+
connect
|
38
|
+
send_emails
|
39
|
+
|
40
|
+
on :success do |res, operation, conn|
|
41
|
+
@completed = true
|
42
|
+
fiber.resume response
|
43
|
+
end
|
44
|
+
|
45
|
+
on :error do |error, operation, conn|
|
46
|
+
@completed = true
|
47
|
+
fiber.leave error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize_connection(conn)
|
53
|
+
conn.on :connect do |*a|
|
54
|
+
end
|
55
|
+
|
56
|
+
conn.on :error do |*a|
|
57
|
+
error!
|
58
|
+
end
|
59
|
+
|
60
|
+
conn.on :disconnect do |*a|
|
61
|
+
error!(Remailer::Error.new(conn.error_message)) unless completed
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_a
|
66
|
+
["tcp://#{request.options.host}:#{request.options.port}", EmmyExtends::Remailer::Connection, method(:initialize_connection), self]
|
67
|
+
end
|
68
|
+
|
69
|
+
#<<<
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Remailer::Options
|
3
|
+
include ModelPack::Document
|
4
|
+
|
5
|
+
attribute :host
|
6
|
+
attribute :port
|
7
|
+
attribute :username
|
8
|
+
attribute :password
|
9
|
+
attribute :use_tls, predicate: true, default: true
|
10
|
+
attribute :require_tls, predicate: true, default: false
|
11
|
+
attribute :debug, predicate: true, default: false
|
12
|
+
attribute :timeout, default: 30
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Remailer::Request
|
3
|
+
include ModelPack::Document
|
4
|
+
|
5
|
+
array :emails, class_name: Remailer::Email
|
6
|
+
object :options, class_name: Remailer::Options
|
7
|
+
|
8
|
+
def operation
|
9
|
+
@operation ||= new_operation
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_operation
|
13
|
+
EmmyExtends::Remailer::Operation.new(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias op operation
|
17
|
+
|
18
|
+
def sync
|
19
|
+
operation.sync
|
20
|
+
end
|
21
|
+
|
22
|
+
#<<<
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "remailer"
|
2
|
+
|
3
|
+
module EmmyExtends
|
4
|
+
module Remailer
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
autoload :Operation, "emmy_extends/remailer/operation"
|
8
|
+
autoload :Connection, "emmy_extends/remailer/connection"
|
9
|
+
autoload :Request, "emmy_extends/remailer/request"
|
10
|
+
autoload :Response, "emmy_extends/remailer/response"
|
11
|
+
autoload :Options, "emmy_extends/remailer/request/options"
|
12
|
+
autoload :Email, "emmy_extends/remailer/request/email"
|
13
|
+
end
|
14
|
+
end
|
data/lib/emmy_extends/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "emmy_extends/remailer"
|
3
|
+
|
4
|
+
describe EmmyExtends::Remailer do
|
5
|
+
around do |example|
|
6
|
+
EmmyMachine.run_block &example
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sends email" do
|
10
|
+
req = EmmyExtends::Remailer::Request.new(
|
11
|
+
emails: [{
|
12
|
+
to: '...',
|
13
|
+
from: '...',
|
14
|
+
content: 'Hello, Mail Tester!'
|
15
|
+
}],
|
16
|
+
options: {
|
17
|
+
host: 'smtp.gmail.com',
|
18
|
+
port: 587,
|
19
|
+
username: '...',
|
20
|
+
password: '...'
|
21
|
+
}
|
22
|
+
)
|
23
|
+
res = req.op.sync
|
24
|
+
expect(res.success?).to be(true)
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emmy-extends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: emmy-machine
|
@@ -123,6 +123,13 @@ files:
|
|
123
123
|
- lib/emmy_extends/mysql2/client.rb
|
124
124
|
- lib/emmy_extends/mysql2/operation.rb
|
125
125
|
- lib/emmy_extends/mysql2/watcher.rb
|
126
|
+
- lib/emmy_extends/remailer.rb
|
127
|
+
- lib/emmy_extends/remailer/connection.rb
|
128
|
+
- lib/emmy_extends/remailer/operation.rb
|
129
|
+
- lib/emmy_extends/remailer/request.rb
|
130
|
+
- lib/emmy_extends/remailer/request/email.rb
|
131
|
+
- lib/emmy_extends/remailer/request/options.rb
|
132
|
+
- lib/emmy_extends/remailer/response.rb
|
126
133
|
- lib/emmy_extends/savon.rb
|
127
134
|
- lib/emmy_extends/savon/class_methods.rb
|
128
135
|
- lib/emmy_extends/savon/model.rb
|
@@ -137,6 +144,7 @@ files:
|
|
137
144
|
- spec/em_http_request_spec.rb
|
138
145
|
- spec/httpi_spec.rb
|
139
146
|
- spec/mysql2_spec.rb
|
147
|
+
- spec/remailer_spec.rb
|
140
148
|
- spec/savon_spec.rb
|
141
149
|
- spec/spec_helper.rb
|
142
150
|
homepage: ''
|
@@ -159,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
167
|
version: '0'
|
160
168
|
requirements: []
|
161
169
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.5.1
|
163
171
|
signing_key:
|
164
172
|
specification_version: 4
|
165
173
|
summary: Emmy support em-http-request, thin, savon, mysql2 etc.
|
@@ -168,5 +176,6 @@ test_files:
|
|
168
176
|
- spec/em_http_request_spec.rb
|
169
177
|
- spec/httpi_spec.rb
|
170
178
|
- spec/mysql2_spec.rb
|
179
|
+
- spec/remailer_spec.rb
|
171
180
|
- spec/savon_spec.rb
|
172
181
|
- spec/spec_helper.rb
|