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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6242a8417b5290e908926dec11edaab460494bf
4
- data.tar.gz: 666e1a1dee20d2129886e296af08ed50708dbd66
3
+ metadata.gz: 24a6f69f0941e54acfcd890f332fb090d94c0a1b
4
+ data.tar.gz: c0fac984497be6ae193848e2f94d7a1826658d50
5
5
  SHA512:
6
- metadata.gz: f99de4b888a72e7d77f312ffb178b01f892f00bc4df818e3034696b5ca0526525ce443cd4f8afd62d8dd1885a339b0a22eb314cd82995c2b31e19766bebac8c1
7
- data.tar.gz: 230d10368caf137283d9c89f066abe53477c3cbe4289f8b894c518befcef17ffd4824e403bf685f2d76239978e4138065a02446b9d59b3f888e66f643487beb2
6
+ metadata.gz: 4abbe5770d657006bd11916db991c3b01984c74f0841b1b96ee9115e193aac28bbc4e1120c99148f739049efa0e534589e594010b5ba67e7b7411c441bae964c
7
+ data.tar.gz: 45337b8049768051e36530c219b27dc308bb3352209783e5b32d151175136d2c36d2129f8dc9d10cdbb975580cd0d5a1529cc21efde05b5275175c0969d50e8c
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ gem 'em-http-request'
7
7
  gem 'mysql2'
8
8
  gem 'httpi'
9
9
  gem 'savon', github: 'inre/savon', branch: 'version2'
10
+ gem 'remailer'
@@ -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,9 @@
1
+ module EmmyExtends
2
+ class Remailer::Email
3
+ include ModelPack::Document
4
+
5
+ attribute :to
6
+ attribute :from
7
+ attribute :content
8
+ end
9
+ 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,13 @@
1
+ module EmmyExtends
2
+ class Remailer::Response
3
+ attr_accessor :status
4
+
5
+ def initialize(status)
6
+ @status = status
7
+ end
8
+
9
+ def success?
10
+ status == 250
11
+ end
12
+ end
13
+ 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
@@ -15,4 +15,4 @@ require 'thin'
15
15
  puts "Thin web server"
16
16
  puts "Application starting in #{config.environment}"
17
17
  puts "Listening on #{config.url}"
18
- Emmy.bind *EmmyExtends::Thin::Controller.new(config, app)
18
+ bind *EmmyExtends::Thin::Controller.new(config, app)
@@ -1,3 +1,3 @@
1
1
  module EmmyExtends
2
- VERSION = "0.1.16"
2
+ VERSION = "0.2"
3
3
  end
@@ -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.1.16
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: 2015-07-06 00:00:00.000000000 Z
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.4.6
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