Created
December 10, 2020 13:43
-
-
Save mwlang/d9dd5ebda76565699e633ca8ca261909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response # => #<HTTP::Client::Response:0x10fcb6b40 | |
@body=nil, | |
@body_io= | |
#<HTTP::FixedLengthContent:0x10fcb23f0 | |
@closed=false, | |
@continue_sent=false, | |
@decoder=nil, | |
@encoder=nil, | |
@encoding=IO::EncodingOptions(@invalid=:skip, @name="UTF-8"), | |
@expects_continue=false, | |
@io= | |
#<OpenSSL::SSL::Socket::Client:0x10fcd8f00 | |
@bio= | |
OpenSSL::BIO( | |
@bio=Pointer(LibCrypto::Bio)@0x7fba07704bf0, | |
@boxed_io=Pointer(Void)@0x10fcb1c00, | |
@io=#<TCPSocket:fd -1>), | |
@buffer_size=8192, | |
@closed=true, | |
@decoder=nil, | |
@encoder=nil, | |
@encoding=nil, | |
@flush_on_newline=false, | |
@in_buffer=Pointer(UInt8)@0x10fcdc000, | |
@in_buffer_rem= | |
Bytes[123, | |
34, | |
115, | |
101, | |
114, | |
118, | |
101, | |
114, | |
84, | |
105, | |
109, | |
101, | |
34, | |
58, | |
49, | |
54, | |
48, | |
55, | |
54, | |
48, | |
55, | |
49, | |
51, | |
49, | |
48, | |
48, | |
48, | |
125], | |
@out_buffer=Pointer(UInt8)@0x10fcd9000, | |
@out_count=0, | |
@read_buffering=true, | |
@ssl=Pointer(Void)@0x7fba0980a200, | |
@sync=false, | |
@sync_close=true>, | |
@read_remaining=28, | |
@sync_close=false>, | |
@cookies=nil, | |
@headers= | |
HTTP::Headers{"Access-Control-Allow-Methods" => "GET, HEAD, OPTIONS", | |
"Access-Control-Allow-Origin" => "*", | |
"Cache-Control" => "no-cache, no-store, must-revalidate", | |
"Connection" => "close", | |
"Content-Length" => "28", | |
"Content-Security-Policy" => "default-src 'self'", | |
"Content-Type" => "application/json;charset=UTF-8", | |
"Date" => "Thu, 10 Dec 2020 13:32:11 GMT", | |
"Expires" => "0", | |
"Pragma" => "no-cache", | |
"Server" => "nginx", | |
"Strict-Transport-Security" => "max-age=31536000; includeSubdomains", | |
"Via" => "1.1 ea6d44855948fa16c9e8fb87911af869.cloudfront.net (CloudFront)", | |
"X-Amz-Cf-Id" => "3o7ihnh6gRJBVCygCsIZwEIpodbe_YehS6Z53IvblXnoQXyaHXJdxw==", | |
"X-Amz-Cf-Pop" => "ATL56-C4", | |
"X-Cache" => "Miss from cloudfront", | |
"X-Content-Security-Policy" => "default-src 'self'", | |
"X-Content-Type-Options" => "nosniff", | |
"X-Frame-Options" => "SAMEORIGIN", | |
"X-WebKit-CSP" => "default-src 'self'", | |
"X-Xss-Protection" => "1; mode=block", | |
"x-mbx-used-weight" => "1", | |
"x-mbx-used-weight-1m" => "1", | |
"x-mbx-uuid" => "3985d2ac-acad-496d-962a-ccb1b9d968e0"}, | |
@status=OK, | |
@status_message="OK", | |
@version="HTTP/1.1"> | |
******************************************************************************** | |
(response.as(HTTP::Client::Response)).body # => "" | |
******************************************************************************** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def record_cassette(service, name : String) | |
WebMock.callbacks.add do | |
after_live_request do |request, response| | |
uri = "#{request.scheme}://#{request.headers["Host"]}#{request.resource.split("?")[0]}" | |
data = { | |
request: { | |
method: request.method, | |
uri: uri, | |
body: request.body.to_s, | |
query_params: request.query_params.to_s, | |
headers: request.headers, | |
timestamp: Time.utc.to_unix_ms, | |
}, | |
response: { | |
status: response.status_code, | |
body: response.body, | |
}, | |
} | |
pp! response | |
puts "*" * 80 | |
pp! response.as(HTTP::Client::Response).body | |
puts "*" * 80 | |
File.open(cassette_filepath(service, name), "w") { |f| YAML.dump(data, f) } | |
end | |
end | |
WebMock.allow_net_connect = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment