restify 1.15.2 → 2.0.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 +25 -2
- data/README.md +23 -31
- data/lib/restify/adapter/base.rb +4 -0
- data/lib/restify/adapter/telemetry.rb +54 -0
- data/lib/restify/adapter/typhoeus.rb +21 -3
- data/lib/restify/context.rb +3 -3
- data/lib/restify/error.rb +2 -2
- data/lib/restify/link.rb +4 -4
- data/lib/restify/processors/base/parsing.rb +2 -21
- data/lib/restify/processors/base.rb +1 -1
- data/lib/restify/promise.rb +2 -2
- data/lib/restify/registry.rb +1 -1
- data/lib/restify/relation.rb +45 -17
- data/lib/restify/request.rb +6 -6
- data/lib/restify/timeout.rb +2 -2
- data/lib/restify/version.rb +3 -3
- data/lib/restify.rb +0 -1
- data/spec/restify/cache_spec.rb +16 -12
- data/spec/restify/context_spec.rb +8 -3
- data/spec/restify/error_spec.rb +13 -16
- data/spec/restify/features/head_requests_spec.rb +5 -4
- data/spec/restify/features/request_bodies_spec.rb +8 -8
- data/spec/restify/features/request_errors_spec.rb +2 -2
- data/spec/restify/features/request_headers_spec.rb +3 -6
- data/spec/restify/features/response_errors_spec.rb +1 -1
- data/spec/restify/global_spec.rb +10 -10
- data/spec/restify/processors/base_spec.rb +6 -7
- data/spec/restify/processors/json_spec.rb +21 -62
- data/spec/restify/processors/msgpack_spec.rb +33 -70
- data/spec/restify/promise_spec.rb +31 -31
- data/spec/restify/registry_spec.rb +5 -7
- data/spec/restify/relation_spec.rb +185 -7
- data/spec/restify/resource_spec.rb +47 -53
- data/spec/restify/timeout_spec.rb +3 -3
- data/spec/restify_spec.rb +12 -73
- data/spec/spec_helper.rb +11 -15
- metadata +33 -64
- data/lib/restify/adapter/em.rb +0 -134
- data/lib/restify/adapter/pooled_em.rb +0 -269
@@ -3,18 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Restify::Resource do
|
6
|
-
subject {
|
6
|
+
subject(:resource) { described_class.new(context, response:, data:, relations:) }
|
7
7
|
|
8
8
|
let(:data) { {} }
|
9
9
|
let(:relations) { {} }
|
10
|
-
let(:context) {
|
11
|
-
let(:response) {
|
12
|
-
let(:resource) { described_class.new(context, response: response, data: data, relations: relations) }
|
13
|
-
|
14
|
-
before do
|
15
|
-
allow(context).to receive(:relation?).and_return(false)
|
16
|
-
allow(context).to receive(:relation).and_raise(KeyError)
|
17
|
-
end
|
10
|
+
let(:context) { instance_double(Restify::Context) }
|
11
|
+
let(:response) { instance_double(Restify::Response) }
|
18
12
|
|
19
13
|
context 'relations' do
|
20
14
|
let(:relations) do
|
@@ -26,41 +20,41 @@ describe Restify::Resource do
|
|
26
20
|
|
27
21
|
describe '#relation?' do
|
28
22
|
it 'matches relations' do
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
43
|
-
|
44
|
-
expect(
|
45
|
-
expect(
|
23
|
+
expect(resource.relation?(:users)).to be true
|
24
|
+
expect(resource.relation?('users')).to be true
|
25
|
+
expect(resource.relation?(:projects)).to be true
|
26
|
+
expect(resource.relation?('projects')).to be true
|
27
|
+
expect(resource.relation?('fuu')).to be false
|
28
|
+
|
29
|
+
expect(resource).to have_relation :users
|
30
|
+
expect(resource).to have_relation :projects
|
31
|
+
|
32
|
+
expect(resource.rel?(:users)).to be true
|
33
|
+
expect(resource.rel?('users')).to be true
|
34
|
+
expect(resource.rel?(:projects)).to be true
|
35
|
+
expect(resource.rel?('projects')).to be true
|
36
|
+
expect(resource.rel?('fuu')).to be false
|
37
|
+
|
38
|
+
expect(resource).to have_rel :users
|
39
|
+
expect(resource).to have_rel :projects
|
46
40
|
end
|
47
41
|
end
|
48
42
|
|
49
43
|
describe '#relation' do
|
50
44
|
it 'returns relation' do
|
51
|
-
expect(
|
52
|
-
|
53
|
-
expect(
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect {
|
58
|
-
|
59
|
-
expect(
|
60
|
-
expect(
|
61
|
-
expect(
|
62
|
-
expect(
|
63
|
-
expect {
|
45
|
+
expect(resource.rel(:users)).to be_a Restify::Relation
|
46
|
+
|
47
|
+
expect(resource.rel(:users)).to eq 'http://example.org/users'
|
48
|
+
expect(resource.rel('users')).to eq 'http://example.org/users'
|
49
|
+
expect(resource.rel(:projects)).to eq 'http://example.org/projects'
|
50
|
+
expect(resource.rel('projects')).to eq 'http://example.org/projects'
|
51
|
+
expect { resource.rel(:fuu) }.to raise_error KeyError
|
52
|
+
|
53
|
+
expect(resource.relation(:users)).to eq 'http://example.org/users'
|
54
|
+
expect(resource.relation('users')).to eq 'http://example.org/users'
|
55
|
+
expect(resource.relation(:projects)).to eq 'http://example.org/projects'
|
56
|
+
expect(resource.relation('projects')).to eq 'http://example.org/projects'
|
57
|
+
expect { resource.relation(:fuu) }.to raise_error KeyError
|
64
58
|
end
|
65
59
|
end
|
66
60
|
|
@@ -68,15 +62,15 @@ describe Restify::Resource do
|
|
68
62
|
let(:relations) { {_restify_follow: 'http://localhost/10'} }
|
69
63
|
|
70
64
|
it 'returns follow relation' do
|
71
|
-
expect(
|
72
|
-
expect(
|
65
|
+
expect(resource.follow).to be_a Restify::Relation
|
66
|
+
expect(resource.follow).to eq 'http://localhost/10'
|
73
67
|
end
|
74
68
|
|
75
69
|
context 'when nil' do
|
76
70
|
let(:relations) { {} }
|
77
71
|
|
78
72
|
it 'returns nil' do
|
79
|
-
expect(
|
73
|
+
expect(resource.follow).to be_nil
|
80
74
|
end
|
81
75
|
end
|
82
76
|
end
|
@@ -85,15 +79,15 @@ describe Restify::Resource do
|
|
85
79
|
let(:relations) { {_restify_follow: 'http://localhost/10'} }
|
86
80
|
|
87
81
|
it 'returns follow relation' do
|
88
|
-
expect(
|
89
|
-
expect(
|
82
|
+
expect(resource.follow!).to be_a Restify::Relation
|
83
|
+
expect(resource.follow!).to eq 'http://localhost/10'
|
90
84
|
end
|
91
85
|
|
92
86
|
context 'when nil' do
|
93
87
|
let(:relations) { {} }
|
94
88
|
|
95
89
|
it 'raise runtime error' do
|
96
|
-
expect {
|
90
|
+
expect { resource.follow! }.to raise_error RuntimeError do |err|
|
97
91
|
expect(err.message).to eq 'Nothing to follow'
|
98
92
|
end
|
99
93
|
end
|
@@ -102,25 +96,25 @@ describe Restify::Resource do
|
|
102
96
|
end
|
103
97
|
|
104
98
|
context 'data' do
|
105
|
-
let(:data) { double 'data' }
|
99
|
+
let(:data) { double 'data' } # rubocop:disable RSpec/VerifiedDoubles
|
106
100
|
|
107
101
|
it 'delegates methods (I)' do
|
108
|
-
|
102
|
+
allow(data).to receive(:some_method).and_return(42)
|
109
103
|
|
110
|
-
expect(
|
111
|
-
expect(
|
104
|
+
expect(resource).to respond_to :some_method
|
105
|
+
expect(resource.some_method).to eq 42
|
112
106
|
end
|
113
107
|
|
114
108
|
it 'delegates methods (II)' do
|
115
|
-
|
109
|
+
allow(data).to receive(:[]).with(1).and_return(2)
|
116
110
|
|
117
|
-
expect(
|
118
|
-
expect(
|
111
|
+
expect(resource).to respond_to :[]
|
112
|
+
expect(resource[1]).to eq 2
|
119
113
|
end
|
120
114
|
|
121
115
|
describe '#data' do
|
122
116
|
it 'returns data' do
|
123
|
-
expect(
|
117
|
+
expect(resource.data).to equal data
|
124
118
|
end
|
125
119
|
end
|
126
120
|
end
|
@@ -16,7 +16,7 @@ describe Restify::Timeout do
|
|
16
16
|
it 'calls given block' do
|
17
17
|
expect { timer.timeout! }.not_to raise_error
|
18
18
|
sleep timer.send(:wait_interval)
|
19
|
-
expect { timer.timeout! }.to raise_error
|
19
|
+
expect { timer.timeout! }.to raise_error Restify::Timeout::Error
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -25,13 +25,13 @@ describe Restify::Timeout do
|
|
25
25
|
it 'calls block on IVar timeout' do
|
26
26
|
expect do
|
27
27
|
timer.wait_on!(Concurrent::IVar.new)
|
28
|
-
end.to raise_error
|
28
|
+
end.to raise_error Restify::Timeout::Error
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'calls block on Promise timeout' do
|
32
32
|
expect do
|
33
33
|
timer.wait_on!(Restify::Promise.new)
|
34
|
-
end.to raise_error
|
34
|
+
end.to raise_error Restify::Timeout::Error
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'does nothing on successful IVar' do
|
data/spec/restify_spec.rb
CHANGED
@@ -132,21 +132,21 @@ describe Restify do
|
|
132
132
|
# Because we forgot to send a "name" the server complains
|
133
133
|
# with an error code that will lead to a raised error.
|
134
134
|
|
135
|
-
expect(e.status).to eq :
|
135
|
+
expect(e.status).to eq :unprocessable_content
|
136
136
|
expect(e.code).to eq 422
|
137
137
|
expect(e.errors).to eq 'name' => ["can't be blank"]
|
138
138
|
end
|
139
139
|
|
140
140
|
# Let's try again.
|
141
|
-
created_user = users_relation.post(name: 'John Smith').value!
|
141
|
+
created_user = users_relation.post({name: 'John Smith'}).value!
|
142
142
|
|
143
143
|
# The server returns a 201 Created response with the created
|
144
144
|
# resource.
|
145
145
|
expect(created_user.response.status).to eq :created
|
146
146
|
expect(created_user.response.code).to eq 201
|
147
147
|
|
148
|
-
expect(created_user).to have_key
|
149
|
-
expect(created_user
|
148
|
+
expect(created_user).to have_key 'name'
|
149
|
+
expect(created_user['name']).to eq 'John Smith'
|
150
150
|
|
151
151
|
# Let's follow the "Location" header.
|
152
152
|
followed_resource = created_user.follow.get.value!
|
@@ -154,8 +154,8 @@ describe Restify do
|
|
154
154
|
expect(followed_resource.response.status).to eq :ok
|
155
155
|
expect(followed_resource.response.code).to eq 200
|
156
156
|
|
157
|
-
expect(followed_resource).to have_key
|
158
|
-
expect(followed_resource
|
157
|
+
expect(followed_resource).to have_key 'name'
|
158
|
+
expect(followed_resource['name']).to eq 'John Smith'
|
159
159
|
|
160
160
|
# Now we will fetch a list of all users.
|
161
161
|
users = users_relation.get.value!
|
@@ -168,80 +168,19 @@ describe Restify do
|
|
168
168
|
|
169
169
|
# We have all our attributes and relations here as defined in the
|
170
170
|
# responses from the server.
|
171
|
-
expect(user).to have_key
|
172
|
-
expect(user[
|
171
|
+
expect(user).to have_key 'name'
|
172
|
+
expect(user['name']).to eq 'John Smith'
|
173
173
|
expect(user).to have_relation :self
|
174
174
|
expect(user).to have_relation :blurb
|
175
175
|
|
176
176
|
# Let's get the blurb.
|
177
177
|
blurb = user.rel(:blurb).get.value!
|
178
178
|
|
179
|
-
expect(blurb).to have_key
|
180
|
-
expect(blurb).to have_key
|
179
|
+
expect(blurb).to have_key 'title'
|
180
|
+
expect(blurb).to have_key 'image'
|
181
181
|
|
182
|
-
expect(blurb[
|
183
|
-
expect(blurb[
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'within EM-synchrony' do
|
188
|
-
it 'consumes the API' do
|
189
|
-
skip 'Seems to be impossible to detect EM scheduled fibers from within'
|
190
|
-
|
191
|
-
EM.synchrony do
|
192
|
-
root = Restify.new('http://localhost:9292/base').get.value!
|
193
|
-
|
194
|
-
users_relation = root.rel(:users)
|
195
|
-
|
196
|
-
expect(users_relation).to be_a Restify::Relation
|
197
|
-
|
198
|
-
create_user_promise = users_relation.post
|
199
|
-
expect(create_user_promise).to be_a Restify::Promise
|
200
|
-
|
201
|
-
expect { create_user_promise.value! }.to \
|
202
|
-
raise_error(Restify::ClientError) do |e|
|
203
|
-
expect(e.status).to eq :unprocessable_entity
|
204
|
-
expect(e.code).to eq 422
|
205
|
-
expect(e.errors).to eq 'name' => ["can't be blank"]
|
206
|
-
end
|
207
|
-
|
208
|
-
created_user = users_relation.post(name: 'John Smith').value!
|
209
|
-
|
210
|
-
expect(created_user.response.status).to eq :created
|
211
|
-
expect(created_user.response.code).to eq 201
|
212
|
-
|
213
|
-
expect(created_user).to have_key :name
|
214
|
-
expect(created_user.name).to eq 'John Smith'
|
215
|
-
|
216
|
-
followed_resource = created_user.follow.get.value!
|
217
|
-
|
218
|
-
expect(followed_resource.response.status).to eq :ok
|
219
|
-
expect(followed_resource.response.code).to eq 200
|
220
|
-
|
221
|
-
expect(followed_resource).to have_key :name
|
222
|
-
expect(followed_resource.name).to eq 'John Smith'
|
223
|
-
|
224
|
-
users = users_relation.get.value!
|
225
|
-
|
226
|
-
expect(users).to have(2).items
|
227
|
-
|
228
|
-
user = users.first
|
229
|
-
|
230
|
-
expect(user).to have_key :name
|
231
|
-
expect(user[:name]).to eq 'John Smith'
|
232
|
-
expect(user).to have_relation :self
|
233
|
-
expect(user).to have_relation :blurb
|
234
|
-
|
235
|
-
blurb = user.rel(:blurb).get.value!
|
236
|
-
|
237
|
-
expect(blurb).to have_key :title
|
238
|
-
expect(blurb).to have_key :image
|
239
|
-
|
240
|
-
expect(blurb[:title]).to eq 'Prof. Dr. John Smith'
|
241
|
-
expect(blurb[:image]).to eq 'http://example.org/avatar.png'
|
242
|
-
|
243
|
-
EventMachine.stop
|
244
|
-
end
|
182
|
+
expect(blurb['title']).to eq 'Prof. Dr. John Smith'
|
183
|
+
expect(blurb['image']).to eq 'http://example.org/avatar.png'
|
245
184
|
end
|
246
185
|
end
|
247
186
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,25 +4,21 @@ require 'rspec'
|
|
4
4
|
require 'rspec/collection_matchers'
|
5
5
|
|
6
6
|
require 'simplecov'
|
7
|
+
require 'simplecov-cobertura'
|
8
|
+
|
7
9
|
SimpleCov.start do
|
8
10
|
add_filter 'spec'
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
SimpleCov
|
14
|
-
|
13
|
+
SimpleCov.formatters = [
|
14
|
+
SimpleCov::Formatter::HTMLFormatter,
|
15
|
+
SimpleCov::Formatter::CoberturaFormatter,
|
16
|
+
]
|
15
17
|
|
16
18
|
require 'restify'
|
17
19
|
|
18
20
|
if ENV['ADAPTER']
|
19
21
|
case ENV['ADAPTER'].to_s.downcase
|
20
|
-
when 'em'
|
21
|
-
require 'restify/adapter/em'
|
22
|
-
Restify.adapter = Restify::Adapter::EM.new
|
23
|
-
when 'em-pooled'
|
24
|
-
require 'restify/adapter/pooled_em'
|
25
|
-
Restify.adapter = Restify::Adapter::PooledEM.new
|
26
22
|
when 'typhoeus'
|
27
23
|
require 'restify/adapter/typhoeus'
|
28
24
|
Restify.adapter = Restify::Adapter::Typhoeus.new
|
@@ -40,21 +36,21 @@ RSpec.configure do |config|
|
|
40
36
|
config.order = 'random'
|
41
37
|
|
42
38
|
config.before(:suite) do
|
43
|
-
|
39
|
+
Restify::Timeout.default_timeout = 1.0
|
44
40
|
end
|
45
41
|
|
46
42
|
config.before do |example|
|
47
43
|
next unless (adapter = example.metadata[:adapter])
|
48
|
-
next if Restify.adapter.
|
44
|
+
next if Restify.adapter.class.ancestors.map(&:to_s).include?(adapter)
|
49
45
|
|
50
46
|
skip 'Spec not enabled for current adapter'
|
51
47
|
end
|
52
48
|
|
53
49
|
config.before do
|
54
|
-
Ethon.logger =
|
50
|
+
Ethon.logger = Logging.logger[Ethon] if defined?(Ethon)
|
55
51
|
|
56
|
-
|
57
|
-
|
52
|
+
Logging.logger.root.level = :debug
|
53
|
+
Logging.logger.root.add_appenders Logging.appenders.stdout
|
58
54
|
end
|
59
55
|
|
60
56
|
config.warnings = true
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -52,26 +51,6 @@ dependencies:
|
|
52
51
|
- - "~>"
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '1.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: hashie
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.3'
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '5.0'
|
65
|
-
type: :runtime
|
66
|
-
prerelease: false
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
68
|
-
requirements:
|
69
|
-
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '3.3'
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '5.0'
|
75
54
|
- !ruby/object:Gem::Dependency
|
76
55
|
name: hitimes
|
77
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,51 +94,65 @@ dependencies:
|
|
115
94
|
- !ruby/object:Gem::Version
|
116
95
|
version: '1.2'
|
117
96
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
97
|
+
name: opentelemetry-api
|
119
98
|
requirement: !ruby/object:Gem::Requirement
|
120
99
|
requirements:
|
121
|
-
- - "
|
100
|
+
- - "~>"
|
122
101
|
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
102
|
+
version: '1.0'
|
124
103
|
type: :runtime
|
125
104
|
prerelease: false
|
126
105
|
version_requirements: !ruby/object:Gem::Requirement
|
127
106
|
requirements:
|
128
|
-
- - "
|
107
|
+
- - "~>"
|
129
108
|
- !ruby/object:Gem::Version
|
130
|
-
version: '0'
|
109
|
+
version: '1.0'
|
131
110
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
111
|
+
name: opentelemetry-common
|
133
112
|
requirement: !ruby/object:Gem::Requirement
|
134
113
|
requirements:
|
135
|
-
- - "
|
114
|
+
- - ">="
|
136
115
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
116
|
+
version: '0'
|
138
117
|
type: :runtime
|
139
118
|
prerelease: false
|
140
119
|
version_requirements: !ruby/object:Gem::Requirement
|
141
120
|
requirements:
|
142
|
-
- - "
|
121
|
+
- - ">="
|
143
122
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
123
|
+
version: '0'
|
145
124
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
125
|
+
name: rack
|
147
126
|
requirement: !ruby/object:Gem::Requirement
|
148
127
|
requirements:
|
149
128
|
- - ">="
|
150
129
|
- !ruby/object:Gem::Version
|
151
130
|
version: '0'
|
152
|
-
type: :
|
131
|
+
type: :runtime
|
153
132
|
prerelease: false
|
154
133
|
version_requirements: !ruby/object:Gem::Requirement
|
155
134
|
requirements:
|
156
135
|
- - ">="
|
157
136
|
- !ruby/object:Gem::Version
|
158
137
|
version: '0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: typhoeus
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.3'
|
145
|
+
type: :runtime
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1.3'
|
159
152
|
description: An experimental hypermedia REST client that uses parallel, keep-alive
|
160
153
|
and pipelined requests by default.
|
161
154
|
email:
|
162
|
-
-
|
155
|
+
- jgraichen@altimos.de
|
163
156
|
executables: []
|
164
157
|
extensions: []
|
165
158
|
extra_rdoc_files: []
|
@@ -169,8 +162,7 @@ files:
|
|
169
162
|
- README.md
|
170
163
|
- lib/restify.rb
|
171
164
|
- lib/restify/adapter/base.rb
|
172
|
-
- lib/restify/adapter/
|
173
|
-
- lib/restify/adapter/pooled_em.rb
|
165
|
+
- lib/restify/adapter/telemetry.rb
|
174
166
|
- lib/restify/adapter/typhoeus.rb
|
175
167
|
- lib/restify/cache.rb
|
176
168
|
- lib/restify/context.rb
|
@@ -216,7 +208,6 @@ licenses:
|
|
216
208
|
- LGPL-3.0+
|
217
209
|
metadata:
|
218
210
|
rubygems_mfa_required: 'true'
|
219
|
-
post_install_message:
|
220
211
|
rdoc_options: []
|
221
212
|
require_paths:
|
222
213
|
- lib
|
@@ -224,36 +215,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
215
|
requirements:
|
225
216
|
- - ">="
|
226
217
|
- !ruby/object:Gem::Version
|
227
|
-
version:
|
218
|
+
version: 3.1.0
|
228
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
220
|
requirements:
|
230
221
|
- - ">="
|
231
222
|
- !ruby/object:Gem::Version
|
232
223
|
version: '0'
|
233
224
|
requirements: []
|
234
|
-
rubygems_version: 3.
|
235
|
-
signing_key:
|
225
|
+
rubygems_version: 3.6.2
|
236
226
|
specification_version: 4
|
237
227
|
summary: An experimental hypermedia REST client.
|
238
|
-
test_files:
|
239
|
-
- spec/restify/cache_spec.rb
|
240
|
-
- spec/restify/context_spec.rb
|
241
|
-
- spec/restify/error_spec.rb
|
242
|
-
- spec/restify/features/head_requests_spec.rb
|
243
|
-
- spec/restify/features/request_bodies_spec.rb
|
244
|
-
- spec/restify/features/request_errors_spec.rb
|
245
|
-
- spec/restify/features/request_headers_spec.rb
|
246
|
-
- spec/restify/features/response_errors_spec.rb
|
247
|
-
- spec/restify/global_spec.rb
|
248
|
-
- spec/restify/link_spec.rb
|
249
|
-
- spec/restify/processors/base_spec.rb
|
250
|
-
- spec/restify/processors/json_spec.rb
|
251
|
-
- spec/restify/processors/msgpack_spec.rb
|
252
|
-
- spec/restify/promise_spec.rb
|
253
|
-
- spec/restify/registry_spec.rb
|
254
|
-
- spec/restify/relation_spec.rb
|
255
|
-
- spec/restify/resource_spec.rb
|
256
|
-
- spec/restify/timeout_spec.rb
|
257
|
-
- spec/restify_spec.rb
|
258
|
-
- spec/spec_helper.rb
|
259
|
-
- spec/support/stub_server.rb
|
228
|
+
test_files: []
|
data/lib/restify/adapter/em.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eventmachine'
|
4
|
-
require 'em-http-request'
|
5
|
-
|
6
|
-
module Restify
|
7
|
-
module Adapter
|
8
|
-
class EM < Base
|
9
|
-
class Connection
|
10
|
-
class << self
|
11
|
-
def open(uri)
|
12
|
-
connections[uri.origin] ||= new uri.origin
|
13
|
-
end
|
14
|
-
|
15
|
-
def connections
|
16
|
-
@connections ||= {}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :origin
|
21
|
-
|
22
|
-
def initialize(origin)
|
23
|
-
@origin = origin
|
24
|
-
@pipeline = true
|
25
|
-
end
|
26
|
-
|
27
|
-
def requests
|
28
|
-
@requests ||= []
|
29
|
-
end
|
30
|
-
|
31
|
-
# rubocop:disable Style/IdenticalConditionalBranches
|
32
|
-
def call(request, writer, retried: false)
|
33
|
-
if requests.empty?
|
34
|
-
requests << [request, writer, retried]
|
35
|
-
process_next
|
36
|
-
else
|
37
|
-
requests << [request, writer, retried]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
# rubocop:enable all
|
41
|
-
|
42
|
-
def connection
|
43
|
-
@connection ||= EventMachine::HttpRequest.new(origin)
|
44
|
-
end
|
45
|
-
|
46
|
-
def pipeline?
|
47
|
-
@pipeline
|
48
|
-
end
|
49
|
-
|
50
|
-
def process_next
|
51
|
-
return if requests.empty?
|
52
|
-
|
53
|
-
request, writer, retried = pipeline? ? requests.shift : requests.first
|
54
|
-
begin
|
55
|
-
req = connection.send request.method.downcase,
|
56
|
-
keepalive: true,
|
57
|
-
redirects: 3,
|
58
|
-
path: request.uri.normalized_path,
|
59
|
-
query: request.uri.normalized_query,
|
60
|
-
body: request.body,
|
61
|
-
head: request.headers
|
62
|
-
rescue Exception => e # rubocop:disable Lint/RescueException
|
63
|
-
writer.reject e
|
64
|
-
requests.shift unless pipeline?
|
65
|
-
return
|
66
|
-
end
|
67
|
-
|
68
|
-
req.callback do
|
69
|
-
requests.shift unless pipeline?
|
70
|
-
|
71
|
-
writer.fulfill Response.new(
|
72
|
-
request,
|
73
|
-
req.last_effective_url,
|
74
|
-
req.response_header.status,
|
75
|
-
req.response_header,
|
76
|
-
req.response,
|
77
|
-
)
|
78
|
-
|
79
|
-
if req.response_header['CONNECTION'] == 'close'
|
80
|
-
@connection = nil
|
81
|
-
@pipeline = false
|
82
|
-
end
|
83
|
-
|
84
|
-
process_next
|
85
|
-
end
|
86
|
-
|
87
|
-
req.errback do
|
88
|
-
requests.shift unless pipeline?
|
89
|
-
@connection = nil
|
90
|
-
|
91
|
-
if pipeline?
|
92
|
-
EventMachine.next_tick do
|
93
|
-
@pipeline = false
|
94
|
-
call request, writer
|
95
|
-
end
|
96
|
-
elsif !retried
|
97
|
-
EventMachine.next_tick { call request, writer }
|
98
|
-
else
|
99
|
-
begin
|
100
|
-
raise "(#{req.response_header.status}) #{req.error}"
|
101
|
-
rescue StandardError => e
|
102
|
-
writer.reject e
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def call_native(request, writer)
|
110
|
-
next_tick do
|
111
|
-
Connection.open(request.uri).call(request, writer)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def next_tick(&block)
|
118
|
-
ensure_running
|
119
|
-
EventMachine.next_tick(&block)
|
120
|
-
end
|
121
|
-
|
122
|
-
def ensure_running
|
123
|
-
return if EventMachine.reactor_running?
|
124
|
-
|
125
|
-
Thread.new do
|
126
|
-
EventMachine.run
|
127
|
-
rescue StandardError => e
|
128
|
-
puts "#{self.class} -> #{e}\n#{e.backtrace.join("\n")}"
|
129
|
-
raise e
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|