restify 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/restify/adapter/typhoeus.rb +15 -3
- data/lib/restify/context.rb +3 -2
- data/lib/restify/error.rb +19 -0
- data/lib/restify/relation.rb +12 -12
- data/lib/restify/request.rb +7 -0
- data/lib/restify/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82d3b62e23db7cb179cce7f4b8a31fe3d965f674
|
4
|
+
data.tar.gz: bee7bbacb6e8f25b326af0fba70f12a5609f7aa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1385660f21c2f4543a84227d49a821edaa57d515d78ba68102e5a75781d188c181fd3fec32e7444275dd951aabcfebd97174bafa654fc1b53a051bc16990559
|
7
|
+
data.tar.gz: 7dba379faf8e84c513ae6adc66a1f8b4ab4fe9f2f546958fe9a561ae14d335c2045d1a4559c23f5f9ea6c4753d9289f3cd21b170a5ad85232f84934068ca0272
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,9 @@ require 'typhoeus'
|
|
5
5
|
module Restify
|
6
6
|
module Adapter
|
7
7
|
class Typhoeus < Base
|
8
|
+
# rubocop:disable RedundantFreeze
|
9
|
+
LOG_PROGNAME = 'restify.adapter.typhoeus'.freeze
|
10
|
+
|
8
11
|
attr_reader :sync
|
9
12
|
|
10
13
|
DEFAULT_HEADERS = {
|
@@ -46,10 +49,19 @@ module Restify
|
|
46
49
|
request.uri,
|
47
50
|
method: request.method,
|
48
51
|
headers: DEFAULT_HEADERS.merge(request.headers),
|
49
|
-
body: request.body
|
52
|
+
body: request.body,
|
53
|
+
followlocation: true,
|
54
|
+
timeout: request.timeout,
|
55
|
+
connecttimeout: request.timeout
|
50
56
|
|
51
57
|
req.on_complete do |response|
|
52
|
-
|
58
|
+
if response.timed_out?
|
59
|
+
writer.reject Restify::Timeout.new request
|
60
|
+
elsif response.code == 0
|
61
|
+
writer.reject Restify::NetworkError.new response.return_message
|
62
|
+
else
|
63
|
+
writer.fulfill convert_back(response, request)
|
64
|
+
end
|
53
65
|
end
|
54
66
|
|
55
67
|
req
|
@@ -78,8 +90,8 @@ module Restify
|
|
78
90
|
@thread ||= Thread.new do
|
79
91
|
loop do
|
80
92
|
begin
|
81
|
-
Thread.stop unless queued?
|
82
93
|
@hydra.run
|
94
|
+
Thread.stop unless queued?
|
83
95
|
rescue StandardError => e
|
84
96
|
puts "#{self.class}: #{e.message}"
|
85
97
|
end
|
data/lib/restify/context.rb
CHANGED
@@ -48,12 +48,13 @@ module Restify
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# rubocop:disable Metrics/MethodLength
|
51
|
-
def request(method, uri, data
|
52
|
-
request = Request.new
|
51
|
+
def request(method, uri, data: nil, **kwargs)
|
52
|
+
request = Request.new(**kwargs,
|
53
53
|
method: method,
|
54
54
|
uri: join(uri),
|
55
55
|
data: data,
|
56
56
|
headers: headers
|
57
|
+
)
|
57
58
|
|
58
59
|
ret = cache.call(request) {|req| adapter.call(req) }
|
59
60
|
ret.then do |response|
|
data/lib/restify/error.rb
CHANGED
@@ -2,6 +2,25 @@
|
|
2
2
|
|
3
3
|
module Restify
|
4
4
|
#
|
5
|
+
|
6
|
+
# A {Timeout} is raised when a request or promise times out.
|
7
|
+
#
|
8
|
+
class Timeout < StandardError
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source)
|
12
|
+
super "Operation with #{source.class} has timed out"
|
13
|
+
|
14
|
+
@source = source
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# A {NetworkError} is raised on unusual network exceptions such as
|
19
|
+
# unresolvable hosts or disconnects.
|
20
|
+
#
|
21
|
+
class NetworkError < StandardError
|
22
|
+
end
|
23
|
+
|
5
24
|
# A {ResponseError} is returned on a non-successful
|
6
25
|
# response from server. Usually it will either be a
|
7
26
|
# {ClientError} or a {ServerError}.
|
data/lib/restify/relation.rb
CHANGED
@@ -20,28 +20,28 @@ module Restify
|
|
20
20
|
@template = Addressable::Template.new template
|
21
21
|
end
|
22
22
|
|
23
|
-
def request(method, data, params)
|
24
|
-
context.request method, expand(params), data
|
23
|
+
def request(method, data, params, opts = {})
|
24
|
+
context.request method, expand(params), **opts, data: data
|
25
25
|
end
|
26
26
|
|
27
|
-
def get(params = {})
|
28
|
-
request :get, nil, params
|
27
|
+
def get(params = {}, opts = {})
|
28
|
+
request :get, nil, params, opts
|
29
29
|
end
|
30
30
|
|
31
|
-
def delete(params = {})
|
32
|
-
request :delete, nil, params
|
31
|
+
def delete(params = {}, opts = {})
|
32
|
+
request :delete, nil, params, opts
|
33
33
|
end
|
34
34
|
|
35
|
-
def post(data = {}, params = {})
|
36
|
-
request :post, data, params
|
35
|
+
def post(data = {}, params = {}, opts = {})
|
36
|
+
request :post, data, params, opts
|
37
37
|
end
|
38
38
|
|
39
|
-
def put(data = {}, params = {})
|
40
|
-
request :put, data, params
|
39
|
+
def put(data = {}, params = {}, opts = {})
|
40
|
+
request :put, data, params, opts
|
41
41
|
end
|
42
42
|
|
43
|
-
def patch(data = {}, params = {})
|
44
|
-
request :patch, data, params
|
43
|
+
def patch(data = {}, params = {}, opts = {})
|
44
|
+
request :patch, data, params, opts
|
45
45
|
end
|
46
46
|
|
47
47
|
def ==(other)
|
data/lib/restify/request.rb
CHANGED
@@ -24,10 +24,17 @@ module Restify
|
|
24
24
|
#
|
25
25
|
attr_reader :headers
|
26
26
|
|
27
|
+
# Request timeout in seconds
|
28
|
+
#
|
29
|
+
# Defaults to 300 seconds.
|
30
|
+
#
|
31
|
+
attr_reader :timeout
|
32
|
+
|
27
33
|
def initialize(opts = {})
|
28
34
|
@method = opts.fetch(:method, :get).downcase
|
29
35
|
@uri = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' }
|
30
36
|
@data = opts.fetch(:data, nil)
|
37
|
+
@timeout = opts.fetch(:timeout, 300)
|
31
38
|
@headers = opts.fetch(:headers, {}).merge \
|
32
39
|
'Content-Type' => 'application/json'
|
33
40
|
end
|
data/lib/restify/version.rb
CHANGED