emmy-extends 0.1.4 → 0.1.5

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: a0f9ee9bea9ad286bcb4470f18c00287c0db4239
4
- data.tar.gz: 9eb27aa0534a251b5682adf7dea625f440fc7bdb
3
+ metadata.gz: 3445b83150979fc91751faea105e47ab4959f2a4
4
+ data.tar.gz: bb928f912f37a0f3517b5a9b7da756ac8d0f494e
5
5
  SHA512:
6
- metadata.gz: 13ff69b825ba007f5305fa321db72faef64c722d14a730e268b6b398dc83c3312794497a922aee27bca1dc2f43e9bd6ebcab99dfe8851a9fe52d35cad781a2d3
7
- data.tar.gz: ebdaeaa9367b60bfd67dc686c4894d7b051081c59f207ae1fe894048db7549662ef09f7785487e89b479dde2e53ba865805b5e484614c7c19896da628cecc45c
6
+ metadata.gz: 29b398950507b0298e357c9338ceb5ff746509773fbf0f57b3e2c5aadefa954f8a1f638b4a8ff6cfb41f5da8a23a80bcd420500d855c4e15d9122c892cceb06a
7
+ data.tar.gz: be3c1b5191ca3f576b4eaae238a08a9fc875d65d24231d8c5e0983841f16f1a7d63c534b00ba2bc104f61b853464fa68fa7ad502ee2dd33929076729df5c7591
data/README.md CHANGED
@@ -1,28 +1,22 @@
1
1
  # Emmy::Extends
2
2
 
3
- TODO: Write a gem description
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
8
6
 
9
7
  ```ruby
10
- gem 'httpi'
8
+ gem 'em-http-request' # if savon em-http-request
9
+ gem 'httpi' # if httpi required
10
+ gem 'mysql2' # if mysql2 required
11
11
  gem 'savon', github: 'chelovekov/savon' # if savon required
12
12
  gem 'emmy-extends'
13
13
  ```
14
14
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install emmy-extends
22
-
23
15
  ## Usage EmHttpRequest
24
16
 
25
17
  ```ruby
18
+ require 'emmy_extends/em_http_request'
19
+
26
20
  EmmyMachine.run_block do
27
21
  using Fibre::Synchrony
28
22
  request = EmmyHttp::Request.new(
@@ -38,6 +32,8 @@ end
38
32
  ## Usage HTTPI
39
33
 
40
34
  ```ruby
35
+ require 'emmy_extends/httpi'
36
+
41
37
  EmmyMachine.run_block do
42
38
  request = HTTPI.post("http://example.com", "bangarang", :emmy)
43
39
  response = request.sync
@@ -47,6 +43,8 @@ end
47
43
  ## Usage Savon
48
44
 
49
45
  ```ruby
46
+ require 'emmy_extends/savon'
47
+
50
48
  EmmyMachine.run_block do
51
49
  savon = EmmyExtends::Savon
52
50
  client = savon.client(wsdl: "http://example.com?wsdl")
@@ -58,7 +56,11 @@ EmmyMachine.run_block do
58
56
  end
59
57
  ```
60
58
 
59
+ or,
60
+
61
61
  ```ruby
62
+ require 'emmy_extends/savon'
63
+
62
64
  class User
63
65
  include EmmyExtends::Savon::Model
64
66
 
@@ -74,6 +76,8 @@ response = user.authenticate(message: { username: "luke", secret: "secret" }).sy
74
76
  ## Usage Thin
75
77
 
76
78
  ```ruby
79
+ require 'emmy_extends/thin'
80
+
77
81
  class Application < Sinatra::Base
78
82
  get '/' do
79
83
  'Hello world!'
@@ -90,6 +94,22 @@ EmmyMachine.run do
90
94
  end
