Class: CloudstackClient::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudstack_client/api.rb

Constant Summary collapse

DEFAULT_API_VERSION =
"4.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  if options[:api_file]
    @api_file = options[:api_file]
    @api_version = File.basename(@api_file, ".msgpack")
  else
    @api_version = options[:api_version] || DEFAULT_API_VERSION
    @api_file = File.expand_path("../../../config/#{@api_version}.msgpack", __FILE__)
  end
  @commands = load_commands
end

Instance Attribute Details

#commandsObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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