Class: Arista::EAPI::Response
- Inherits:
-
Object
- Object
- Arista::EAPI::Response
- Defined in:
- lib/arista/eapi/response.rb
Constant Summary collapse
- ERROR_CODES =
{ 1000 => Arista::EAPI::Error::GeneralError, 1001 => Arista::EAPI::Error::InternalException, 1002 => Arista::EAPI::Error::InvalidCommand, 1003 => Arista::EAPI::Error::TextOnly, 1004 => Arista::EAPI::Error::IncomptibleCommand, 1005 => Arista::EAPI::Error::AmbiguousCommand }
- PARSERS =
[ Arista::EAPI::Parser::Show ]
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#response ⇒ Object
Returns the value of attribute response.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(commands, body) ⇒ Response
constructor
A new instance of Response.
- #process_result(cmd, result) ⇒ Object
Constructor Details
#initialize(commands, body) ⇒ Response
Returns a new instance of Response.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arista/eapi/response.rb', line 26 def initialize(commands, body) self.response = JSON.parse(body) self.results = [] if response['error'] code = response['error']['code'] raise code < 0 ? Exception.new(response['message']) : ERROR_CODES[code] end commands.each_with_index do |cmd, idx| results << process_result(cmd, response['result'][idx]) end results end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
24 25 26 |
# File 'lib/arista/eapi/response.rb', line 24 def code @code end |
#response ⇒ Object
Returns the value of attribute response.
24 25 26 |
# File 'lib/arista/eapi/response.rb', line 24 def response @response end |
#results ⇒ Object
Returns the value of attribute results.
24 25 26 |
# File 'lib/arista/eapi/response.rb', line 24 def results @results end |
Instance Method Details
#process_result(cmd, result) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/arista/eapi/response.rb', line 42 def process_result(cmd, result) case Arista::EAPI.format_for(cmd) when 'json' then convert_hash_keys(result) else Arista::EAPI::Parser.parse(cmd, result['output']) end end |