Class: CloudstackClient::Api

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

Constant Summary collapse

DEFAULT_API_VERSION =
"4.5"
API_PATH =
File.expand_path("../../../data/", __FILE__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  set_api_path(options)
  set_api_version_and_file(options)
  load_commands
end

Instance Attribute Details

#api_fileObject (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_pathObject (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_versionObject (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

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/cloudstack_client/api.rb', line 48

def all_required_params?(command, args)
  required_params(command).all? { |k| args.key? k }
end

#command_supported?(command) ⇒ Boolean

Returns:

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

Returns:

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



52
53
54
55
56
# File 'lib/cloudstack_client/api.rb', line 52

def missing_params_msg(command)
  "#{command} requires the following parameter" +
  "#{ 's' if required_params(command).size > 1 }: " +
  required_params(command).join(", ")
end

#params(command) ⇒ Object



44
45
46
# File 'lib/cloudstack_client/api.rb', line 44

def params(command)
  @commands[command]["params"]
end

#required_params(command) ⇒ Object



38
39
40
41
42
# File 'lib/cloudstack_client/api.rb', line 38

def required_params(command)
  self.params(command).map do |param|
    param["name"] if param["required"] == true
  end.compact
end