restify 1.0.0 → 1.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/restify/adapter/typhoeus.rb +46 -32
- data/lib/restify/resource.rb +5 -12
- data/lib/restify/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b00cff50046f420707ed6d6e8851d74e1392f5f
|
4
|
+
data.tar.gz: fa5553ba030b9ec8bcd2457d4c24a866ad1db293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76ad0f4229b26ba714763793a086ba2cffb62642fa1ebb329037e1b542a5802ace3f29acc1220100488f7010b2eae5963a729d812475d17fa7834e43079a1004
|
7
|
+
data.tar.gz: 32908687b5e5b3234ccc5985cf1184a179d60f5589383482a4dff87abf168f7dbbefe101b4f7a4fcbe0d5ccb10b0b2d5e2c9a46dbae11dfd9cf54ddedb94baae
|
@@ -3,30 +3,23 @@ require 'typhoeus'
|
|
3
3
|
module Restify
|
4
4
|
module Adapter
|
5
5
|
class Typhoeus < Base
|
6
|
-
|
7
|
-
@queue = Queue.new
|
8
|
-
@hydra = ::Typhoeus::Hydra.new
|
9
|
-
@options = options
|
6
|
+
attr_reader :sync
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@hydra.queue req
|
8
|
+
DEFAULT_HEADERS = {
|
9
|
+
'Expect' => '',
|
10
|
+
'Transfer-Encoding' => ''
|
11
|
+
}.freeze
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
puts "#{self.class}: #{e.message}"
|
24
|
-
end
|
25
|
-
end
|
13
|
+
def initialize(sync: false, **options)
|
14
|
+
@queue = Queue.new
|
15
|
+
@sync = sync
|
16
|
+
@hydra = ::Typhoeus::Hydra.new(pipelining: true, **options)
|
17
|
+
|
18
|
+
start unless sync?
|
26
19
|
end
|
27
20
|
|
28
21
|
def sync?
|
29
|
-
@
|
22
|
+
@sync
|
30
23
|
end
|
31
24
|
|
32
25
|
def queue(request, writer)
|
@@ -48,26 +41,47 @@ module Restify
|
|
48
41
|
req = ::Typhoeus::Request.new \
|
49
42
|
request.uri,
|
50
43
|
method: request.method,
|
51
|
-
headers: request.headers,
|
44
|
+
headers: DEFAULT_HEADERS.merge(request.headers),
|
52
45
|
body: request.body
|
53
46
|
|
54
|
-
req.on_complete
|
55
|
-
|
56
|
-
|
57
|
-
body = response.body
|
47
|
+
req.on_complete {|response| handle(response, writer, request) }
|
48
|
+
req
|
49
|
+
end
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
51
|
+
def handle(native_response, writer, request)
|
52
|
+
writer.fulfill convert_back(native_response, request)
|
62
53
|
|
63
|
-
|
54
|
+
@hydra.queue convert(*@queue.pop(true)) while !@queue.empty?
|
55
|
+
end
|
64
56
|
|
65
|
-
|
66
|
-
|
67
|
-
|
57
|
+
def convert_back(response, request)
|
58
|
+
uri = request.uri
|
59
|
+
status = response.code
|
60
|
+
body = response.body
|
61
|
+
headers = convert_headers(response.headers)
|
62
|
+
|
63
|
+
::Restify::Response.new(request, uri, status, headers, body)
|
64
|
+
end
|
65
|
+
|
66
|
+
def convert_headers(headers)
|
67
|
+
headers.each_with_object({}) do |header, memo|
|
68
|
+
memo[header[0].upcase.tr('-', '_')] = header[1]
|
68
69
|
end
|
70
|
+
end
|
69
71
|
|
70
|
-
|
72
|
+
def start
|
73
|
+
Thread.new do
|
74
|
+
loop do
|
75
|
+
begin
|
76
|
+
while (req = convert(*@queue.pop))
|
77
|
+
@hydra.queue req
|
78
|
+
@hydra.run if @queue.empty?
|
79
|
+
end
|
80
|
+
rescue StandardError => e
|
81
|
+
puts "#{self.class}: #{e.message}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
71
85
|
end
|
72
86
|
end
|
73
87
|
end
|
data/lib/restify/resource.rb
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require 'forwardable'
|
3
2
|
|
4
3
|
module Restify
|
5
4
|
#
|
6
|
-
class Resource <
|
7
|
-
extend Forwardable
|
5
|
+
class Resource < SimpleDelegator
|
8
6
|
|
9
7
|
# @api private
|
10
8
|
#
|
11
9
|
def initialize(context, response: nil, data: nil, relations: {})
|
12
|
-
|
10
|
+
super(data)
|
11
|
+
|
13
12
|
@context = context
|
14
13
|
@response = response
|
15
14
|
@relations = relations
|
16
15
|
end
|
17
16
|
|
18
|
-
# @api private
|
19
|
-
#
|
20
|
-
def __getobj__
|
21
|
-
@data
|
22
|
-
end
|
23
|
-
|
24
17
|
# Check if resource has a relation with given name.
|
25
18
|
#
|
26
19
|
# @param name [String, Symbol] Relation name.
|
@@ -55,7 +48,7 @@ module Restify
|
|
55
48
|
#
|
56
49
|
# @return [Object] Response data.
|
57
50
|
#
|
58
|
-
|
51
|
+
alias data __getobj__
|
59
52
|
|
60
53
|
# @!method response
|
61
54
|
#
|
@@ -104,7 +97,7 @@ module Restify
|
|
104
97
|
# @api private
|
105
98
|
def inspect
|
106
99
|
text = {
|
107
|
-
"@data" =>
|
100
|
+
"@data" => data,
|
108
101
|
"@relations" => @relations
|
109
102
|
}.map {|k,v | k + '=' + v.inspect }.join(' ')
|
110
103
|
|
data/lib/restify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -176,9 +176,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- - "
|
179
|
+
- - ">"
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
181
|
+
version: 1.3.1
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
184
|
rubygems_version: 2.5.1
|