def request(params)
begin
params[:expects] = Array(params[:expects]) | [307]
params[:headers] ||= {}
params[:headers]['Content-Type'] = 'application/json'
params[:headers]['API-Version'] = @version
params[:headers]['Auth-Token'] = auth_token unless params[:path] == 'Session'
params[:path] = "#{@path}/#{params[:path]}" unless params[:path] =~ %r{^#{Regexp.escape(@path)}/}
response = @connection.request(params.merge!({:host => @host}))
if response.body.empty?
response.body = {}
elsif response.headers['Content-Type'] == 'application/json'
response.body = Fog::JSON.decode(response.body)
end
if response.body['status'] == 'failure'
raise Error, response.body['msgs'].first['INFO']
end
if response.status == 307 && params[:path] !~ %r{^/REST/Job/}
response = poll_job(response, params[:expects])
end
response
rescue Excon::Errors::HTTPStatusError => error
if @auth_token && error.message =~ /login: (Bad or expired credentials|inactivity logout)/
@auth_token = nil
retry
else
raise error
end
end
response
end