emmy-http 0.1.2 → 0.1.4
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/emmy-http.gemspec +6 -5
- data/lib/emmy_http.rb +5 -2
- data/lib/emmy_http/adapter.rb +4 -4
- data/lib/emmy_http/client/proxy.rb +11 -0
- data/lib/emmy_http/{request → client}/ssl.rb +1 -0
- data/lib/emmy_http/{request → client}/timeouts.rb +0 -0
- data/lib/emmy_http/model.rb +20 -0
- data/lib/emmy_http/operation.rb +20 -8
- data/lib/emmy_http/request.rb +40 -6
- data/lib/emmy_http/response.rb +31 -12
- data/lib/emmy_http/utils.rb +13 -0
- data/lib/emmy_http/version.rb +1 -1
- data/spec/emmy_http_spec.rb +8 -17
- metadata +19 -17
- data/Gemfile.lock +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d26296dca8f3723e6a546df57216f76bcac7b0d7
|
4
|
+
data.tar.gz: 703a92886d8d7d49ad9d1d3b23f0aa45fc7a8b27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba57901437a6bf3168f8e9eed31f9782f97adae2ec1a02597bd070b96502e34a6e0023e8a678d6773a619cc4886f4cf1b36dfef14927f8f2d2c73b9da68e6d0
|
7
|
+
data.tar.gz: f99f6ac836f5be0312df16339a0f0d5d482a1d1c34ec83af52c11b702e77043578252bf867792343686e42e7dcc4168c7031ddd34dcd45f52da9130ac4c12745
|
data/Gemfile
CHANGED
data/emmy-http.gemspec
CHANGED
@@ -6,9 +6,9 @@ require 'emmy_http/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "emmy-http"
|
8
8
|
spec.version = EmmyHttp::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
11
|
-
spec.summary = %q{
|
9
|
+
spec.authors = ["inre"]
|
10
|
+
spec.email = ["inre.storm@gmail.com"]
|
11
|
+
spec.summary = %q{EmmyHttp is a }
|
12
12
|
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
@@ -18,9 +18,10 @@ 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 "emmy-machine", "~> 0.1"
|
21
|
+
#spec.add_dependency "emmy-machine", "~> 0.1"
|
22
22
|
spec.add_dependency "fibre", "~> 0.9.3"
|
23
|
-
spec.add_dependency "
|
23
|
+
spec.add_dependency "util_pack", "~> 0.1"
|
24
|
+
spec.add_dependency "model_pack", "~> 0.9.6"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/emmy_http.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
require "model_pack"
|
2
2
|
require "emmy_http/version"
|
3
|
+
require "forwardable"
|
3
4
|
|
4
5
|
module EmmyHttp
|
5
6
|
class ConnectionError < StandardError; end
|
6
7
|
class TimeoutError < ConnectionError; end
|
7
8
|
|
8
9
|
autoload :Adapter, "emmy_http/adapter"
|
9
|
-
autoload :Timeouts, "emmy_http/
|
10
|
-
autoload :
|
10
|
+
autoload :Timeouts, "emmy_http/client/timeouts"
|
11
|
+
autoload :Proxy, "emmy_http/client/proxy"
|
12
|
+
autoload :SSL, "emmy_http/client/ssl"
|
11
13
|
autoload :Request, "emmy_http/request"
|
12
14
|
autoload :Operation, "emmy_http/operation"
|
13
15
|
autoload :Response, "emmy_http/response"
|
14
16
|
autoload :Timeout, "emmy_http/timeout"
|
17
|
+
autoload :Utils, "emmy_http/utils"
|
15
18
|
end
|
data/lib/emmy_http/adapter.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module EmmyHttp
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
%w(status headers body setup to_a).each do |method|
|
2
|
+
module Adapter
|
3
|
+
%w(delegate= to_a).each do |method|
|
6
4
|
define_method method do
|
7
5
|
raise 'method not implemented'
|
8
6
|
end
|
9
7
|
end
|
8
|
+
|
9
|
+
#<<<
|
10
10
|
end
|
11
11
|
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# class Google
|
3
|
+
# include EmmyHttp::Model
|
4
|
+
# adapter EmmyExtends::EmHttpRequest
|
5
|
+
# default EmmyHttp::Request.new(
|
6
|
+
# type: "post",
|
7
|
+
# headers: {
|
8
|
+
# 'Content-Type' => 'application/json'
|
9
|
+
# }
|
10
|
+
# )
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# google = Google.new(url: 'http://google.com')
|
14
|
+
# response = google.sync
|
15
|
+
|
16
|
+
module EmmyHttp
|
17
|
+
module Model
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/emmy_http/operation.rb
CHANGED
@@ -10,11 +10,10 @@ module EmmyHttp
|
|
10
10
|
events :init, :head, :success, :error
|
11
11
|
|
12
12
|
def initialize(request, adapter)
|
13
|
-
|
14
|
-
@
|
13
|
+
raise "invalid adapter" if adapter.nil? || !adapter.respond_to?(:to_a) || !adapter.respond_to?(:delegate=)
|
14
|
+
@request = request
|
15
|
+
@adapter = adapter
|
15
16
|
@adapter.delegate = self
|
16
|
-
@response = Response.new
|
17
|
-
setup
|
18
17
|
end
|
19
18
|
|
20
19
|
def connect
|
@@ -26,11 +25,23 @@ module EmmyHttp
|
|
26
25
|
# create connection
|
27
26
|
connect
|
28
27
|
|
28
|
+
on :init do |connection|
|
29
|
+
# update connection
|
30
|
+
@connection = connection
|
31
|
+
end
|
32
|
+
|
33
|
+
on :head do |response, operation, conn|
|
34
|
+
# set response
|
35
|
+
@response = response
|
36
|
+
end
|
37
|
+
|
29
38
|
on :success do |response, operation, conn|
|
39
|
+
# return response
|
30
40
|
fiber.resume response
|
31
41
|
end
|
32
42
|
|
33
43
|
on :error do |error, operation, conn|
|
44
|
+
# return error as exception
|
34
45
|
fiber.leave ConnectionError, error.to_s
|
35
46
|
end
|
36
47
|
end
|
@@ -42,13 +53,13 @@ module EmmyHttp
|
|
42
53
|
|
43
54
|
def serializable_hash
|
44
55
|
{
|
45
|
-
request:
|
56
|
+
request: request.serializable_hash,
|
46
57
|
response: response && response.serializable_hash
|
47
58
|
}
|
48
59
|
end
|
49
60
|
|
50
61
|
private
|
51
|
-
|
62
|
+
=begin
|
52
63
|
def setup
|
53
64
|
adapter.setup
|
54
65
|
|
@@ -57,19 +68,20 @@ module EmmyHttp
|
|
57
68
|
end
|
58
69
|
|
59
70
|
on :head do |operation, conn|
|
71
|
+
@response = request.response_class.new
|
60
72
|
response.headers = operation.adapter.headers
|
61
73
|
end
|
62
74
|
|
63
75
|
on :success do |response, operation, conn|
|
64
76
|
response.status = operation.adapter.status
|
65
|
-
response.body
|
77
|
+
response.body = operation.adapter.body
|
66
78
|
end
|
67
79
|
|
68
80
|
on :error do |error, operation, conn|
|
69
81
|
response.status = operation.adapter.status
|
70
82
|
end
|
71
83
|
end
|
72
|
-
|
84
|
+
=end
|
73
85
|
#<<<
|
74
86
|
end
|
75
87
|
end
|
data/lib/emmy_http/request.rb
CHANGED
@@ -1,25 +1,59 @@
|
|
1
1
|
module EmmyHttp
|
2
2
|
class Request
|
3
3
|
include ModelPack::Document
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
#def_delegator :operation, :sync, :init, :head, :success, :error, :init!, :head!, :success!, :error!, :to_a
|
4
7
|
|
5
8
|
attribute :type, default: "get" # word *method* reserved in ruby
|
6
9
|
attribute :url,
|
7
10
|
writer: ->(url) { url.is_a?(URI) ? url : URI.parse(url) },
|
8
11
|
serialize: ->(value) { value.to_s }
|
9
12
|
dictionary :headers
|
10
|
-
|
11
|
-
attribute :
|
12
|
-
|
13
|
-
|
13
|
+
|
14
|
+
attribute :query # replace url.query
|
15
|
+
# POST, PUT
|
16
|
+
attribute :body # string, json hash
|
17
|
+
attribute :form # hash form
|
18
|
+
attribute :file # path
|
19
|
+
|
20
|
+
attribute :keep_alive, predicate: true
|
21
|
+
attribute :redirects, default: 6
|
22
|
+
|
23
|
+
object :timeouts, class_name: Timeouts, default: Timeouts
|
14
24
|
object :ssl, class_name: SSL
|
25
|
+
object :proxy, class_name: Proxy
|
26
|
+
|
27
|
+
attribute :adapter,
|
28
|
+
writer: ->(class_name) { class_name.is_a?(String) ? constantize(class_name) : class_name },
|
29
|
+
serialize: ->(value) { value.to_s }
|
30
|
+
=begin
|
31
|
+
attribute :response_class,
|
32
|
+
writer: ->(class_name) { class_name.is_a?(String) ? constantize(class_name) : class_name },
|
33
|
+
serialize: ->(value) { value.to_s }
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@response_class = Response
|
37
|
+
end
|
38
|
+
=end
|
39
|
+
def operation
|
40
|
+
@operation ||= EmmyHttp::Operation.new(self, adapter)
|
41
|
+
end
|
42
|
+
|
43
|
+
def sync
|
44
|
+
operation.sync
|
45
|
+
end
|
15
46
|
|
16
47
|
# FIXME: move to model_pack
|
17
48
|
def ssl?
|
18
49
|
!!ssl
|
19
50
|
end
|
20
51
|
|
21
|
-
|
22
|
-
|
52
|
+
private
|
53
|
+
|
54
|
+
def constantize(class_name)
|
55
|
+
return nil unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ class_name
|
56
|
+
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
23
57
|
end
|
24
58
|
|
25
59
|
#<<<
|
data/lib/emmy_http/response.rb
CHANGED
@@ -3,22 +3,41 @@ module EmmyHttp
|
|
3
3
|
include ModelPack::Document
|
4
4
|
|
5
5
|
attribute :status
|
6
|
-
dictionary :headers, writer: -> (head) { convert_headers(head) }
|
6
|
+
dictionary :headers, writer: -> (head) { EmmyHttp::Utils.convert_headers(head) }
|
7
7
|
attribute :body
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def reset
|
10
|
+
@status = 0
|
11
|
+
@headers = {}
|
12
|
+
@body = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def chunked_encoding?
|
16
|
+
headers['Transfer-Encoding'] =~ /chunked/i
|
17
|
+
end
|
18
|
+
|
19
|
+
def keepalive?
|
20
|
+
headers['Keep-Alive'] =~ /keep-alive/i
|
21
|
+
end
|
22
|
+
|
23
|
+
def compressed?
|
24
|
+
headers['Content-Encoding'] =~ /gzip|compressed|deflate/i
|
11
25
|
end
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
def location
|
28
|
+
headers['Location']
|
29
|
+
end
|
30
|
+
|
31
|
+
def content_length
|
32
|
+
headers['Content-Length'].to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
def redirection?
|
36
|
+
300 <= status && 400 > status
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_a
|
40
|
+
[status, headers, body]
|
22
41
|
end
|
23
42
|
|
24
43
|
#<<<
|
data/lib/emmy_http/version.rb
CHANGED
data/spec/emmy_http_spec.rb
CHANGED
@@ -17,24 +17,11 @@ describe EmmyHttp do
|
|
17
17
|
extend self
|
18
18
|
end
|
19
19
|
|
20
|
-
class FakeAdapter
|
20
|
+
class FakeAdapter
|
21
|
+
attr_accessor :delegate
|
22
|
+
include EmmyHttp::Adapter
|
21
23
|
using EventObject
|
22
24
|
|
23
|
-
def status
|
24
|
-
200
|
25
|
-
end
|
26
|
-
|
27
|
-
def headers
|
28
|
-
{'CONTENT_TYPE' => 'text/html'}
|
29
|
-
end
|
30
|
-
|
31
|
-
def body
|
32
|
-
"OK"
|
33
|
-
end
|
34
|
-
|
35
|
-
def setup
|
36
|
-
end
|
37
|
-
|
38
25
|
def initialize_connection
|
39
26
|
self.delegate.init! delegate
|
40
27
|
end
|
@@ -42,7 +29,11 @@ describe EmmyHttp do
|
|
42
29
|
def connected(conn)
|
43
30
|
# replace request with timer
|
44
31
|
EventMachine.add_timer(0) do
|
45
|
-
|
32
|
+
response = EmmyHttp::Response.new
|
33
|
+
response.headers = {'CONTENT_TYPE' => 'text/html'}
|
34
|
+
response.status = 200
|
35
|
+
self.delegate.head!(response, delegate, conn)
|
36
|
+
response.body = "OK"
|
46
37
|
self.delegate.success!(delegate.response, delegate, conn)
|
47
38
|
end
|
48
39
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emmy-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fibre
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.9.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.9.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: util_pack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: model_pack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.9.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:
|
54
|
+
version: 0.9.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,13 +96,12 @@ dependencies:
|
|
96
96
|
version: '3'
|
97
97
|
description:
|
98
98
|
email:
|
99
|
-
-
|
99
|
+
- inre.storm@gmail.com
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- Gemfile
|
105
|
-
- Gemfile.lock
|
106
105
|
- LICENSE.txt
|
107
106
|
- README.md
|
108
107
|
- Rakefile
|
@@ -110,13 +109,16 @@ files:
|
|
110
109
|
- lib/emmy_http.rb
|
111
110
|
- lib/emmy_http/adapter.rb
|
112
111
|
- lib/emmy_http/backend.rb
|
112
|
+
- lib/emmy_http/client/proxy.rb
|
113
|
+
- lib/emmy_http/client/ssl.rb
|
114
|
+
- lib/emmy_http/client/timeouts.rb
|
115
|
+
- lib/emmy_http/model.rb
|
113
116
|
- lib/emmy_http/operation.rb
|
114
117
|
- lib/emmy_http/request.rb
|
115
|
-
- lib/emmy_http/request/ssl.rb
|
116
|
-
- lib/emmy_http/request/timeouts.rb
|
117
118
|
- lib/emmy_http/response.rb
|
118
119
|
- lib/emmy_http/server/options.rb
|
119
120
|
- lib/emmy_http/timeout.rb
|
121
|
+
- lib/emmy_http/utils.rb
|
120
122
|
- lib/emmy_http/version.rb
|
121
123
|
- pkg/emmy-http-0.1.0.gem
|
122
124
|
- pkg/emmy-http-0.1.1.gem
|
@@ -142,10 +144,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
144
|
version: '0'
|
143
145
|
requirements: []
|
144
146
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.4.
|
147
|
+
rubygems_version: 2.4.3
|
146
148
|
signing_key:
|
147
149
|
specification_version: 4
|
148
|
-
summary:
|
150
|
+
summary: EmmyHttp is a
|
149
151
|
test_files:
|
150
152
|
- spec/emmy_http_spec.rb
|
151
153
|
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
emmy-http (0.1.2)
|
5
|
-
emmy-machine (~> 0.1)
|
6
|
-
fibre (~> 0.9.3)
|
7
|
-
model_pack (~> 0.9)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
diff-lcs (1.2.5)
|
13
|
-
emmy-machine (0.1.6)
|
14
|
-
eventmachine (~> 1.0.3)
|
15
|
-
fibre (~> 0.9)
|
16
|
-
event_object (0.9.0)
|
17
|
-
eventmachine (1.0.3)
|
18
|
-
fibre (0.9.6)
|
19
|
-
event_object (~> 0.9)
|
20
|
-
model_pack (0.9.3)
|
21
|
-
rake (10.3.2)
|
22
|
-
rspec (3.1.0)
|
23
|
-
rspec-core (~> 3.1.0)
|
24
|
-
rspec-expectations (~> 3.1.0)
|
25
|
-
rspec-mocks (~> 3.1.0)
|
26
|
-
rspec-core (3.1.3)
|
27
|
-
rspec-support (~> 3.1.0)
|
28
|
-
rspec-expectations (3.1.1)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.1.0)
|
31
|
-
rspec-mocks (3.1.0)
|
32
|
-
rspec-support (~> 3.1.0)
|
33
|
-
rspec-support (3.1.0)
|
34
|
-
|
35
|
-
PLATFORMS
|
36
|
-
ruby
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
bundler (~> 1.6)
|
40
|
-
emmy-http!
|
41
|
-
rake (~> 10.0)
|
42
|
-
rspec (~> 3)
|