20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/heroku-client/http.rb', line 20
def request(method, uri, body = {})
= { "Accept" => "application/json"}
basic_auth = { password: apikey }
options = { basic_auth: basic_auth, headers: }
options[:body] = body unless body.empty?
url = "https://api.heroku.com/#{uri}"
resp = HTTParty.get url, options if method == :get
resp = HTTParty.post url, options if method == :post
resp = HTTParty.put url, options if method == :put
resp = HTTParty.delete url, options if method == :delete
unless resp.success?
error_message = json_util.parse_error(resp.body)
raise UnauthorizedError, error_message if resp.code == 401
raise PaymentRequiredError, error_message if resp.code == 402
raise ForbiddenError, error_message if resp.code == 403
raise NotFoundError, error_message if resp.code == 404
raise PreConditionFailedError, error_message if resp.code == 412
raise UnprocessableEntityError, error_message if resp.code == 422
raise LockedError, error_message if resp.code == 423
raise UnknownError
end
json_util.parse_response resp.body
end
|