Class: Emasser::System

Inherits:
SubCommandBase show all
Defined in:
lib/emasser/get.rb

Overview

The Systems endpoints provide the ability to view system information.

Endpoint:

 /api/systems            - Get system information
/api/systems/{systemId} - Get system information for a specific system

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner

Methods included from OutputConverters

#change_to_datetime, #to_output_hash

Methods included from InputConverters

#to_input_hash

Methods included from OptionsParser

#optional_options, #required_options

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/emasser/get.rb', line 57

def self.exit_on_failure?
  true
end

Instance Method Details

#byIdObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/emasser/get.rb', line 115

def byId
  optional_options_keys = optional_options(@_initializer).keys
  optional_options = to_input_hash(optional_options_keys, options)
  # optional_options.merge!(Emasser::GET_SYSTEM_RETURN_TYPE)

  begin
    # Get system information matching provided parameters
    result = EmassClient::SystemsApi.new.get_system(options[:systemId], optional_options)
    puts to_output_hash(result).green
  rescue EmassClient::ApiError => e
    puts 'Exception when calling SystemsApi->get_systems'.red
    puts to_output_hash(e).split('\n').join('. ')
  end
end

#idObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/emasser/get.rb', line 69

def id
  if options[:system_name].nil? && options[:system_owner].nil?
    raise ArgumentError,
          'SYSTEM_NAME or SYSTEM_OWNER is required'
  end

  begin
    results = EmassClient::SystemsApi.new.get_systems.data
    # Convert the Ruby Object (results) to a Hash (hash) and save each hash to an Array (hash_array)
    hash_array = []
    results.each do |element|
      hash = {}
      # instance_variables returns an array of object’s instance variables
      # instance_variable_get returns the value of the instance variable, given the variable name
      element.instance_variables.each do |v|
        hash[v.to_s.delete('@')] = element.instance_variable_get(v)
      end
      hash_array.push(hash)
    end
    # Filter the hash array based on provided options
    results = filter_systems(hash_array, options[:system_name], options[:system_owner])
    # Output the filtered results
    results.each { |result| puts "#{result['system_id']} - #{result['owning_organization']} - #{result['name']}" }
  rescue EmassClient::ApiError => e
    puts 'Exception when calling SystemsApi->get_systems'
    puts to_output_hash(e)
  end
end