Class: Artifice::Excon::Connection

Inherits:
Excon::Connection
  • Object
show all
Defined in:
lib/artifice/excon.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.endpointsObject



73
74
75
# File 'lib/artifice/excon.rb', line 73

def endpoints
  @endpoints ||= {}
end

Instance Method Details

#request_kernel(params) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/artifice/excon.rb', line 78

def request_kernel(params)
  endpoint = self.class.endpoints[params[:host]] ||
    self.class.endpoints[:default]
  return super unless endpoint

  rack_request = RackRequest.new(endpoint)

  params[:headers].each do |header, value|
    rack_request.header(header, value)
  end if params[:headers]

  request = "#{params[:scheme]}://#{params[:host]}:#{params[:port]}"
  request << params[:path]
  request << query_string(params[:query])

  response = rack_request.request(request,
    { :method => params[:method], :input => params[:body] })

  response = ::Excon::Response.new(:body => response.body,
    :headers => response.headers, :status => response.status)

  if params.has_key?(:expects) && ![*params[:expects]].include?(response.status)
    raise(::Excon::Errors.status_error(params, response))
  end

  response
end