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_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, #debug, #host, #read_timeout, #secret_key, #symbolize_keys, #verbose
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
#send_async_request, #send_request
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 |
# 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 && @api.command_supports_param?(command["name"], k) params[k] = v 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 |