Class: CloudstackClient::Client
- Inherits:
-
Connection
- Object
- Connection
- CloudstackClient::Client
- Includes:
- Utils
- Defined in:
- lib/cloudstack_client/client.rb
Constant Summary
Constants inherited from Connection
CloudstackClient::Connection::DEF_ASYNC_TIMEOUT, CloudstackClient::Connection::DEF_POLL_INTERVAL, CloudstackClient::Connection::DEF_REQUEST_RETRIES, CloudstackClient::Connection::DEF_REQ_TIMEOUT
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Connection
#api_key, #api_url, #async_poll_interval, #async_timeout, #ca_file, #debug, #host, #read_timeout, #request_retries, #secret_key, #symbolize_keys, #verbose, #verify_ssl
Instance Method Summary collapse
- #define_api_methods ⇒ Object
-
#initialize(api_url, api_key, secret_key, options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Utils
#camel_case_to_underscore, #print_debug_output, #underscore_to_camel_case
Methods inherited from Connection
Methods included from RequestHandling
Constructor Details
#initialize(api_url, api_key, secret_key, options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/cloudstack_client/client.rb', line 13 def initialize(api_url, api_key, secret_key, = {}) super(api_url, api_key, secret_key, ) define_api_methods unless [:no_api_methods] end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
11 12 13 |
# File 'lib/cloudstack_client/client.rb', line 11 def api @api end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/cloudstack_client/client.rb', line 10 def @options end |
Instance Method Details
#define_api_methods ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cloudstack_client/client.rb', line 18 def define_api_methods @api = Api.new(@options) @api.commands.each do |name, command| method_name = camel_case_to_underscore(command["name"]).to_sym define_singleton_method(method_name) do |args = {}, = {}| params = { "command" => command["name"] } args.each do |k, v| k = k.to_s.gsub("_", "") if !v.nil? && @api.command_supports_param?(command["name"], k) params[k] = v elsif !v.nil? && .fetch(:strict_params, @options[:strict_params]) raise ParameterError, "#{command['name']} does not support parameter #{k}" end end unless @api.all_required_params?(command["name"], params) raise ParameterError, @api.missing_params_msg(command["name"]) end if command["isasync"] == false || [:sync] send_request(params, ) else send_async_request(params, ) end end end end |