Parent

Class/Module Index [+]

Quicksearch

WebMock::HttpLibAdapters::ExconAdapter

Public Class Methods

body_from(params) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 49
def self.body_from(params)
  body = params[:body]
  return body unless body.respond_to?(:read)

  contents = body.read
  body.rewind if body.respond_to?(:rewind)
  contents
end
build_request(params) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 41
def self.build_request(params)
  params = params.dup
  method  = (params.delete(:method) || :get).to_s.downcase.to_sym
  params[:query] = to_query(params[:query]) if params[:query].is_a?(Hash)
  uri = Addressable::URI.new(params).to_s
  WebMock::RequestSignature.new method, uri, :body => body_from(params), :headers => params[:headers]
end
disable!() click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 21
def self.disable!
  Excon.send(:remove_const, :Connection)
  Excon.send(:const_set, :Connection, ExconConnection.superclass)
end
enable!() click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 16
def self.enable!
  Excon.send(:remove_const, :Connection)
  Excon.send(:const_set, :Connection, ExconConnection)
end
mock_response(real) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 67
def self.mock_response(real)
  mock = WebMock::Response.new
  mock.status  = real.status
  mock.headers = real.headers
  mock.body    = real.body
  mock
end
perform_callbacks(request, response, options = {}) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 75
def self.perform_callbacks(request, response, options = {})
  return unless WebMock::CallbackRegistry.any_callbacks?
  WebMock::CallbackRegistry.invoke_callbacks(options.merge(:lib => :excon), request, response)
end
real_response(mock) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 58
def self.real_response(mock)
  raise Excon::Errors::Timeout if mock.should_timeout
  mock.raise_error_if_any
  Excon::Response.new              :body    => mock.body,
    :status  => mock.status[0].to_i,
    :headers => mock.headers
end
to_query(hash) click to toggle source
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 27
def self.to_query(hash)
  string = ""
  for key, values in hash
    if values.nil?
      string << key.to_s << '&'
    else
      for value in [*values]
        string << key.to_s << '=' << CGI.escape(value.to_s) << '&'
      end
    end
  end
  string.chop! # remove trailing '&'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.