require 'net/https' require 'uri' require 'multi_json' require 'yaml' require 'addressable/uri' require 'deep_merge' module Onering module API module Errors class NotConnected < Exception; end class ClientError < Exception; end class ServerError < Exception; end class ConnectionTimeout < Exception; end end class Base include Onering::Util DEFAULT_BASE="https://onering" DEFAULT_PATH="/api" DEFAULT_OPTIONS_FILE=[ "./cli.yml", "~/.onering/cli.yml", "/etc/onering/cli.yml" ] DEFAULT_CLIENT_PEM=[ "./client.pem", "~/.onering/client.pem", "/etc/onering/client.pem" ] class<= 400 rv = (MultiJson.load(response.body) rescue {}) unless response.body.empty? if rv['errors'] msg = "#{rv['errors']['type']}: #{rv['errors']['message']}" end if response.code.to_i >= 500 raise Errors::ServerError.new("HTTP #{response.code}: #{msg}") else raise Errors::ClientError.new("HTTP #{response.code}: #{msg}") end else if response['Content-Type'] == 'application/json' rv = (response.body.empty? ? nil : MultiJson.load(response.body)) else rv = response.body end end rv end def make_filter(filter) filter = filter.collect{|k,v| "#{k}/#{v}" } if filter.is_a?(Hash) filter = filter.collect{|i| i.sub(':','/') }.join("/") if filter.is_a?(Array) filter end def echo(obj) if obj.is_a?(Array) obj.each do |i| puts i end end end end end end end