lib/cloudstack_client/client.rb in cloudstack_client-0.6.1 vs lib/cloudstack_client/client.rb in cloudstack_client-0.6.2

- old
+ new

@@ -11,34 +11,28 @@ class Connection @@async_poll_interval = 2.0 @@async_timeout = 400 + # include all commands + 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 def initialize(api_url, api_key, secret_key, opts = {}) @api_url = api_url @api_key = api_key @secret_key = secret_key @verbose = opts[:quiet] ? false : true @debug = opts[:debug] ? true : false - CloudstackClient::Connection.include_commands unless opts[:no_commands] end ## - # Loads all commands from the commands subdirectory and includes them - # - - def self.include_commands - 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 - end - - ## # Sends a synchronous request to the CloudStack API and returns the response as a Hash. # # The wrapper element of the response (e.g. mycommandresponse) is discarded and the # contents of that element are returned. @@ -74,9 +68,10 @@ puts "Error connecting to API:" puts "#{@api_url} is not reachable" exit 1 end + if response.is_a? Net::HTTPOK begin json = JSON.parse(response.body) json = json[params['command'].downcase + 'response'] rescue JSON::ParserError \ No newline at end of file