emmy-extends 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59e4184470b8f3962a3af837e984bd1f0ea3b3e9
4
+ data.tar.gz: bb4e3b35b44c3ed09d52456ce407e447788fbc70
5
+ SHA512:
6
+ metadata.gz: bf8f3be8054e75eddf97fa0a8023c0ed5cce02c2451aee53815c4d3edc8a601c9bf3e31f3d9812e468ced94309301a234f20a2a3d2451e65700ef6cfeb3013f4
7
+ data.tar.gz: edbd5b2d7b8e64f0fdc0a48a94d623bf9db02486e3a10ecfb57e607cd8e8518a0aa710782d01147ae82775eabea2683be60322136dbedf264b099eb799801f29
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emmy-extends.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 che
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Emmy::Extends
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'emmy-extends'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install emmy-extends
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/emmy-extends/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'emmy_extends/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "emmy-extends"
8
+ spec.version = EmmyExtends::VERSION
9
+ spec.authors = ["che"]
10
+ spec.email = ["max@kupibilet.ru"]
11
+ spec.summary = %q{Emmy support em-http-request, thin etc.}
12
+ #spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "eventmachine", "~> 1.0.3"
22
+ spec.add_dependency "em-http-request", "~> 1.1.2"
23
+ spec.add_dependency "emmy-machine", "~> 0.1.3"
24
+ spec.add_dependency "emmy-http", "~> 0.1.0"
25
+
26
+ spec.add_development_dependency "rspec", "~> 3"
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
@@ -0,0 +1,11 @@
1
+ require "emmy_extends/version"
2
+
3
+ module EmmyExtends
4
+ module EmHttpRequest
5
+ autoload :Connection, "emmy_extends/em_http_request/connection"
6
+ autoload :Adapter, "emmy_extends/em_http_request/adapter"
7
+ end
8
+
9
+ module Thin
10
+ end
11
+ end
@@ -0,0 +1,110 @@
1
+ require 'em-http-request'
2
+
3
+ module EmmyExtends
4
+ class EmHttpRequest::Adapter < EmmyHttp::Adapter
5
+ using EventObject
6
+
7
+ attr_reader :http_request
8
+ attr_reader :http_client
9
+ attr_reader :body
10
+ attr_reader :connection
11
+
12
+ def initialize_connection(conn)
13
+ @connection = conn
14
+ conn.extend EmHttpRequest::Connection
15
+ @http_request.conn = conn
16
+ @http_request.post_init
17
+
18
+ conn.on :connect do
19
+ http_request.connection_completed
20
+ end
21
+
22
+ conn.on :data do |chunk|
23
+ http_request.receive_data chunk
24
+ end
25
+
26
+ conn.on :close do |reason=nil|
27
+ http_request.unbind(reason)
28
+ end
29
+
30
+ # before connection_completed
31
+ @http_request.finalize_request(@http_client)
32
+
33
+ conn.pending_connect_timeout = http_request.connopts.connect_timeout
34
+ conn.comm_inactivity_timeout = http_request.connopts.inactivity_timeout
35
+
36
+ @body = ''
37
+ delegate.init!(delegate, conn)
38
+
39
+ rescue EventMachine::ConnectionError => e
40
+ EventMachine.next_tick { @http_client.close(e.message) }
41
+ delegate.error!("connection error", self)
42
+ end
43
+
44
+ def connection_options
45
+ {
46
+ connect_timeout: delegate.request.timeouts.connect,
47
+ inactivity_timeout: delegate.request.timeouts.inactivity,
48
+ :ssl => (delegate.request.ssl?) ? {
49
+ :cert_chain_file => delegate.request.ssl.cert_chain_file,
50
+ :verify_peer => (delegate.request.ssl.verify_peer == :peer)
51
+ } : {}
52
+ }
53
+ end
54
+
55
+ def request_options
56
+ {
57
+ redirects: 5,
58
+ keepalive: false,
59
+ path: delegate.request.url.path,
60
+ query: delegate.request.url.query,
61
+ body: delegate.request.body,
62
+ head: delegate.request.headers
63
+ }
64
+ end
65
+
66
+ def setup
67
+ raise 'delegator must be set before' unless delegate
68
+ setup_http_request
69
+ setup_http_client
70
+ end
71
+
72
+ def setup_http_client
73
+ @http_client ||= begin
74
+ EventMachine::HttpClient.new(@http_request, HttpClientOptions.new(delegate.request.url, request_options, delegate.request.method)).tap do |client|
75
+ client.stream do |chunk|
76
+ @body << chunk
77
+ end
78
+
79
+ client.headers do |response_header|
80
+ delegate.head!(delegate, connection)
81
+ end
82
+
83
+ client.callback do
84
+ delegate.success!(delegate, connection)
85
+ end
86
+
87
+ client.errback do |c|
88
+ delegate.error!(client.error, delegate, connection)
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def setup_http_request
95
+ @http_request = EventMachine::HttpRequest.new(delegate.request.url, connection_options)
96
+ end
97
+
98
+ def to_a
99
+ ["tcp://#{delegate.request.url.host}:#{delegate.request.url.port}", EmmyMachine::Connection, method(:initialize_connection), self]
100
+ end
101
+
102
+ def headers
103
+ @http_client.response_header
104
+ end
105
+
106
+ def status
107
+ (@http_client.error || @http_client.response_header.empty?) ? 0 : @http_client.response_header.status
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,15 @@
1
+ module EmmyExtends
2
+ module EmHttpRequest::Connection
3
+ def self.extended(base)
4
+ base.extend EventMachine::Deferrable
5
+ end
6
+
7
+ def succeed
8
+ @callback.call
9
+ end
10
+
11
+ def callback(&b)
12
+ @callback = b
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module EmmyExtends
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe EmmyExtends::EmHttpRequest do
4
+
5
+ around do |example|
6
+ EventMachine.run do
7
+ EmmyMachine.fiber_block &example
8
+ end
9
+ end
10
+
11
+ it "should send request to github.com page" do
12
+ request = EmmyHttp::Request.new(
13
+ method: 'get',
14
+ url: 'http://github.com'
15
+ )
16
+ operation = EmmyHttp::Operation.new(request, EmmyExtends::EmHttpRequest::Adapter.new)
17
+ response = operation.sync
18
+ EventMachine.stop
19
+
20
+ expect(response.status).to be 200
21
+ expect(response.headers).to include("CONTENT_TYPE")
22
+ expect(response.body.empty?).to be false
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require File.expand_path("./lib/emmy_extends")
5
+ require "emmy_machine"
6
+ require "emmy_http"
7
+ require "fibre"
8
+
9
+ using EventObject
10
+ Fibre.pool.on :error do |e|
11
+ raise e
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.color = true
16
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emmy-extends
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - che
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: em-http-request
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: emmy-machine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: emmy-http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ description:
112
+ email:
113
+ - max@kupibilet.ru
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - emmy-extends.gemspec
124
+ - lib/emmy_extends.rb
125
+ - lib/emmy_extends/em_http_request/adapter.rb
126
+ - lib/emmy_extends/em_http_request/connection.rb
127
+ - lib/emmy_extends/version.rb
128
+ - spec/em_http_request_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Emmy support em-http-request, thin etc.
154
+ test_files:
155
+ - spec/em_http_request_spec.rb
156
+ - spec/spec_helper.rb