class Qubell::APICall

Implements Qubell API HTTP call helpers

Public Class Methods

handle_error(code) click to toggle source

@param [String] response

# File lib/qubell/api_call.rb, line 35
def self.handle_error(code)
  case code
  when 400 then raise Qubell::ExecutionError
  when 401 then raise Qubell::AuthenticationError
  when 403 then raise Qubell::PermissionsDeniedError
  when 404 then raise Qubell::ResourceUnavaliable
  when 409 then raise Qubell::WorkflowError
  else raise Qubell::BaseError, code
  end
end
handle_response(response) click to toggle source

@param [String] data

# File lib/qubell/api_call.rb, line 22
def self.handle_response(response)
  if response.code == 200
    case response.headers[:content_type]
    when 'application/json' then JSON.parse(response, symbolize_names: true)
    when 'application/x-yaml' then YAML.load response
    else response.empty? ? nil : response
    end
  else
    handle_error(response.code)
  end
end