emmy-extends 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +71 -3
- data/emmy-extends.gemspec +1 -1
- data/lib/emmy_extends/core_ext.rb +23 -0
- data/lib/emmy_extends/em_http_request/adapter.rb +6 -2
- data/lib/emmy_extends/httpi/adapter.rb +56 -0
- data/lib/emmy_extends/httpi/operation.rb +60 -0
- data/lib/emmy_extends/savon/class_methods.rb +17 -0
- data/lib/emmy_extends/savon/model.rb +8 -0
- data/lib/emmy_extends/savon/response.rb +54 -0
- data/lib/emmy_extends/thin/backend.rb +44 -0
- data/lib/emmy_extends/thin/class_methods.rb +9 -0
- data/lib/emmy_extends/thin/connection.rb +15 -0
- data/lib/emmy_extends/thin/controller.rb +45 -0
- data/lib/emmy_extends/version.rb +1 -1
- data/lib/emmy_extends.rb +22 -1
- data/spec/ConvertTemperature.asmx.xml +135 -0
- data/spec/em_http_request_spec.rb +13 -9
- data/spec/httpi_spec.rb +23 -0
- data/spec/savon_spec.rb +33 -0
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b715412f362627d471570cb954c2a0cbc67c915
|
4
|
+
data.tar.gz: c2cddcc8d334cb02a444651acbe73879b15d978f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dbb89b9ed86d5480f24462e76312707e66eca20682697c6c233b39e6317553af847c4ed5da7cd74787d83aa63b4871799e9875cc81bcf3fb6cf65199231eea1
|
7
|
+
data.tar.gz: 7b605d851a17de3ba6494c31b93b3f65df5d5a366a7c6f188a64bf7f22462aab263fdf80bacefa1f21395b7e4b076c6c61b141a4fa7917ea8792f67a655f2d0a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,8 @@ TODO: Write a gem description
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
+
gem 'httpi'
|
11
|
+
gem 'savon', github: 'chelovekov/savon' # if savon required
|
10
12
|
gem 'emmy-extends'
|
11
13
|
```
|
12
14
|
|
@@ -18,13 +20,79 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
$ gem install emmy-extends
|
20
22
|
|
21
|
-
## Usage
|
23
|
+
## Usage EmHttpRequest
|
22
24
|
|
23
|
-
|
25
|
+
```ruby
|
26
|
+
EmmyMachine.run_block do
|
27
|
+
using Fibre::Synchrony
|
28
|
+
request = EmmyHttp::Request.new(
|
29
|
+
method: 'get',
|
30
|
+
url: 'http://github.com'
|
31
|
+
)
|
32
|
+
operation1 = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
|
33
|
+
operation2 = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
|
34
|
+
response = [operation1, operation2].sync
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage HTTPI
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
EmmyMachine.run_block do
|
42
|
+
request = HTTPI.post("http://example.com", "bangarang", :emmy)
|
43
|
+
response = request.sync
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Usage Savon
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
EmmyMachine.run_block do
|
51
|
+
savon = EmmyExtends::Savon
|
52
|
+
client = savon.client(wsdl: "http://example.com?wsdl")
|
53
|
+
request = client.call(:authenticate) do
|
54
|
+
message username: "luke", password: "secret"
|
55
|
+
convert_request_keys_to :camelcase
|
56
|
+
end
|
57
|
+
response = request.sync
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class User
|
63
|
+
include EmmyExtends::Savon::Model
|
64
|
+
|
65
|
+
client wsdl: "http://example.com?wsdl"
|
66
|
+
global :basic_auth, "luke", "secret"
|
67
|
+
|
68
|
+
operations :authenticate, :find_user
|
69
|
+
end
|
70
|
+
user = User.new
|
71
|
+
response = user.authenticate(message: { username: "luke", secret: "secret" }).sync
|
72
|
+
```
|
73
|
+
|
74
|
+
## Usage Thin
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class Application < Sinatra::Base
|
78
|
+
get '/' do
|
79
|
+
'Hello world!'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
EmmyMachine.run do
|
84
|
+
app = Rack::Builder.new do
|
85
|
+
use Rack::Logger
|
86
|
+
run Application
|
87
|
+
end
|
88
|
+
|
89
|
+
EmmyMachine.bind(*EmmyExtends::Thin.server("tcp://localhost:65535", app, options))
|
90
|
+
end
|
91
|
+
```
|
24
92
|
|
25
93
|
## Contributing
|
26
94
|
|
27
|
-
1. Fork it ( https://github.com/
|
95
|
+
1. Fork it ( https://github.com/chelovekov/emmy-extends/fork )
|
28
96
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
97
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
98
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/emmy-extends.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "eventmachine", "~> 1.0.3"
|
22
22
|
spec.add_dependency "em-http-request", "~> 1.1.2"
|
23
23
|
spec.add_dependency "emmy-machine", "~> 0.1.3"
|
24
|
-
spec.add_dependency "emmy-http", "~> 0.1.
|
24
|
+
spec.add_dependency "emmy-http", "~> 0.1.1"
|
25
25
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3"
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.7"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
module CoreExt
|
3
|
+
refine Hash do
|
4
|
+
def transform_values
|
5
|
+
return enum_for(:transform_values) unless block_given?
|
6
|
+
result = self.class.new
|
7
|
+
each do |key, value|
|
8
|
+
result[key] = yield(value)
|
9
|
+
end
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
def stringify_keys
|
14
|
+
transform_keys{ |key| key.to_s }
|
15
|
+
end
|
16
|
+
|
17
|
+
def symbolize_keys
|
18
|
+
transform_keys{ |key| key.to_sym rescue key }
|
19
|
+
end
|
20
|
+
alias_method :to_options, :symbolize_keys
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -70,7 +70,7 @@ module EmmyExtends
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def setup_http_client
|
73
|
-
@http_client
|
73
|
+
@http_client = begin
|
74
74
|
EventMachine::HttpClient.new(@http_request, HttpClientOptions.new(delegate.request.url, request_options, delegate.request.method)).tap do |client|
|
75
75
|
client.stream do |chunk|
|
76
76
|
@body << chunk
|
@@ -81,7 +81,11 @@ module EmmyExtends
|
|
81
81
|
end
|
82
82
|
|
83
83
|
client.callback do
|
84
|
-
|
84
|
+
if @http_client.response_header && @http_client.response_header.status.zero?
|
85
|
+
delegate.error!("connection timed out", delegate, connection)
|
86
|
+
else
|
87
|
+
delegate.success!(delegate.response, delegate, connection)
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
client.errback do |c|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "httpi"
|
2
|
+
|
3
|
+
module EmmyExtends
|
4
|
+
class HTTPI::Adapter < ::HTTPI::Adapter::Base
|
5
|
+
register :emmy
|
6
|
+
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def initialize(request)
|
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
|
+
end
|
21
|
+
|
22
|
+
def setup_http_auth
|
23
|
+
unless @request.auth.type == :basic
|
24
|
+
raise NotSupportedError, "EM-HTTP-Request does only support HTTP basic auth"
|
25
|
+
end
|
26
|
+
@emmy_request.headers[:authorization] = @request.auth.credentials
|
27
|
+
end
|
28
|
+
|
29
|
+
def proxy_options
|
30
|
+
{
|
31
|
+
:host => @request.proxy.host,
|
32
|
+
:port => @request.proxy.port,
|
33
|
+
:authorization => [@request.proxy.user, @request.proxy.password]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
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
|
+
if @request.on_body
|
43
|
+
raise NotSupportedError, "EM-HTTP-Request does not support response streaming"
|
44
|
+
end
|
45
|
+
|
46
|
+
@emmy_request.method = method
|
47
|
+
@operation
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_request_url(url)
|
51
|
+
"%s://%s:%s%s" % [url.scheme, url.host, url.port, url.path]
|
52
|
+
end
|
53
|
+
|
54
|
+
#<<<
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class HTTPI::Operation
|
3
|
+
using EventObject
|
4
|
+
|
5
|
+
attr_reader :request
|
6
|
+
attr_reader :response
|
7
|
+
attr_reader :connection
|
8
|
+
attr_reader :http
|
9
|
+
|
10
|
+
events :success, :error
|
11
|
+
|
12
|
+
def initialize(http)
|
13
|
+
@http = http
|
14
|
+
@request = http.request
|
15
|
+
setup
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect
|
19
|
+
http.connect
|
20
|
+
end
|
21
|
+
|
22
|
+
def sync
|
23
|
+
Fiber.sync do |fiber|
|
24
|
+
connect
|
25
|
+
|
26
|
+
on :success do |response, operation, conn|
|
27
|
+
fiber.resume response
|
28
|
+
end
|
29
|
+
|
30
|
+
on :error do |error, operation, conn|
|
31
|
+
# FIXME: TimeoutError separate
|
32
|
+
fiber.leave ConnectionError, error.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
http.on :init do |connection|
|
39
|
+
@connection = connection
|
40
|
+
end
|
41
|
+
|
42
|
+
http.on :success do |res, http, conn|
|
43
|
+
@response = ::HTTPI::Response.new(*res)
|
44
|
+
success!(response, self, conn)
|
45
|
+
end
|
46
|
+
|
47
|
+
http.on :error do |error, http, conn|
|
48
|
+
error!(error, self, conn)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def code
|
53
|
+
0
|
54
|
+
end
|
55
|
+
|
56
|
+
def follow_redirect?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "savon"
|
2
|
+
|
3
|
+
# Example,
|
4
|
+
# client = Savon.client do
|
5
|
+
# endpoint "http://example.com"
|
6
|
+
# namespace "http://v1.example.com"
|
7
|
+
# end
|
8
|
+
# response = client.call(:authenticate, message: { username: "luke", password: "secret" }).sync
|
9
|
+
#
|
10
|
+
module EmmyExtends
|
11
|
+
module Savon::ClassMethods
|
12
|
+
def client(globals = {}, &block)
|
13
|
+
globals[:response_class] = Savon::Response
|
14
|
+
::Savon::Client.new(globals, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Savon::Response
|
3
|
+
using EventObject
|
4
|
+
|
5
|
+
attr_reader :request
|
6
|
+
attr_reader :response
|
7
|
+
attr_reader :connection
|
8
|
+
attr_reader :httpi
|
9
|
+
attr_reader :globals
|
10
|
+
attr_reader :locals
|
11
|
+
|
12
|
+
events :success, :error
|
13
|
+
|
14
|
+
def initialize(httpi, globals, locals)
|
15
|
+
@httpi = httpi
|
16
|
+
@request = httpi.request
|
17
|
+
@globals = globals
|
18
|
+
@locals = locals
|
19
|
+
setup
|
20
|
+
end
|
21
|
+
|
22
|
+
def connect
|
23
|
+
@httpi.connect
|
24
|
+
end
|
25
|
+
|
26
|
+
def sync
|
27
|
+
Fiber.sync do |fiber|
|
28
|
+
connect
|
29
|
+
|
30
|
+
on :success do |response, savon, conn|
|
31
|
+
fiber.resume response
|
32
|
+
end
|
33
|
+
|
34
|
+
on :error do |error, savon, conn|
|
35
|
+
# FIXME: TimeoutError separate
|
36
|
+
fiber.leave EmmyHttp::ConnectionError, error.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@httpi.on :success do |response, httpi, conn|
|
43
|
+
@response = ::Savon::Response.new(response, globals, locals)
|
44
|
+
@connection = conn
|
45
|
+
success!(@response, self, conn)
|
46
|
+
end
|
47
|
+
|
48
|
+
@httpi.on :error do |error, httpi, conn|
|
49
|
+
@connection = conn
|
50
|
+
error!(error, self, conn)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'thin'
|
2
|
+
|
3
|
+
module EmmyExtends
|
4
|
+
class Thin::Backend < ::Thin::Backends::Base
|
5
|
+
attr_accessor :url
|
6
|
+
|
7
|
+
def initialize(host, port, options)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect
|
12
|
+
raise "deprecated. you should start server through emmy.bind"
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
raise "deprecated. you should start server through emmy.bind"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Stops the server
|
20
|
+
def disconnect
|
21
|
+
puts "disconnect"
|
22
|
+
#EventMachine.stop_server(@signature)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_connection(conn)
|
26
|
+
@stopping = false
|
27
|
+
thin_connection = ::Thin::Connection.new(conn.signature)
|
28
|
+
thin_connection.backend = self
|
29
|
+
conn.delegate = thin_connection
|
30
|
+
super(thin_connection)
|
31
|
+
@running = true # FIXME: maybe not here
|
32
|
+
|
33
|
+
conn.following.post_init
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_a
|
37
|
+
[url, EmmyExtends::Thin::Connection, method(:initialize_connection)]
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{@host}:#{@port}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Thin::Connection < ::EventMachine::Connection
|
3
|
+
attr_accessor :delegate
|
4
|
+
|
5
|
+
def unbind(reason=nil)
|
6
|
+
@delegate.unbind
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(name, *a, &b)
|
10
|
+
@delegate.send(name, *a, &b)
|
11
|
+
end
|
12
|
+
|
13
|
+
#<<<
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EmmyExtends
|
2
|
+
class Thin::Controller < ::Thin::Controllers::Controller
|
3
|
+
|
4
|
+
def initialize(url, app, options)
|
5
|
+
@url = URL(url.to_s)
|
6
|
+
@app = app
|
7
|
+
super(options)
|
8
|
+
options[:backend] ||= Backend
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
server = ::Thin::Server.new(@options[:socket] || @url.host, @url.port, @options)
|
13
|
+
# Set options
|
14
|
+
server.pid_file = @options[:pid]
|
15
|
+
server.log_file = @options[:log]
|
16
|
+
server.timeout = @options[:timeout]
|
17
|
+
server.maximum_connections = @options[:max_conns]
|
18
|
+
server.maximum_persistent_connections = @options[:max_persistent_conns]
|
19
|
+
server.threaded = @options[:threaded]
|
20
|
+
server.no_epoll = @options[:no_epoll] if server.backend.respond_to?(:no_epoll=)
|
21
|
+
server.threadpool_size = @options[:threadpool_size] if server.threaded?
|
22
|
+
|
23
|
+
# ssl support
|
24
|
+
if @options[:ssl]
|
25
|
+
server.ssl = true
|
26
|
+
server.ssl_options = { :private_key_file => @options[:ssl_key_file], :cert_chain_file => @options[:ssl_cert_file], :verify_peer => !@options[:ssl_disable_verify] }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Detach the process, after this line the current process returns
|
30
|
+
server.daemonize if @options[:daemonize]
|
31
|
+
|
32
|
+
# +config+ must be called before changing privileges since it might require superuser power.
|
33
|
+
server.config
|
34
|
+
|
35
|
+
server.change_privilege @options[:user], @options[:group] if @options[:user] && @options[:group]
|
36
|
+
|
37
|
+
server.app = app
|
38
|
+
|
39
|
+
#server.on_restart { Thin::Command.run(:start, @options) }
|
40
|
+
|
41
|
+
# just return thin-backend
|
42
|
+
server.backend
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/emmy_extends/version.rb
CHANGED
data/lib/emmy_extends.rb
CHANGED
@@ -1,11 +1,32 @@
|
|
1
1
|
require "emmy_extends/version"
|
2
2
|
|
3
3
|
module EmmyExtends
|
4
|
+
autoload :CoreExt, "emmy_extends/core_ext"
|
5
|
+
|
4
6
|
module EmHttpRequest
|
5
7
|
autoload :Connection, "emmy_extends/em_http_request/connection"
|
6
|
-
autoload :Adapter,
|
8
|
+
autoload :Adapter, "emmy_extends/em_http_request/adapter"
|
9
|
+
end
|
10
|
+
|
11
|
+
module HTTPI
|
12
|
+
autoload :Adapter, "emmy_extends/httpi/adapter"
|
13
|
+
autoload :Operation, "emmy_extends/httpi/operation"
|
14
|
+
end
|
15
|
+
|
16
|
+
module Savon
|
17
|
+
autoload :ClassMethods, "emmy_extends/savon/class_methods"
|
18
|
+
autoload :Response, "emmy_extends/savon/response"
|
19
|
+
autoload :Model, "emmy_extends/savon/model"
|
20
|
+
|
21
|
+
extend ClassMethods
|
7
22
|
end
|
8
23
|
|
9
24
|
module Thin
|
25
|
+
autoload :Connection, "emmy_extends/thin/connection"
|
26
|
+
autoload :Backend, "emmy_extends/thin/backend"
|
27
|
+
autoload :Controller, "emmy_extends/thin/controller"
|
28
|
+
autoload :ClassMethods, "emmy_extends/thin/class_methods"
|
29
|
+
|
30
|
+
extend ClassMethods
|
10
31
|
end
|
11
32
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.webserviceX.NET/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.webserviceX.NET/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
|
3
|
+
<wsdl:types>
|
4
|
+
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
|
5
|
+
<s:element name="ConvertTemp">
|
6
|
+
<s:complexType>
|
7
|
+
<s:sequence>
|
8
|
+
<s:element minOccurs="1" maxOccurs="1" name="Temperature" type="s:double" />
|
9
|
+
<s:element minOccurs="1" maxOccurs="1" name="FromUnit" type="tns:TemperatureUnit" />
|
10
|
+
<s:element minOccurs="1" maxOccurs="1" name="ToUnit" type="tns:TemperatureUnit" />
|
11
|
+
</s:sequence>
|
12
|
+
</s:complexType>
|
13
|
+
</s:element>
|
14
|
+
<s:simpleType name="TemperatureUnit">
|
15
|
+
<s:restriction base="s:string">
|
16
|
+
<s:enumeration value="degreeCelsius" />
|
17
|
+
<s:enumeration value="degreeFahrenheit" />
|
18
|
+
<s:enumeration value="degreeRankine" />
|
19
|
+
<s:enumeration value="degreeReaumur" />
|
20
|
+
<s:enumeration value="kelvin" />
|
21
|
+
</s:restriction>
|
22
|
+
</s:simpleType>
|
23
|
+
<s:element name="ConvertTempResponse">
|
24
|
+
<s:complexType>
|
25
|
+
<s:sequence>
|
26
|
+
<s:element minOccurs="1" maxOccurs="1" name="ConvertTempResult" type="s:double" />
|
27
|
+
</s:sequence>
|
28
|
+
</s:complexType>
|
29
|
+
</s:element>
|
30
|
+
<s:element name="double" type="s:double" />
|
31
|
+
</s:schema>
|
32
|
+
</wsdl:types>
|
33
|
+
<wsdl:message name="ConvertTempSoapIn">
|
34
|
+
<wsdl:part name="parameters" element="tns:ConvertTemp" />
|
35
|
+
</wsdl:message>
|
36
|
+
<wsdl:message name="ConvertTempSoapOut">
|
37
|
+
<wsdl:part name="parameters" element="tns:ConvertTempResponse" />
|
38
|
+
</wsdl:message>
|
39
|
+
<wsdl:message name="ConvertTempHttpGetIn">
|
40
|
+
<wsdl:part name="Temperature" type="s:string" />
|
41
|
+
<wsdl:part name="FromUnit" type="s:string" />
|
42
|
+
<wsdl:part name="ToUnit" type="s:string" />
|
43
|
+
</wsdl:message>
|
44
|
+
<wsdl:message name="ConvertTempHttpGetOut">
|
45
|
+
<wsdl:part name="Body" element="tns:double" />
|
46
|
+
</wsdl:message>
|
47
|
+
<wsdl:message name="ConvertTempHttpPostIn">
|
48
|
+
<wsdl:part name="Temperature" type="s:string" />
|
49
|
+
<wsdl:part name="FromUnit" type="s:string" />
|
50
|
+
<wsdl:part name="ToUnit" type="s:string" />
|
51
|
+
</wsdl:message>
|
52
|
+
<wsdl:message name="ConvertTempHttpPostOut">
|
53
|
+
<wsdl:part name="Body" element="tns:double" />
|
54
|
+
</wsdl:message>
|
55
|
+
<wsdl:portType name="ConvertTemperatureSoap">
|
56
|
+
<wsdl:operation name="ConvertTemp">
|
57
|
+
<wsdl:input message="tns:ConvertTempSoapIn" />
|
58
|
+
<wsdl:output message="tns:ConvertTempSoapOut" />
|
59
|
+
</wsdl:operation>
|
60
|
+
</wsdl:portType>
|
61
|
+
<wsdl:portType name="ConvertTemperatureHttpGet">
|
62
|
+
<wsdl:operation name="ConvertTemp">
|
63
|
+
<wsdl:input message="tns:ConvertTempHttpGetIn" />
|
64
|
+
<wsdl:output message="tns:ConvertTempHttpGetOut" />
|
65
|
+
</wsdl:operation>
|
66
|
+
</wsdl:portType>
|
67
|
+
<wsdl:portType name="ConvertTemperatureHttpPost">
|
68
|
+
<wsdl:operation name="ConvertTemp">
|
69
|
+
<wsdl:input message="tns:ConvertTempHttpPostIn" />
|
70
|
+
<wsdl:output message="tns:ConvertTempHttpPostOut" />
|
71
|
+
</wsdl:operation>
|
72
|
+
</wsdl:portType>
|
73
|
+
<wsdl:binding name="ConvertTemperatureSoap" type="tns:ConvertTemperatureSoap">
|
74
|
+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
|
75
|
+
<wsdl:operation name="ConvertTemp">
|
76
|
+
<soap:operation soapAction="http://www.webserviceX.NET/ConvertTemp" style="document" />
|
77
|
+
<wsdl:input>
|
78
|
+
<soap:body use="literal" />
|
79
|
+
</wsdl:input>
|
80
|
+
<wsdl:output>
|
81
|
+
<soap:body use="literal" />
|
82
|
+
</wsdl:output>
|
83
|
+
</wsdl:operation>
|
84
|
+
</wsdl:binding>
|
85
|
+
<wsdl:binding name="ConvertTemperatureSoap12" type="tns:ConvertTemperatureSoap">
|
86
|
+
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
|
87
|
+
<wsdl:operation name="ConvertTemp">
|
88
|
+
<soap12:operation soapAction="http://www.webserviceX.NET/ConvertTemp" style="document" />
|
89
|
+
<wsdl:input>
|
90
|
+
<soap12:body use="literal" />
|
91
|
+
</wsdl:input>
|
92
|
+
<wsdl:output>
|
93
|
+
<soap12:body use="literal" />
|
94
|
+
</wsdl:output>
|
95
|
+
</wsdl:operation>
|
96
|
+
</wsdl:binding>
|
97
|
+
<wsdl:binding name="ConvertTemperatureHttpGet" type="tns:ConvertTemperatureHttpGet">
|
98
|
+
<http:binding verb="GET" />
|
99
|
+
<wsdl:operation name="ConvertTemp">
|
100
|
+
<http:operation location="/ConvertTemp" />
|
101
|
+
<wsdl:input>
|
102
|
+
<http:urlEncoded />
|
103
|
+
</wsdl:input>
|
104
|
+
<wsdl:output>
|
105
|
+
<mime:mimeXml part="Body" />
|
106
|
+
</wsdl:output>
|
107
|
+
</wsdl:operation>
|
108
|
+
</wsdl:binding>
|
109
|
+
<wsdl:binding name="ConvertTemperatureHttpPost" type="tns:ConvertTemperatureHttpPost">
|
110
|
+
<http:binding verb="POST" />
|
111
|
+
<wsdl:operation name="ConvertTemp">
|
112
|
+
<http:operation location="/ConvertTemp" />
|
113
|
+
<wsdl:input>
|
114
|
+
<mime:content type="application/x-www-form-urlencoded" />
|
115
|
+
</wsdl:input>
|
116
|
+
<wsdl:output>
|
117
|
+
<mime:mimeXml part="Body" />
|
118
|
+
</wsdl:output>
|
119
|
+
</wsdl:operation>
|
120
|
+
</wsdl:binding>
|
121
|
+
<wsdl:service name="ConvertTemperature">
|
122
|
+
<wsdl:port name="ConvertTemperatureSoap" binding="tns:ConvertTemperatureSoap">
|
123
|
+
<soap:address location="http://www.webservicex.net/ConvertTemperature.asmx" />
|
124
|
+
</wsdl:port>
|
125
|
+
<wsdl:port name="ConvertTemperatureSoap12" binding="tns:ConvertTemperatureSoap12">
|
126
|
+
<soap12:address location="http://www.webservicex.net/ConvertTemperature.asmx" />
|
127
|
+
</wsdl:port>
|
128
|
+
<wsdl:port name="ConvertTemperatureHttpGet" binding="tns:ConvertTemperatureHttpGet">
|
129
|
+
<http:address location="http://www.webservicex.net/ConvertTemperature.asmx" />
|
130
|
+
</wsdl:port>
|
131
|
+
<wsdl:port name="ConvertTemperatureHttpPost" binding="tns:ConvertTemperatureHttpPost">
|
132
|
+
<http:address location="http://www.webservicex.net/ConvertTemperature.asmx" />
|
133
|
+
</wsdl:port>
|
134
|
+
</wsdl:service>
|
135
|
+
</wsdl:definitions>
|
@@ -8,17 +8,21 @@ describe EmmyExtends::EmHttpRequest do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
it "should send request to github.com page" do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
it "should send request to github.com home page" do
|
12
|
+
begin
|
13
|
+
request = EmmyHttp::Request.new(
|
14
|
+
method: 'get',
|
15
|
+
url: 'http://github.com'
|
16
|
+
)
|
17
|
+
operation = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
|
18
|
+
response = operation.sync
|
19
|
+
ensure
|
20
|
+
EventMachine.stop
|
21
|
+
end
|
19
22
|
|
20
23
|
expect(response.status).to be 200
|
21
|
-
expect(response.headers).to include("
|
24
|
+
expect(response.headers).to include("Content-Type")
|
25
|
+
expect(response.headers["Server"]).to eq("GitHub.com")
|
22
26
|
expect(response.body.empty?).to be false
|
23
27
|
end
|
24
28
|
end
|
data/spec/httpi_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "emmy_extends/httpi/adapter"
|
3
|
+
require "httpi"
|
4
|
+
|
5
|
+
describe EmmyExtends::HTTPI do
|
6
|
+
around do |example|
|
7
|
+
EventMachine.run do
|
8
|
+
EmmyMachine.fiber_block &example
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should send request to github.com home page" do
|
13
|
+
begin
|
14
|
+
request = HTTPI.get("http://github.com", :emmy)
|
15
|
+
response = request.sync
|
16
|
+
ensure
|
17
|
+
EventMachine.stop
|
18
|
+
end
|
19
|
+
expect(response).to be_a(HTTPI::Response)
|
20
|
+
expect(response.code).to be 200
|
21
|
+
expect(response.headers).to include("Content-Type")
|
22
|
+
end
|
23
|
+
end
|
data/spec/savon_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "httpi"
|
3
|
+
require "emmy_extends/httpi/adapter"
|
4
|
+
require "savon"
|
5
|
+
|
6
|
+
describe EmmyExtends::Savon do
|
7
|
+
around do |example|
|
8
|
+
EventMachine.run do
|
9
|
+
EmmyMachine.fiber_block &example
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should send SOAP request" do
|
14
|
+
HTTPI.adapter = :emmy
|
15
|
+
begin
|
16
|
+
client = EmmyExtends::Savon.client(
|
17
|
+
wsdl: File.expand_path("../ConvertTemperature.asmx.xml", __FILE__),
|
18
|
+
convert_request_keys_to: :camelcase,
|
19
|
+
open_timeout: 10,
|
20
|
+
read_timeout: 10,
|
21
|
+
log: false
|
22
|
+
)
|
23
|
+
request = client.call(:convert_temp, :message => { :temperature => 30, :from_unit => "degreeCelsius", :to_unit => "degreeFahrenheit" })
|
24
|
+
response = request.sync
|
25
|
+
ensure
|
26
|
+
EventMachine.stop
|
27
|
+
end
|
28
|
+
|
29
|
+
fahrenheit = response.body[:convert_temp_response][:convert_temp_result]
|
30
|
+
expect(fahrenheit).to eq("86")
|
31
|
+
expect(response).to be_a(Savon::Response)
|
32
|
+
end
|
33
|
+
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.
|
4
|
+
version: 0.1.1
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,10 +122,23 @@ files:
|
|
122
122
|
- Rakefile
|
123
123
|
- emmy-extends.gemspec
|
124
124
|
- lib/emmy_extends.rb
|
125
|
+
- lib/emmy_extends/core_ext.rb
|
125
126
|
- lib/emmy_extends/em_http_request/adapter.rb
|
126
127
|
- lib/emmy_extends/em_http_request/connection.rb
|
128
|
+
- lib/emmy_extends/httpi/adapter.rb
|
129
|
+
- lib/emmy_extends/httpi/operation.rb
|
130
|
+
- lib/emmy_extends/savon/class_methods.rb
|
131
|
+
- lib/emmy_extends/savon/model.rb
|
132
|
+
- lib/emmy_extends/savon/response.rb
|
133
|
+
- lib/emmy_extends/thin/backend.rb
|
134
|
+
- lib/emmy_extends/thin/class_methods.rb
|
135
|
+
- lib/emmy_extends/thin/connection.rb
|
136
|
+
- lib/emmy_extends/thin/controller.rb
|
127
137
|
- lib/emmy_extends/version.rb
|
138
|
+
- spec/ConvertTemperature.asmx.xml
|
128
139
|
- spec/em_http_request_spec.rb
|
140
|
+
- spec/httpi_spec.rb
|
141
|
+
- spec/savon_spec.rb
|
129
142
|
- spec/spec_helper.rb
|
130
143
|
homepage: ''
|
131
144
|
licenses:
|
@@ -152,5 +165,8 @@ signing_key:
|
|
152
165
|
specification_version: 4
|
153
166
|
summary: Emmy support em-http-request, thin etc.
|
154
167
|
test_files:
|
168
|
+
- spec/ConvertTemperature.asmx.xml
|
155
169
|
- spec/em_http_request_spec.rb
|
170
|
+
- spec/httpi_spec.rb
|
171
|
+
- spec/savon_spec.rb
|
156
172
|
- spec/spec_helper.rb
|