lib/cloudstack_client/client.rb in cloudstack_client-0.9.2 vs lib/cloudstack_client/client.rb in cloudstack_client-0.9.3

- old
+ new

@@ -12,17 +12,18 @@ @@async_poll_interval = 2.0 @@async_timeout = 400 # include all commands - Dir.glob(File.dirname(__FILE__) + "/commands/*.rb").each do |file| + Dir.glob(File.dirname(__FILE__) + "/commands/*.rb").each do |file| require file module_name = File.basename(file, '.rb').split('_').map{|f| f.capitalize}.join include Object.const_get("CloudstackClient").const_get(module_name) end attr_accessor :verbose + attr_accessor :debug def initialize(api_url, api_key, secret_key, opts = {}) @api_url = api_url @api_key = api_key @secret_key = secret_key @@ -54,11 +55,11 @@ url = "#{@api_url}?#{data}&signature=#{signature}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) - + if uri.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end @@ -68,22 +69,22 @@ puts "Error connecting to API:" puts "#{@api_url} is not reachable" exit 1 end - + if response.is_a? Net::HTTPOK - begin + begin json = JSON.parse(response.body) json = json[params['command'].downcase + 'response'] rescue JSON::ParserError puts "Error parsing response from server:" puts response.body exit 2 end else - begin + begin json = JSON.parse(response.body) puts "Error executing command..." puts json if @debug json = json[params['command'].downcase + 'response'] puts "#{json['errorcode']}: #{json['errortext']}" @@ -135,13 +136,13 @@ private def debug_output(output, seperator = '-' * 80) puts - puts seperator + puts seperator puts output puts seperator puts end end # class -end \ No newline at end of file +end