swd 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/swd/debugger.rb +3 -0
- data/lib/swd/debugger/request_filter.rb +20 -0
- data/spec/swd/debugger/request_filter_spec.rb +29 -0
- metadata +7 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/swd/debugger.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module SWD
|
2
|
+
module Debugger
|
3
|
+
class RequestFilter
|
4
|
+
# Callback called in HTTPClient (before sending a request)
|
5
|
+
# request:: HTTP::Message
|
6
|
+
def filter_request(request)
|
7
|
+
started = "======= [SWD] HTTP REQUEST STARTED ======="
|
8
|
+
SWD.logger.info [started, request.dump].join("\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Callback called in HTTPClient (after received a response)
|
12
|
+
# request:: HTTP::Message
|
13
|
+
# response:: HTTP::Message
|
14
|
+
def filter_response(request, response)
|
15
|
+
finished = "======= [SWD] HTTP REQUEST FINISHED ======="
|
16
|
+
SWD.logger.info ['-' * 50, response.dump, finished].join("\n")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SWD::Debugger::RequestFilter do
|
4
|
+
let(:resource_endpoint) { 'https://example.com/resources' }
|
5
|
+
let(:request) { HTTP::Message.new_request(:get, URI.parse(resource_endpoint)) }
|
6
|
+
let(:response) { HTTP::Message.new_response({:hello => 'world'}.to_json) }
|
7
|
+
let(:request_filter) { SWD::Debugger::RequestFilter.new }
|
8
|
+
|
9
|
+
describe '#filter_request' do
|
10
|
+
it 'should log request' do
|
11
|
+
SWD.logger.should_receive(:info).with(
|
12
|
+
"======= [SWD] HTTP REQUEST STARTED =======\n" +
|
13
|
+
request.dump
|
14
|
+
)
|
15
|
+
request_filter.filter_request(request)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#filter_response' do
|
20
|
+
it 'should log response' do
|
21
|
+
SWD.logger.should_receive(:info).with(
|
22
|
+
"--------------------------------------------------\n" +
|
23
|
+
response.dump +
|
24
|
+
"\n======= [SWD] HTTP REQUEST FINISHED ======="
|
25
|
+
)
|
26
|
+
request_filter.filter_response(request, response)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- nov matake
|
@@ -174,6 +174,8 @@ files:
|
|
174
174
|
- VERSION
|
175
175
|
- lib/swd.rb
|
176
176
|
- lib/swd/cache.rb
|
177
|
+
- lib/swd/debugger.rb
|
178
|
+
- lib/swd/debugger/request_filter.rb
|
177
179
|
- lib/swd/exception.rb
|
178
180
|
- lib/swd/resource.rb
|
179
181
|
- lib/swd/response.rb
|
@@ -183,6 +185,7 @@ files:
|
|
183
185
|
- spec/mock_json/redirect_expired.json
|
184
186
|
- spec/mock_json/success.json
|
185
187
|
- spec/spec_helper.rb
|
188
|
+
- spec/swd/debugger/request_filter_spec.rb
|
186
189
|
- spec/swd/exception_spec.rb
|
187
190
|
- spec/swd/resource_spec.rb
|
188
191
|
- spec/swd_spec.rb
|
@@ -227,6 +230,7 @@ test_files:
|
|
227
230
|
- spec/mock_json/redirect_expired.json
|
228
231
|
- spec/mock_json/success.json
|
229
232
|
- spec/spec_helper.rb
|
233
|
+
- spec/swd/debugger/request_filter_spec.rb
|
230
234
|
- spec/swd/exception_spec.rb
|
231
235
|
- spec/swd/resource_spec.rb
|
232
236
|
- spec/swd_spec.rb
|