Parent

Class/Module Index [+]

Quicksearch

WebMock::HttpLibAdapters::TyphoeusAdapter

Public Class Methods

add_after_request_callback() click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 30
def self.add_after_request_callback
  unless Typhoeus::Hydra.
    global_hooks[:after_request_before_on_complete].
      include?(AFTER_REQUEST_CALLBACK)
    Typhoeus::Hydra.
      global_hooks[:after_request_before_on_complete] << AFTER_REQUEST_CALLBACK
  end
end
build_request_signature(req) click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 44
def self.build_request_signature(req)
  uri = WebMock::Util::URI.heuristic_parse(req.url)
  uri.path = uri.normalized_path.gsub("[^:]//","/")
  if req.username
    uri.user = req.username
    uri.password = req.password
  end

  body = req.body

  if req.params && req.method == :post
    body = request_body_for_post_request_with_params(req)
  end

  request_signature = WebMock::RequestSignature.new(
    req.method,
    uri.to_s,
    :body => body,
    :headers => req.headers
  )
  request_signature
end
build_webmock_response(typhoeus_response) click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 74
def self.build_webmock_response(typhoeus_response)
  webmock_response = WebMock::Response.new
  webmock_response.status = [typhoeus_response.code, typhoeus_response.status_message]
  webmock_response.body = typhoeus_response.body
  webmock_response.headers = typhoeus_response.headers_hash
  webmock_response
end
disable!() click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 20
def self.disable!
  @disabled = true
  remove_after_request_callback
  ::Typhoeus::Hydra.allow_net_connect = true
end
disabled?() click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 26
def self.disabled?
  !!@disabled
end
enable!() click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 14
def self.enable!
  @disabled = false
  add_after_request_callback
  ::Typhoeus::Hydra.allow_net_connect = true
end
remove_after_request_callback() click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 39
def self.remove_after_request_callback
  Typhoeus::Hydra.global_hooks[:after_request_before_on_complete].
    delete_if {|v| v == AFTER_REQUEST_CALLBACK }
end
request_body_for_post_request_with_params(req) click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 67
def self.request_body_for_post_request_with_params(req)
  params = req.params
  form = Typhoeus::Form.new(params)
  form.process!
  form.to_s
end
request_hash(request_signature) click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 108
def self.request_hash(request_signature)
  hash = {}

  hash[:body]    = request_signature.body
  hash[:headers] = request_signature.headers

  hash
end
stub_typhoeus(request_signature, webmock_response, typhoeus) click to toggle source
# File lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb, line 82
def self.stub_typhoeus(request_signature, webmock_response, typhoeus)
  response = if webmock_response.should_timeout
    ::Typhoeus::Response.new(
      :code         => 0,
      :status_message => "",
      :body         => "",
      :headers_hash => {},
      :curl_return_code => 28
    )
  else
    ::Typhoeus::Response.new(
      :code         => webmock_response.status[0],
      :status_message => webmock_response.status[1],
      :body         => webmock_response.body,
      :headers_hash => webmock_response.headers
    )
  end


  typhoeus.stub(
    request_signature.method || :any,
    /.*/,
    :webmock_stub => true
  ).and_return(response)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.