emmy-extends 0.1.6 → 0.1.7

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: 62c3d3f001e9b3d11387006dac45b263cc5c5b58
4
- data.tar.gz: 2604f4f3c1bf4574bc01b764dc2c33195d96f330
3
+ metadata.gz: 8a3710c71f753f825f9b64bec852bc517d174f26
4
+ data.tar.gz: d849f5f3e4753900dd30a76647b7161729bd4373
5
5
  SHA512:
6
- metadata.gz: 53f5b935129d09a71a202715b3a30dc3f07f3d33aff5964cebcd163e34f00c764f5199696ad78753916b74721891d60573d75359c560471d14f087b69292f40b
7
- data.tar.gz: 9e81ebdc54bcac45cf9db94ae0fced2b06efd296b995090134ff60e11e9833ce9bfbe46ea7c9ced6cfa7da9f9653eed3009a69eed607c10a23427f83b1e67b35
6
+ metadata.gz: 8dec14fbc285fe82e87924c1d26ca38d501e48e8cb7f40763b21ac18b65e7adba5b9a8595b9bbeb76bdd4a1647724e2f637900707771aba3134e34967e583c74
7
+ data.tar.gz: b41d0223c7801402509c2dd42258cb30f1d972f55e9909baeb47415922e55760d10a14df966b9f95a80996e484a1fe709c103e6d788cc765de7c39f0d91d64cc
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in emmy-extends.gemspec
4
4
  gemspec
5
5
 
6
- gem 'em-http-request', '~> 1.1.2'
6
+ gem 'em-http-request'
7
7
  gem 'mysql2'
8
8
  gem 'httpi'
9
9
  gem 'savon', github: 'chelovekov/savon', branch: 'version2'
data/emmy-extends.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'emmy_extends/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "emmy-extends"
8
8
  spec.version = EmmyExtends::VERSION
9
- spec.authors = ["che"]
10
- spec.email = ["chelovekov@gmail.com"]
9
+ spec.authors = ["inre"]
10
+ spec.email = ["inre.storm@gmail.com"]
11
11
  spec.summary = %q{Emmy support em-http-request, thin, savon, mysql2 etc.}
12
12
  #spec.description = %q{TODO: Write a longer description. Optional.}
13
13
  spec.homepage = ""
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "eventmachine", "~> 1.0.3"
21
+ #spec.add_dependency "eventmachine", "~> 1.0.3"
22
22
  spec.add_dependency "emmy-machine", "~> 0.1.6"
23
- spec.add_dependency "emmy-http", "~> 0.1.2"
23
+ spec.add_dependency "emmy-http", "~> 0.1.4"
24
24
 
25
25
  spec.add_development_dependency "rspec", "~> 3"
26
26
  spec.add_development_dependency "bundler", "~> 1.7"
@@ -1,11 +1,27 @@
1
+ using EventObject
2
+
1
3
  module EmmyExtends
2
- class EmHttpRequest::Adapter < EmmyHttp::Adapter
3
- using EventObject
4
+ class EmHttpRequest::Adapter
5
+ include EmmyHttp::Adapter
4
6
 
5
7
  attr_reader :http_request
6
8
  attr_reader :http_client
7
9
  attr_reader :body
8
10
  attr_reader :connection
11
+ attr_reader :operation
12
+ attr_reader :response
13
+
14
+ # required for adapter
15
+
16
+ def delegate=(operation)
17
+ @operation = operation
18
+ setup_http_request
19
+ setup_http_client
20
+ end
21
+
22
+ def to_a
23
+ ["tcp://#{operation.request.url.host}:#{operation.request.url.port}", EmmyMachine::Connection, method(:initialize_connection), self]
24
+ end
9
25
 
10
26
  def initialize_connection(conn)
11
27
  @connection = conn
@@ -32,20 +48,22 @@ module EmmyExtends
32
48
  conn.comm_inactivity_timeout = http_request.connopts.inactivity_timeout
33
49
 
34
50
  @body = ''
35
- delegate.init!(delegate, conn)
51
+ #operation.connection = conn # update connection handler
52
+ operation.init!(operation, conn)
36
53
 
37
54
  rescue EventMachine::ConnectionError => e
38
55
  EventMachine.next_tick { @http_client.close(e.message) }
39
- delegate.error!("connection error", self)
56
+ operation.error!("connection error", self)
40
57
  end
41
58
 
42
59
  def connection_options
