def raw(verb, url, *args)
url = url.sub(/^\//, '')
result = instrumented(verb.to_s.upcase, url, *args) do
if url !~ /^https?:/ or url.start_with? api_endpoint
connection.public_send(verb, url, *args)
else
Faraday.public_send(verb, url, *args) { |r| r.headers.delete("Authorization") }
end
end
case result.status
when 0 then raise Travis::Client::SSLError, 'SSL error: could not verify peer'
when 200..299 then JSON.parse(result.body) rescue result.body
when 301, 303 then raw(:get, result.headers['Location'])
when 302, 307, 308 then raw(verb, result.headers['Location'])
when 401 then raise Travis::Client::NotLoggedIn, 'not logged in'
when 403 then raise Travis::Client::NotLoggedIn, 'invalid access token'
when 404 then raise Travis::Client::NotFound, result.body
when 422 then raise Travis::Client::ValidationFailed, result.body
when 400..499 then raise Travis::Client::Error, "%s: %p" % [result.status, result.body]
when 500..599 then raise Travis::Client::Error, "server error (%s: %p)" % [result.status, result.body]
else raise Travis::Client::Error, "unhandled status code #{result.status}"
end
end