emmy-extends 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile +2 -0
- data/emmy-extends.gemspec +1 -1
- data/lib/emmy_extends/em_http_request/adapter.rb +2 -1
- data/lib/emmy_extends/httpi/adapter.rb +15 -15
- data/lib/emmy_extends/mysql2/client.rb +21 -0
- data/lib/emmy_extends/mysql2/operation.rb +36 -0
- data/lib/emmy_extends/mysql2/watcher.rb +24 -0
- data/lib/emmy_extends/version.rb +1 -1
- data/lib/emmy_extends.rb +6 -0
- data/spec/em_http_request_spec.rb +8 -14
- data/spec/httpi_spec.rb +4 -9
- data/spec/mysql2_spec.rb +51 -0
- data/spec/savon_spec.rb +11 -16
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a0e3a4faca05d0d6a5c8538652143080296e81c
|
4
|
+
data.tar.gz: e1d0b56934235795d602acdc37f0fa46b8025d4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9fca19b26b97bde2a10297b5c29861ce43c2bb04b4a5b37e036e44bd5bb866a4e2bb5d455337ffd540c96837c45ec571439eb12a83a6e936345a86d5138615d
|
7
|
+
data.tar.gz: 046dc4b7d3bfbca15de50b826125bc94553ff558c8f59f12e644bfdd2cf105befa10d0e9122de62c596374edc1896a89e1c2183194a8f77f4fabcca988ec20aa
|
data/Gemfile
CHANGED
data/emmy-extends.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "eventmachine", "~> 1.0.3"
|
22
22
|
spec.add_dependency "em-http-request", "~> 1.1.2"
|
23
|
-
spec.add_dependency "emmy-machine", "~> 0.1.
|
23
|
+
spec.add_dependency "emmy-machine", "~> 0.1.6"
|
24
24
|
spec.add_dependency "emmy-http", "~> 0.1.1"
|
25
25
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3"
|
@@ -71,7 +71,8 @@ module EmmyExtends
|
|
71
71
|
|
72
72
|
def setup_http_client
|
73
73
|
@http_client = begin
|
74
|
-
|
74
|
+
method = delegate.request.method.to_s.upcase
|
75
|
+
EventMachine::HttpClient.new(@http_request, HttpClientOptions.new(delegate.request.url, request_options, method)).tap do |client|
|
75
76
|
client.stream do |chunk|
|
76
77
|
@body << chunk
|
77
78
|
end
|
@@ -8,22 +8,13 @@ module EmmyExtends
|
|
8
8
|
|
9
9
|
def initialize(request)
|
10
10
|
@request = request
|
11
|
-
@emmy_request = EmmyHttp::Request.new(
|
12
|
-
url: build_request_url(@request.url),
|
13
|
-
method: 'POST',
|
14
|
-
timeouts: { connect: @request.open_timeout, inactivity: @request.read_timeout },
|
15
|
-
headers: @request.headers.to_hash,
|
16
|
-
body: @request.body
|
17
|
-
)
|
18
|
-
@emmy_operation = EmmyHttp::Operation.new(@emmy_request, EmmyExtends::EmHttpRequest::Adapter.new)
|
19
|
-
@operation = HTTPI::Operation.new(@emmy_operation)
|
20
11
|
end
|
21
12
|
|
22
13
|
def setup_http_auth
|
23
14
|
unless @request.auth.type == :basic
|
24
15
|
raise NotSupportedError, "EM-HTTP-Request does only support HTTP basic auth"
|
25
16
|
end
|
26
|
-
@
|
17
|
+
@http_request.headers[:authorization] = @request.auth.credentials
|
27
18
|
end
|
28
19
|
|
29
20
|
def proxy_options
|
@@ -35,15 +26,24 @@ module EmmyExtends
|
|
35
26
|
end
|
36
27
|
|
37
28
|
def request(method)
|
38
|
-
# FIXME: proxy support # proxy_options if @request.proxy
|
39
|
-
#setup_proxy(options) if @request.proxy
|
40
|
-
setup_http_auth if @request.auth.http?
|
41
|
-
|
42
29
|
if @request.on_body
|
43
30
|
raise NotSupportedError, "EM-HTTP-Request does not support response streaming"
|
44
31
|
end
|
45
32
|
|
46
|
-
@
|
33
|
+
@http_request = EmmyHttp::Request.new(
|
34
|
+
url: build_request_url(@request.url),
|
35
|
+
method: method,
|
36
|
+
timeouts: { connect: @request.open_timeout, inactivity: @request.read_timeout },
|
37
|
+
headers: @request.headers.to_hash,
|
38
|
+
body: @request.body
|
39
|
+
)
|
40
|
+
|
41
|
+
# FIXME: proxy support # proxy_options if @request.proxy
|
42
|
+
#setup_proxy(options) if @request.proxy
|
43
|
+
setup_http_auth if @request.auth.http?
|
44
|
+
|
45
|
+
@http_operation = EmmyHttp::Operation.new(@http_request, EmmyExtends::EmHttpRequest::Adapter.new)
|
46
|
+
@operation = HTTPI::Operation.new(@http_operation)
|
47
47
|
@operation
|
48
48
|
end
|
49
49
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Mysql2::Client < ::Mysql2::Client
|
3
|
+
using EventObject
|
4
|
+
|
5
|
+
def query(sql, opts={})
|
6
|
+
if ::EM.reactor_running?
|
7
|
+
super(sql, opts.merge(:async => true))
|
8
|
+
Mysql2::Operation.new(self)
|
9
|
+
else
|
10
|
+
super(sql, opts)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def close(*args)
|
15
|
+
@watch.detach if @watch
|
16
|
+
super(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
#<<<
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Mysql2::Operation
|
3
|
+
using EventObject
|
4
|
+
events :success, :error
|
5
|
+
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def watch
|
13
|
+
@watch ||= EmmyMachine.watch(*self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def sync
|
17
|
+
Fiber.sync do |fiber|
|
18
|
+
watch
|
19
|
+
|
20
|
+
on :success do |response, operation, conn|
|
21
|
+
fiber.resume response
|
22
|
+
end
|
23
|
+
|
24
|
+
on :error do |error, operation, conn|
|
25
|
+
fiber.leave error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_a
|
31
|
+
[client.socket, Mysql2::Watcher, @client, self, {notify_readable: true, notify_writable: false}]
|
32
|
+
end
|
33
|
+
|
34
|
+
#<<<
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
module Mysql2::Watcher
|
3
|
+
|
4
|
+
attr_accessor :client, :operation
|
5
|
+
|
6
|
+
def initialize(client, operation)
|
7
|
+
@client = client
|
8
|
+
@operation = operation
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify_readable
|
12
|
+
detach
|
13
|
+
begin
|
14
|
+
result = @client.async_result
|
15
|
+
rescue Exception => e
|
16
|
+
@operation.error!(e.to_s, @operation, self)
|
17
|
+
else
|
18
|
+
@operation.success!(result, @operation, self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#<<<
|
23
|
+
end
|
24
|
+
end
|
data/lib/emmy_extends/version.rb
CHANGED
data/lib/emmy_extends.rb
CHANGED
@@ -13,6 +13,12 @@ module EmmyExtends
|
|
13
13
|
autoload :Operation, "emmy_extends/httpi/operation"
|
14
14
|
end
|
15
15
|
|
16
|
+
module Mysql2
|
17
|
+
autoload :Operation, "emmy_extends/mysql2/operation"
|
18
|
+
autoload :Client, "emmy_extends/mysql2/client"
|
19
|
+
autoload :Watcher, "emmy_extends/mysql2/watcher"
|
20
|
+
end
|
21
|
+
|
16
22
|
module Savon
|
17
23
|
autoload :ClassMethods, "emmy_extends/savon/class_methods"
|
18
24
|
autoload :Response, "emmy_extends/savon/response"
|
@@ -3,26 +3,20 @@ require "spec_helper"
|
|
3
3
|
describe EmmyExtends::EmHttpRequest do
|
4
4
|
|
5
5
|
around do |example|
|
6
|
-
|
7
|
-
EmmyMachine.fiber_block &example
|
8
|
-
end
|
6
|
+
EmmyMachine.run_block &example
|
9
7
|
end
|
10
8
|
|
11
9
|
it "should send request to github.com home page" do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
response = operation.sync
|
19
|
-
ensure
|
20
|
-
EventMachine.stop
|
21
|
-
end
|
10
|
+
request = EmmyHttp::Request.new(
|
11
|
+
method: 'get',
|
12
|
+
url: 'http://httpbin.org'
|
13
|
+
)
|
14
|
+
operation = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
|
15
|
+
response = operation.sync
|
22
16
|
|
23
17
|
expect(response.status).to be 200
|
24
18
|
expect(response.headers).to include("Content-Type")
|
25
|
-
expect(response.headers["Server"]).to eq("
|
19
|
+
expect(response.headers["Server"]).to eq("gunicorn/18.0")
|
26
20
|
expect(response.body.empty?).to be false
|
27
21
|
end
|
28
22
|
end
|
data/spec/httpi_spec.rb
CHANGED
@@ -4,18 +4,13 @@ require "httpi"
|
|
4
4
|
|
5
5
|
describe EmmyExtends::HTTPI do
|
6
6
|
around do |example|
|
7
|
-
|
8
|
-
EmmyMachine.fiber_block &example
|
9
|
-
end
|
7
|
+
EmmyMachine.run_block &example
|
10
8
|
end
|
11
9
|
|
12
10
|
it "should send request to github.com home page" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
ensure
|
17
|
-
EventMachine.stop
|
18
|
-
end
|
11
|
+
request = HTTPI.get("http://httpbin.org", :emmy)
|
12
|
+
response = request.sync
|
13
|
+
|
19
14
|
expect(response).to be_a(HTTPI::Response)
|
20
15
|
expect(response.code).to be 200
|
21
16
|
expect(response.headers).to include("Content-Type")
|
data/spec/mysql2_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "mysql2"
|
3
|
+
|
4
|
+
describe EmmyExtends::Mysql2 do
|
5
|
+
using EventObject
|
6
|
+
|
7
|
+
let(:delay) { 1.0/3 }
|
8
|
+
let(:query) { "SELECT sleep(#{delay}) as mysql2_query" }
|
9
|
+
let(:db) { EmmyExtends::Mysql2::Client.new }
|
10
|
+
|
11
|
+
context "fibers required" do
|
12
|
+
around do |example|
|
13
|
+
EmmyMachine.run_block &example
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should query create operation" do
|
17
|
+
operation = db.query query
|
18
|
+
expect(operation).to be_a EmmyExtends::Mysql2::Operation
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should execute query through sync" do
|
22
|
+
operation = db.query query
|
23
|
+
response = operation.sync
|
24
|
+
expect(response).to be_a Mysql2::Result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "without fibres" do
|
29
|
+
|
30
|
+
it "should execute query without fibers" do
|
31
|
+
result = nil
|
32
|
+
expect {
|
33
|
+
EmmyMachine.run do
|
34
|
+
operation = db.query query
|
35
|
+
EmmyMachine.watch(*operation)
|
36
|
+
operation.on :success do |response|
|
37
|
+
EmmyMachine.stop
|
38
|
+
result = response
|
39
|
+
end
|
40
|
+
|
41
|
+
operation.on :error do |error|
|
42
|
+
EmmyMachine.stop
|
43
|
+
raise error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
}.to_not raise_error
|
47
|
+
|
48
|
+
expect(result).to be_a Mysql2::Result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/savon_spec.rb
CHANGED
@@ -5,26 +5,21 @@ require "savon"
|
|
5
5
|
|
6
6
|
describe EmmyExtends::Savon do
|
7
7
|
around do |example|
|
8
|
-
|
9
|
-
EmmyMachine.fiber_block &example
|
10
|
-
end
|
8
|
+
EmmyMachine.run_block &example
|
11
9
|
end
|
12
10
|
|
13
11
|
it "should send SOAP request" do
|
14
12
|
HTTPI.adapter = :emmy
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ensure
|
26
|
-
EventMachine.stop
|
27
|
-
end
|
13
|
+
|
14
|
+
client = EmmyExtends::Savon.client(
|
15
|
+
wsdl: File.expand_path("../ConvertTemperature.asmx.xml", __FILE__),
|
16
|
+
convert_request_keys_to: :camelcase,
|
17
|
+
open_timeout: 10,
|
18
|
+
read_timeout: 10,
|
19
|
+
log: false
|
20
|
+
)
|
21
|
+
request = client.call(:convert_temp, :message => { :temperature => 30, :from_unit => "degreeCelsius", :to_unit => "degreeFahrenheit" })
|
22
|
+
response = request.sync
|
28
23
|
|
29
24
|
fahrenheit = response.body[:convert_temp_response][:convert_temp_result]
|
30
25
|
expect(fahrenheit).to eq("86")
|
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- che
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.6
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: emmy-http
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +127,9 @@ files:
|
|
127
127
|
- lib/emmy_extends/em_http_request/connection.rb
|
128
128
|
- lib/emmy_extends/httpi/adapter.rb
|
129
129
|
- lib/emmy_extends/httpi/operation.rb
|
130
|
+
- lib/emmy_extends/mysql2/client.rb
|
131
|
+
- lib/emmy_extends/mysql2/operation.rb
|
132
|
+
- lib/emmy_extends/mysql2/watcher.rb
|
130
133
|
- lib/emmy_extends/savon/class_methods.rb
|
131
134
|
- lib/emmy_extends/savon/model.rb
|
132
135
|
- lib/emmy_extends/savon/response.rb
|
@@ -138,6 +141,7 @@ files:
|
|
138
141
|
- spec/ConvertTemperature.asmx.xml
|
139
142
|
- spec/em_http_request_spec.rb
|
140
143
|
- spec/httpi_spec.rb
|
144
|
+
- spec/mysql2_spec.rb
|
141
145
|
- spec/savon_spec.rb
|
142
146
|
- spec/spec_helper.rb
|
143
147
|
homepage: ''
|
@@ -168,5 +172,6 @@ test_files:
|
|
168
172
|
- spec/ConvertTemperature.asmx.xml
|
169
173
|
- spec/em_http_request_spec.rb
|
170
174
|
- spec/httpi_spec.rb
|
175
|
+
- spec/mysql2_spec.rb
|
171
176
|
- spec/savon_spec.rb
|
172
177
|
- spec/spec_helper.rb
|