43
60
  {
44
- connect_timeout: delegate.request.timeouts.connect,
45
- inactivity_timeout: delegate.request.timeouts.inactivity,
46
- :ssl => (delegate.request.ssl?) ? {
47
- :cert_chain_file => delegate.request.ssl.cert_chain_file,
48
- :verify_peer => (delegate.request.ssl.verify_peer == :peer)
61
+ connect_timeout: operation.request.timeouts.connect,
62
+ inactivity_timeout: operation.request.timeouts.inactivity,
63
+ ssl: (operation.request.ssl?) ? {
64
+ cert_chain_file: operation.request.ssl.cert_chain_file,
65
+ verify_peer: (operation.request.ssl.verify_peer == :peer),
66
+ ssl_version: operation.request.ssl.ssl_version
49
67
  } : {}
50
68
  }
51
69
  end
@@ -54,15 +72,15 @@ module EmmyExtends
54
72
  {
55
73
  redirects: 5,
56
74
  keepalive: false,
57
- path: delegate.request.url.path,
58
- query: delegate.request.url.query,
59
- body: encode_body(delegate.request.body),
60
- head: delegate.request.headers
75
+ path: operation.request.url.path,
76
+ query: operation.request.url.query,
77
+ body: encode_body(operation.request.body),
78
+ head: operation.request.headers
61
79
  }
62
80
  end
63
81
 
64
82
  def encode_body(body)
65
- return body if delegate.request.headers["Content-Encoding"] != "gzip"
83
+ return body if operation.request.headers["Content-Encoding"] != "gzip"
66
84
  wio = StringIO.new("w")
67
85
  begin
68
86
  w_gz = Zlib::GzipWriter.new(wio)
@@ -73,50 +91,40 @@ module EmmyExtends
73
91
  end
74
92
  end
75
93
 
76
- def setup
77
- raise 'delegator must be set before' unless delegate
78
- setup_http_request
79
- setup_http_client
80
- end
81
-
82
94
  def setup_http_client
83
95
  @http_client = begin
84
- type = delegate.request.type.to_s.upcase # http method
85
- http_client_options = HttpClientOptions.new(delegate.request.url, request_options, type)
96
+ type = operation.request.type.to_s.upcase # http method
97
+ http_client_options = HttpClientOptions.new(operation.request.url, request_options, type)
86
98
  EventMachine::HttpClient.new(@http_request, http_client_options).tap do |client|
87
99
  client.stream do |chunk|
88
100
  @body << chunk
89
101
  end
90
102
 
91
103
  client.headers do |response_header|
92
- delegate.head!(delegate, connection)
104
+ @response = EmmyHttp::Response.new
105
+ response.headers = http_client.response_header
106
+ response.status = status
107
+ operation.head!(response, operation, connection)
93
108
  end
94
109
 
95
110
  client.callback do
96
111
  if @http_client.response_header && @http_client.response_header.status.zero?
97
- delegate.error!("connection timed out", delegate, connection)
112
+ operation.error!("connection timed out", operation, connection)
98
113
  else
99
- delegate.success!(delegate.response, delegate, connection)
114
+ response.body = body
115
+ operation.success!(response, operation, connection)
100
116
  end
101
117
  end
102
118
 
103
119
  client.errback do |c|
104
- delegate.error!(client.error, delegate, connection)
120
+ operation.error!(client.error, operation, connection)
105
121
  end
106
122
  end
107
123
  end
108
124
  end
109
125
 
110
126
  def setup_http_request
111
- @http_request = EventMachine::HttpRequest.new(delegate.request.url, connection_options)
112
- end
113
-
114
- def to_a
115
- ["tcp://#{delegate.request.url.host}:#{delegate.request.url.port}", EmmyMachine::Connection, method(:initialize_connection), self]
116
- end
117
-
118
- def headers
119
- @http_client.response_header
127
+ @http_request = EventMachine::HttpRequest.new(operation.request.url, connection_options)
120
128
  end
121
129
 
122
130
  def status
@@ -1,3 +1,3 @@
1
1
  module EmmyExtends
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -17,7 +17,7 @@ describe EmmyExtends::EmHttpRequest do
17
17
 
18
18
  expect(response.status).to be 200
19
19
  expect(response.headers).to include("Content-Type")
20
- expect(response.headers["Server"]).to eq("gunicorn/18.0")
20
+ expect(response.headers["Server"]).to eq("nginx")
21
21
  expect(response.body.empty?).to be false
22
22
  end
23
23
 
@@ -32,7 +32,7 @@ describe EmmyExtends::EmHttpRequest do
32
32
  expect(operation.to_a.first).to eq("tcp://httpbin.org:443")
33
33
  expect(response.status).to be 200
34
34
  expect(response.headers).to include("Content-Type")
35
- expect(response.headers["Server"]).to eq("gunicorn/18.0")
35
+ expect(response.headers["Server"]).to eq("nginx")
36
36
  expect(response.body.empty?).to be false
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emmy-extends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
- - che
7
+ - inre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: eventmachine
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.0.3
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 1.0.3
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: emmy-machine
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +30,14 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 0.1.2
33
+ version: 0.1.4
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: 0.1.2
40
+ version: 0.1.4
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +82,7 @@ dependencies:
96
82
  version: '10.0'
97
83
  description:
98
84
  email:
99
- - chelovekov@gmail.com
85
+ - inre.storm@gmail.com
100
86
  executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
@@ -157,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
143
  version: '0'
158
144
  requirements: []
159
145
  rubyforge_project:
160
- rubygems_version: 2.4.1
146
+ rubygems_version: 2.4.3
161
147
  signing_key:
162
148
  specification_version: 4
163
149
  summary: Emmy support em-http-request, thin, savon, mysql2 etc.