class Reggora::ApiClient

Public Class Methods

authenticate(username, password, type) click to toggle source
# File lib/reggora/Adapters/api_client.rb, line 8
def self.authenticate(username, password, type)
  body = {:username => username, :password => password}

  response = Net::HTTP.post URI("#{$base_api_uri}#{type}/auth"), body.to_json
  case response
  when Net::HTTPSuccess then
    JSON.parse(response.read_body)
  when Net::HTTPBadRequest then
    res = JSON.parse(response.read_body)
    raise res.inspect if res["error"].nil?
    print res
  when Net::HTTPUnauthorized then
    raise "Unauthorized."
  when Net::HTTPInternalServerError then
    raise "Internal server error"
  else
    raise "Unknown error #{response}: #{response.inspect}"
  end
end