4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/supergood/vendors/http.rb', line 4
def self.patch
if !self.existing_patch?
block = lambda do |x|
alias original_perform perform
def perform(original_request_payload, original_options)
request = {
headers: original_request_payload..to_hash,
method: original_request_payload.verb.upcase.to_s,
body: Supergood::Utils.safe_parse_json(original_request_payload.body.source),
url: original_request_payload.uri.to_s,
path: original_request_payload.uri.path,
search: original_request_payload.uri.query,
domain: Supergood::Utils.get_host_without_www(original_request_payload.uri.host)
}
Supergood.intercept(request) do
original_response = original_perform(original_request_payload, original_options)
status, statusText = original_response.status.to_s.split(' ')
{
headers: original_response..to_hash,
status: status,
statusText: statusText,
body: Supergood::Utils.safe_parse_json(original_response),
original_response: original_response
}
end
end
end
if defined?(HTTP::Client)
HTTP::Client.class_eval(&block)
end
end
end
|