class VCR::LibraryHooks::Typhoeus::RequestHandler
@private
@private
Attributes
request[R]
Public Class Methods
new(request)
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 17 def initialize(request) @request = request request.block_connection = false if VCR.turned_on? end
Public Instance Methods
vcr_request()
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 22 def vcr_request @vcr_request ||= VCR::Request.new \ request.options.fetch(:method, :get), request.url, request_body, request.options.fetch(:headers, {}) end
Private Instance Methods
externally_stubbed?()
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 32 def externally_stubbed? ::Typhoeus::Expectation.find_by(request) end
on_stubbed_by_vcr_request()
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 46 def on_stubbed_by_vcr_request response = ::Typhoeus::Response.new \ :http_version => stubbed_response.http_version, :code => stubbed_response.status.code, :status_message => stubbed_response.status.message, :headers => stubbed_response_headers, :body => stubbed_response.body, :effective_url => stubbed_response.adapter_metadata.fetch('effective_url', request.url), :mock => true first_header_line = "HTTP/#{stubbed_response.http_version} #{response.code} #{response.status_message}\r\n" response.instance_variable_set(:@first_header_line, first_header_line) response.instance_variable_get(:@options)[:response_headers] = first_header_line + response.headers.map { |k,v| "#{k}: #{v}"}.join("\r\n") response end
on_unhandled_request()
click to toggle source
Calls superclass method
VCR::RequestHandler#on_unhandled_request
# File lib/vcr/library_hooks/typhoeus.rb, line 41 def on_unhandled_request invoke_after_request_hook(nil) super end
request_body()
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 73 def request_body request.encoded_body end
set_typed_request_for_after_hook(*args)
click to toggle source
Calls superclass method
VCR::RequestHandler#set_typed_request_for_after_hook
# File lib/vcr/library_hooks/typhoeus.rb, line 36 def set_typed_request_for_after_hook(*args) super request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request) end
stubbed_response_headers()
click to toggle source
# File lib/vcr/library_hooks/typhoeus.rb, line 64 def stubbed_response_headers @stubbed_response_headers ||= {}.tap do |hash| stubbed_response.headers.each do |key, values| hash[key] = values.size == 1 ? values.first : values end if stubbed_response.headers end end