module ThreeScale::Core::APIClient::Support::ClassMethods

Public Instance Methods

default_http_error_exception(exception = nil) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 31
def default_http_error_exception(exception = nil)
  return @default_http_error_exception ||= APIError unless exception
  @default_http_error_exception = exception
end
default_prefix(prefix = nil) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 36
def default_prefix(prefix = nil)
  return @default_prefix ||= self.to_s.split(':').last.downcase.to_sym unless prefix
  @default_prefix = prefix
end
default_uri(uri = nil) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 26
def default_uri(uri = nil)
  return @default_uri ||= "/internal/#{self.to_s.split(':').last.downcase!}s/" unless uri
  @default_uri = uri
end
parse_json(body) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 22
def parse_json(body)
  JSON.parse(body, symbolize_names: true)
end
status_ok?(method, uri, response) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 10
def status_ok?(method, uri, response)
  status = response.status
  # handle server errors here, since we will not be expecting JSON
  raise internal_api_error(status).new(method, uri, response) if status >= 500
  case method
    when :post then [200, 201]
    when :put then [200, 204, 202]
    when :delete then [200, 204, 202]
    else [200]
  end.include? status
end

Private Instance Methods

internal_api_error(status) click to toggle source
# File lib/3scale/core/api_client/support.rb, line 43
def internal_api_error(status)
  case status
    when 503 then APIServiceUnavailableError
    when 502 then APIBadGatewayError
    when 500 then APIInternalServerError
    else APIServerError
  end
end