require 'net/http' require 'uri' require 'json' require 'yaml' require 'addressable/uri' module Onering module API module Errors class NotConnected < Exception; end class ClientError < Exception; end class ServerError < Exception; end end class Base DEFAULT_BASE="http://onering" DEFAULT_PATH="/api" DEFAULT_OPTIONS={} class<= 400 rv = JSON.load(response.body) 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 : JSON.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