Class: CloudstackClient::Api
- Inherits:
-
Object
- Object
- CloudstackClient::Api
- Defined in:
- lib/cloudstack_client/api.rb
Constant Summary collapse
- DEFAULT_API_VERSION =
"4.2"
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
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
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cloudstack_client/api.rb', line 10 def initialize( = {}) if [:api_file] @api_file = [:api_file] @api_version = File.basename(@api_file, ".msgpack") else @api_version = [:api_version] || DEFAULT_API_VERSION @api_file = File.("../../../config/#{@api_version}.msgpack", __FILE__) end @commands = load_commands end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
8 9 10 |
# File 'lib/cloudstack_client/api.rb', line 8 def commands @commands end |
Instance Method Details
#all_required_params?(command, args) ⇒ Boolean
35 36 37 |
# File 'lib/cloudstack_client/api.rb', line 35 def all_required_params?(command, args) required_params(command).all? { |k| args.key? k } end |
#command_supported?(command) ⇒ Boolean
21 22 23 |
# File 'lib/cloudstack_client/api.rb', line 21 def command_supported?(command) @commands.has_key? command end |
#command_supports_param?(command, key) ⇒ Boolean
25 26 27 |
# File 'lib/cloudstack_client/api.rb', line 25 def command_supports_param?(command, key) @commands[command]["params"].detect { |p| p["name"] == key } ? true : false end |
#missing_params_msg(command) ⇒ Object
39 40 41 42 |
# File 'lib/cloudstack_client/api.rb', line 39 def missing_params_msg(command) requ = required_params(command) "#{command} requires the following parameter#{ 's' if requ.size > 1}: #{requ.join(', ')}" end |
#required_params(command) ⇒ Object
29 30 31 32 33 |
# File 'lib/cloudstack_client/api.rb', line 29 def required_params(command) @commands[command]["params"].map do |param| param["name"] if param["required"] == true end.compact end |