Class: CloudstackClient::Api
- Inherits:
-
Object
- Object
- CloudstackClient::Api
- Includes:
- Utils
- Defined in:
- lib/cloudstack_client/api.rb
Constant Summary collapse
- DEFAULT_API_VERSION =
"4.5"- API_PATH =
File.("../../../data/", __FILE__)
Instance Attribute Summary collapse
-
#api_file ⇒ Object
readonly
Returns the value of attribute api_file.
-
#api_path ⇒ Object
readonly
Returns the value of attribute api_path.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Class Method Summary collapse
Instance Method Summary collapse
- #all_required_params?(command, args) ⇒ Boolean
- #command_supported?(command) ⇒ Boolean
- #command_supports_param?(command, key) ⇒ Boolean
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
- #missing_params_msg(command) ⇒ Object
- #required_params(command) ⇒ Object
Methods included from Utils
#camel_case_to_underscore, #print_debug_output, #underscore_to_camel_case
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
21 22 23 24 25 |
# File 'lib/cloudstack_client/api.rb', line 21 def initialize( = {}) set_api_path() set_api_version_and_file() load_commands end |
Instance Attribute Details
#api_file ⇒ Object (readonly)
Returns the value of attribute api_file.
13 14 15 |
# File 'lib/cloudstack_client/api.rb', line 13 def api_file @api_file end |
#api_path ⇒ Object (readonly)
Returns the value of attribute api_path.
13 14 15 |
# File 'lib/cloudstack_client/api.rb', line 13 def api_path @api_path end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
13 14 15 |
# File 'lib/cloudstack_client/api.rb', line 13 def api_version @api_version end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
12 13 14 |
# File 'lib/cloudstack_client/api.rb', line 12 def commands @commands end |
Class Method Details
.versions(api_path = API_PATH) ⇒ Object
15 16 17 18 19 |
# File 'lib/cloudstack_client/api.rb', line 15 def self.versions(api_path = API_PATH) Dir[api_path + "/*.json.gz"].map do |path| File.basename(path, ".json.gz") end end |
Instance Method Details
#all_required_params?(command, args) ⇒ Boolean
44 45 46 |
# File 'lib/cloudstack_client/api.rb', line 44 def all_required_params?(command, args) required_params(command).all? { |k| args.key? k } end |
#command_supported?(command) ⇒ Boolean
27 28 29 |
# File 'lib/cloudstack_client/api.rb', line 27 def command_supported?(command) @commands.has_key? underscore_to_camel_case(command) end |
#command_supports_param?(command, key) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/cloudstack_client/api.rb', line 31 def command_supports_param?(command, key) command = underscore_to_camel_case(command) @commands[command]["params"].detect do |params| params["name"] == key.to_s end ? true : false end |
#missing_params_msg(command) ⇒ Object
48 49 50 51 52 |
# File 'lib/cloudstack_client/api.rb', line 48 def missing_params_msg(command) "#{command} requires the following parameter" + "#{ 's' if required_params(command).size > 1 }: " + required_params(command).join(", ") end |
#required_params(command) ⇒ Object
38 39 40 41 42 |
# File 'lib/cloudstack_client/api.rb', line 38 def required_params(command) @commands[command]["params"].map do |param| param["name"] if param["required"] == true end.compact end |