rest-core 3.6.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +0 -1
- data/CHANGES.md +28 -0
- data/Gemfile +0 -2
- data/README.md +14 -95
- data/Rakefile +16 -3
- data/example/simple.rb +1 -0
- data/example/use-cases.rb +15 -3
- data/lib/rest-core.rb +38 -75
- data/lib/rest-core/client/universal.rb +3 -1
- data/lib/rest-core/client_oauth1.rb +64 -59
- data/lib/rest-core/event.rb +9 -11
- data/lib/rest-core/middleware/auth_basic.rb +21 -21
- data/lib/rest-core/middleware/bypass.rb +8 -8
- data/lib/rest-core/middleware/cache.rb +94 -90
- data/lib/rest-core/middleware/clash_response.rb +15 -14
- data/lib/rest-core/middleware/common_logger.rb +27 -26
- data/lib/rest-core/middleware/default_headers.rb +8 -8
- data/lib/rest-core/middleware/default_payload.rb +8 -8
- data/lib/rest-core/middleware/default_query.rb +8 -8
- data/lib/rest-core/middleware/default_site.rb +12 -12
- data/lib/rest-core/middleware/defaults.rb +38 -38
- data/lib/rest-core/middleware/error_detector.rb +10 -10
- data/lib/rest-core/middleware/error_detector_http.rb +6 -4
- data/lib/rest-core/middleware/error_handler.rb +14 -14
- data/lib/rest-core/middleware/follow_redirect.rb +28 -27
- data/lib/rest-core/middleware/json_request.rb +13 -11
- data/lib/rest-core/middleware/json_response.rb +29 -28
- data/lib/rest-core/middleware/oauth1_header.rb +84 -83
- data/lib/rest-core/middleware/oauth2_header.rb +27 -25
- data/lib/rest-core/middleware/oauth2_query.rb +15 -15
- data/lib/rest-core/middleware/query_response.rb +14 -14
- data/lib/rest-core/middleware/retry.rb +25 -23
- data/lib/rest-core/middleware/smash_response.rb +15 -14
- data/lib/rest-core/middleware/timeout.rb +18 -19
- data/lib/rest-core/test.rb +1 -18
- data/lib/rest-core/util/clash.rb +38 -37
- data/lib/rest-core/util/config.rb +40 -39
- data/lib/rest-core/util/dalli_extension.rb +11 -10
- data/lib/rest-core/util/hmac.rb +9 -8
- data/lib/rest-core/util/json.rb +55 -54
- data/lib/rest-core/util/parse_link.rb +13 -12
- data/lib/rest-core/util/parse_query.rb +24 -22
- data/lib/rest-core/version.rb +1 -1
- data/rest-core.gemspec +121 -158
- data/test/test_cache.rb +2 -0
- data/test/test_default_payload.rb +1 -1
- data/test/test_error_handler.rb +5 -4
- data/test/test_timeout.rb +9 -8
- data/test/test_universal.rb +8 -0
- metadata +9 -73
- data/lib/rest-core/builder.rb +0 -162
- data/lib/rest-core/client.rb +0 -277
- data/lib/rest-core/client/simple.rb +0 -2
- data/lib/rest-core/engine.rb +0 -36
- data/lib/rest-core/engine/dry.rb +0 -9
- data/lib/rest-core/engine/http-client.rb +0 -41
- data/lib/rest-core/error.rb +0 -5
- data/lib/rest-core/event_source.rb +0 -137
- data/lib/rest-core/middleware.rb +0 -151
- data/lib/rest-core/promise.rb +0 -249
- data/lib/rest-core/thread_pool.rb +0 -131
- data/lib/rest-core/timer.rb +0 -58
- data/lib/rest-core/util/payload.rb +0 -173
- data/test/test_builder.rb +0 -40
- data/test/test_client.rb +0 -177
- data/test/test_event_source.rb +0 -159
- data/test/test_future.rb +0 -16
- data/test/test_httpclient.rb +0 -118
- data/test/test_payload.rb +0 -204
- data/test/test_promise.rb +0 -146
- data/test/test_simple.rb +0 -38
- data/test/test_thread_pool.rb +0 -10
data/test/test_promise.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rest-core/test'
|
3
|
-
|
4
|
-
describe RC::Promise do
|
5
|
-
def new_promise
|
6
|
-
RC::Promise.new(RC::CLIENT => @client.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
before do
|
10
|
-
@client = RC::Builder.client
|
11
|
-
@promise = new_promise
|
12
|
-
end
|
13
|
-
|
14
|
-
after do
|
15
|
-
@client.shutdown
|
16
|
-
@client.thread_pool.size.should.eq 0
|
17
|
-
Muack.verify
|
18
|
-
end
|
19
|
-
|
20
|
-
would 'work, reject, yield' do
|
21
|
-
@client.pool_size = 1
|
22
|
-
flag = 0
|
23
|
-
@promise.defer do
|
24
|
-
flag.should.eq 0
|
25
|
-
flag += 1
|
26
|
-
@promise.reject(nil)
|
27
|
-
end
|
28
|
-
@promise.yield
|
29
|
-
flag.should.eq 1
|
30
|
-
@promise.send(:error).should.kind_of? RC::Error
|
31
|
-
end
|
32
|
-
|
33
|
-
would 'work, fulfill, yield' do
|
34
|
-
@client.pool_size = 2
|
35
|
-
flag = 0
|
36
|
-
@promise.defer do
|
37
|
-
flag.should.eq 0
|
38
|
-
flag += 1
|
39
|
-
@promise.fulfill('body', 1, {'K' => 'V'})
|
40
|
-
end
|
41
|
-
@promise.yield
|
42
|
-
flag.should.eq 1
|
43
|
-
@promise.send(:body) .should.eq 'body'
|
44
|
-
@promise.send(:status) .should.eq 1
|
45
|
-
@promise.send(:headers).should.eq('K' => 'V')
|
46
|
-
end
|
47
|
-
|
48
|
-
would 'work, wait, done' do
|
49
|
-
@client.pool_size = 3
|
50
|
-
flag = 0
|
51
|
-
promise = @client.defer(:itself) do
|
52
|
-
flag.should.eq 0
|
53
|
-
flag += 1
|
54
|
-
end
|
55
|
-
@client.wait
|
56
|
-
flag.should.eq 1
|
57
|
-
promise.should.done?
|
58
|
-
end if Object.respond_to?(:itself)
|
59
|
-
|
60
|
-
would 'work, check body' do
|
61
|
-
@client.pool_size = 3
|
62
|
-
flag = 0
|
63
|
-
result = @client.defer do
|
64
|
-
flag.should.eq 0
|
65
|
-
flag += 1
|
66
|
-
end
|
67
|
-
result.should.eq 1
|
68
|
-
flag.should.eq 1
|
69
|
-
end
|
70
|
-
|
71
|
-
would 'warn on callback error' do
|
72
|
-
mock(any_instance_of(RC::Promise)).warn(is_a(String)) do |msg|
|
73
|
-
msg.should.eq 'boom'
|
74
|
-
end
|
75
|
-
|
76
|
-
@client.new.get('http://localhost:1') do |err|
|
77
|
-
err.should.kind_of?(Errno::ECONNREFUSED)
|
78
|
-
raise 'boom'
|
79
|
-
end.wait
|
80
|
-
end
|
81
|
-
|
82
|
-
would 'call error_callback on errors' do
|
83
|
-
errors = []
|
84
|
-
@client.new(:error_callback => lambda{ |e| errors << e }).
|
85
|
-
get('http://localhost:1') do |err|
|
86
|
-
err.should.kind_of?(Errno::ECONNREFUSED)
|
87
|
-
raise 'boom'
|
88
|
-
end.wait
|
89
|
-
errors.map(&:class).should.eq [Errno::ECONNREFUSED, RuntimeError]
|
90
|
-
end
|
91
|
-
|
92
|
-
would 'then then then' do
|
93
|
-
plusone = lambda do |r|
|
94
|
-
r.merge(RC::RESPONSE_BODY => r[RC::RESPONSE_BODY] + 1)
|
95
|
-
end
|
96
|
-
2.times{ @promise.then(&plusone).then(&plusone).then(&plusone) }
|
97
|
-
@promise.fulfill(0, 200, {})
|
98
|
-
@promise.future_body.should.eq 6
|
99
|
-
end
|
100
|
-
|
101
|
-
would 'call inline if pool_size < 0' do
|
102
|
-
@client.pool_size = -1
|
103
|
-
current_thread = Thread.current
|
104
|
-
@promise.defer do
|
105
|
-
Thread.current.should.eq current_thread
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
would 'call in a new thread if pool_size == 0' do
|
110
|
-
@client.pool_size = 0
|
111
|
-
thread = nil
|
112
|
-
rd, wr = IO.pipe
|
113
|
-
mock(Thread).new.with_any_args.peek_return do |t|
|
114
|
-
thread = t
|
115
|
-
wr.puts
|
116
|
-
end
|
117
|
-
@promise.defer do
|
118
|
-
rd.gets
|
119
|
-
Thread.current.should.eq thread
|
120
|
-
@promise.reject(nil)
|
121
|
-
end
|
122
|
-
@promise.yield
|
123
|
-
end
|
124
|
-
|
125
|
-
would 'call in thread pool if pool_size > 0' do
|
126
|
-
@client.pool_size = 1
|
127
|
-
flag = 0
|
128
|
-
rd, wr = IO.pipe
|
129
|
-
@promise.defer do
|
130
|
-
rd.gets
|
131
|
-
flag.should.eq 0
|
132
|
-
flag += 1
|
133
|
-
@promise.reject(nil)
|
134
|
-
end
|
135
|
-
p1 = new_promise
|
136
|
-
p1.defer do # block until promise #0 is done because pool_size == 1
|
137
|
-
flag.should.eq 1
|
138
|
-
flag += 1
|
139
|
-
p1.reject(nil)
|
140
|
-
end
|
141
|
-
wr.puts # start promise #0
|
142
|
-
@promise.yield
|
143
|
-
p1.yield # block until promise #1 is done
|
144
|
-
flag.should.eq 2
|
145
|
-
end
|
146
|
-
end
|
data/test/test_simple.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rest-core/test'
|
3
|
-
|
4
|
-
describe RC::Simple do
|
5
|
-
path = 'http://example.com/'
|
6
|
-
|
7
|
-
after do
|
8
|
-
WebMock.reset!
|
9
|
-
end
|
10
|
-
|
11
|
-
would 'give RESPONSE_BODY' do
|
12
|
-
stub_request(:get, path).to_return(:body => 'OK')
|
13
|
-
RC::Simple.new.get(path).should.eq 'OK'
|
14
|
-
end
|
15
|
-
|
16
|
-
would 'give RESPONSE_HEADERS' do
|
17
|
-
stub_request(:head, path).to_return(:headers => {'A' => 'B'})
|
18
|
-
RC::Simple.new.head(path).should.eq 'A' => 'B'
|
19
|
-
end
|
20
|
-
|
21
|
-
would 'give RESPONSE_HEADERS' do
|
22
|
-
stub_request(:get, path).to_return(:status => 199)
|
23
|
-
RC::Simple.new.get(path, {},
|
24
|
-
RC::RESPONSE_KEY => RC::RESPONSE_STATUS).should.eq 199
|
25
|
-
end
|
26
|
-
|
27
|
-
would 'give RESPONSE_SOCKET' do
|
28
|
-
stub_request(:get, path).to_return(:body => 'OK')
|
29
|
-
RC::Simple.new.get(path, {}, RC::HIJACK => true).read.should.eq 'OK'
|
30
|
-
end
|
31
|
-
|
32
|
-
would 'give REQUEST_URI' do
|
33
|
-
stub_request(:get, "#{path}?a=b").to_return(:body => 'OK')
|
34
|
-
RC::Simple.new.get(path, {:a => 'b'},
|
35
|
-
RC::RESPONSE_KEY => RC::REQUEST_URI).should.eq "#{path}?a=b"
|
36
|
-
RC::Simple.wait
|
37
|
-
end
|
38
|
-
end
|
data/test/test_thread_pool.rb
DELETED