91
95
  ```
92
96
 
97
+ ## Usage Mysql2
98
+
99
+ ```ruby
100
+ require 'benchmark'
101
+ require 'emmy_extends/mysql2'
102
+
103
+ EmmyMachine.run_block do
104
+ conn1 = EmmyExtends::Mysql2::Client.new
105
+ conn2 = EmmyExtends::Mysql2::Client.new
106
+ puts Benchmark.measure {
107
+ using Fibre::Synchrony
108
+ [conn1.query("SELECT sleep(1) as mysql2_query"), conn2.query("SELECT sleep(2) as mysql2_query")].sync
109
+ }
110
+ end
111
+ ```
112
+
93
113
  ## Contributing
94
114
 
95
115
  1. Fork it ( https://github.com/chelovekov/emmy-extends/fork )
data/emmy-extends.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "emmy-extends"
8
8
  spec.version = EmmyExtends::VERSION
9
9
  spec.authors = ["che"]
10
- spec.email = ["max@kupibilet.ru"]
11
- spec.summary = %q{Emmy support em-http-request, thin etc.}
10
+ spec.email = ["chelovekov@gmail.com"]
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 = ""
14
14
  spec.license = "MIT"
@@ -56,11 +56,23 @@ module EmmyExtends
56
56
  keepalive: false,
57
57
  path: delegate.request.url.path,
58
58
  query: delegate.request.url.query,
59
- body: delegate.request.body,
59
+ body: encode_body(delegate.request.body),
60
60
  head: delegate.request.headers
61
61
  }
62
62
  end
63
63
 
64
+ def encode_body(body)
65
+ return body if delegate.request.headers["Content-Encoding"] != "gzip"
66
+ wio = StringIO.new("w")
67
+ begin
68
+ w_gz = Zlib::GzipWriter.new(wio)
69
+ w_gz.write(body)
70
+ wio.string
71
+ ensure
72
+ w_gz.close
73
+ end
74
+ end
75
+
64
76
  def setup
65
77
  raise 'delegator must be set before' unless delegate
66
78
  setup_http_request
@@ -70,7 +82,8 @@ module EmmyExtends
70
82
  def setup_http_client
71
83
  @http_client = begin
72
84
  method = delegate.request.method.to_s.upcase
73
- EventMachine::HttpClient.new(@http_request, HttpClientOptions.new(delegate.request.url, request_options, method)).tap do |client|
85
+ http_client_options = HttpClientOptions.new(delegate.request.url, request_options, method)
86
+ EventMachine::HttpClient.new(@http_request, http_client_options).tap do |client|
74
87
  client.stream do |chunk|
75
88
  @body << chunk
76
89
  end
@@ -3,7 +3,7 @@ module EmmyExtends
3
3
  using EventObject
4
4
 
5
5
  def query(sql, opts={})
6
- if ::EM.reactor_running?
6
+ if ::EventMachine.reactor_running?
7
7
  super(sql, opts.merge(:async => true))
8
8
  Mysql2::Operation.new(self)
9
9
  else
@@ -40,14 +40,14 @@ module EmmyExtends
40
40
  def setup
41
41
  @httpi.on :success do |response, httpi, conn|
42
42
  @response = ::Savon::Response.new(response, globals, locals)
43
- unless @response.http_error
44
- unless @response.soap_fault
43
+ unless @response.soap_fault
44
+ unless @response.http_error
45
45
  success!(@response, self, conn)
46
46
  else
47
- error!("SOAP error (#{@response.soap_fault.to_s})", self, conn)
47
+ error!("HTTP error (#{@response.http.code})", self, conn)
48
48
  end
49
49
  else
50
- error!("HTTP error (#{@response.http.code})", self, conn)
50
+ error!("SOAP error (#{@response.soap_fault.to_s})", self, conn)
51
51
  end
52
52
  end
53
53
 
@@ -1,3 +1,3 @@
1
1
  module EmmyExtends
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -7,7 +7,7 @@ describe EmmyExtends::EmHttpRequest do
7
7
  EmmyMachine.run_block &example
8
8
  end
9
9
 
10
- it "should send request to github.com home page" do
10
+ it "should send request to httpbin.org" do
11
11
  request = EmmyHttp::Request.new(
12
12
  method: 'get',
13
13
  url: 'http://httpbin.org'
@@ -20,4 +20,19 @@ describe EmmyExtends::EmHttpRequest do
20
20
  expect(response.headers["Server"]).to eq("gunicorn/18.0")
21
21
  expect(response.body.empty?).to be false
22
22
  end
23
+
24
+ it "should send https request to httpbin.org" do
25
+ request = EmmyHttp::Request.new(
26
+ method: 'get',
27
+ url: 'https://httpbin.org'
28
+ )
29
+ operation = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
30
+ response = operation.sync
31
+
32
+ expect(operation.to_a.first).to eq("tcp://httpbin.org:443")
33
+ expect(response.status).to be 200
34
+ expect(response.headers).to include("Content-Type")
35
+ expect(response.headers["Server"]).to eq("gunicorn/18.0")
36
+ expect(response.body.empty?).to be false
37
+ end
23
38
  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
4
+ version: 0.1.5
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-29 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: '10.0'
97
97
  description:
98
98
  email:
99
- - max@kupibilet.ru
99
+ - chelovekov@gmail.com
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
@@ -131,7 +131,6 @@ files:
131
131
  - lib/emmy_extends/thin/connection.rb
132
132
  - lib/emmy_extends/thin/controller.rb
133
133
  - lib/emmy_extends/version.rb
134
- - npm-debug.log
135
134
  - spec/ConvertTemperature.asmx.xml
136
135
  - spec/em_http_request_spec.rb
137
136
  - spec/httpi_spec.rb
@@ -161,7 +160,7 @@ rubyforge_project:
161
160
  rubygems_version: 2.4.1
162
161
  signing_key:
163
162
  specification_version: 4
164
- summary: Emmy support em-http-request, thin etc.
163
+ summary: Emmy support em-http-request, thin, savon, mysql2 etc.
165
164
  test_files:
166
165
  - spec/ConvertTemperature.asmx.xml
167
166
  - spec/em_http_request_spec.rb
data/npm-debug.log DELETED
@@ -1,62 +0,0 @@
1
- 0 info it worked if it ends with ok
2
- 1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', 'bit8' ]
3
- 2 info using npm@1.3.11
4
- 3 info using node@v0.10.21
5
- 4 verbose cache add [ 'bit8', null ]
6
- 5 verbose cache add name=undefined spec="bit8" args=["bit8",null]
7
- 6 verbose parsed url { protocol: null,
8
- 6 verbose parsed url slashes: null,
9
- 6 verbose parsed url auth: null,
10
- 6 verbose parsed url host: null,
11
- 6 verbose parsed url port: null,
12
- 6 verbose parsed url hostname: null,
13
- 6 verbose parsed url hash: null,
14
- 6 verbose parsed url search: null,
15
- 6 verbose parsed url query: null,
16
- 6 verbose parsed url pathname: 'bit8',
17
- 6 verbose parsed url path: 'bit8',
18
- 6 verbose parsed url href: 'bit8' }
19
- 7 silly lockFile dda9e3ba-bit8 bit8
20
- 8 verbose lock bit8 /Users/che/.npm/dda9e3ba-bit8.lock
21
- 9 silly lockFile dda9e3ba-bit8 bit8
22
- 10 silly lockFile dda9e3ba-bit8 bit8
23
- 11 verbose addNamed [ 'bit8', '' ]
24
- 12 verbose addNamed [ null, '*' ]
25
- 13 silly lockFile b74efb73-bit8 bit8@
26
- 14 verbose lock bit8@ /Users/che/.npm/b74efb73-bit8.lock
27
- 15 silly addNameRange { name: 'bit8', range: '*', hasData: false }
28
- 16 verbose url raw bit8
29
- 17 verbose url resolving [ 'https://registry.npmjs.org/', './bit8' ]
30
- 18 verbose url resolved https://registry.npmjs.org/bit8
31
- 19 info trying registry request attempt 1 at 18:31:24
32
- 20 http GET https://registry.npmjs.org/bit8
33
- 21 http 404 https://registry.npmjs.org/bit8
34
- 22 silly registry.get cb [ 404,
35
- 22 silly registry.get { date: 'Sat, 20 Sep 2014 14:31:25 GMT',
36
- 22 silly registry.get server: 'CouchDB/1.5.0 (Erlang OTP/R16B03)',
37
- 22 silly registry.get 'content-type': 'application/json',
38
- 22 silly registry.get 'cache-control': 'max-age=0',
39
- 22 silly registry.get 'content-length': '52',
40
- 22 silly registry.get 'accept-ranges': 'bytes',
41
- 22 silly registry.get via: '1.1 varnish',
42
- 22 silly registry.get age: '0',
43
- 22 silly registry.get 'x-served-by': 'cache-ams4133-AMS',
44
- 22 silly registry.get 'x-cache': 'MISS',
45
- 22 silly registry.get 'x-cache-hits': '0',
46
- 22 silly registry.get 'x-timer': 'S1411223485.110665,VS0,VE714',
47
- 22 silly registry.get 'keep-alive': 'timeout=10, max=50',
48
- 22 silly registry.get connection: 'Keep-Alive' } ]
49
- 23 silly lockFile b74efb73-bit8 bit8@
50
- 24 silly lockFile b74efb73-bit8 bit8@
51
- 25 error 404 'bit8' is not in the npm registry.
52
- 25 error 404 You should bug the author to publish it
53
- 25 error 404
54
- 25 error 404 Note that you can also install from a
55
- 25 error 404 tarball, folder, or http url, or git url.
56
- 26 error System Darwin 13.3.0
57
- 27 error command "node" "/usr/local/bin/npm" "install" "bit8"
58
- 28 error cwd /Users/che/Dropbox/Projects/emmy-extends
59
- 29 error node -v v0.10.21
60
- 30 error npm -v 1.3.11
61
- 31 error code E404
62
- 32 verbose exit [ 1, true ]