Class: Babl::ModuleResponse
- Inherits:
-
Object
- Object
- Babl::ModuleResponse
- Defined in:
- lib/babl/module_response.rb
Instance Attribute Summary collapse
-
#exitcode ⇒ Object
readonly
Returns the value of attribute exitcode.
-
#payload_url ⇒ Object
readonly
Returns the value of attribute payload_url.
Instance Method Summary collapse
- #fetch_payload ⇒ Object
-
#initialize(response) ⇒ ModuleResponse
constructor
A new instance of ModuleResponse.
- #raise_exception_when_unsuccessful! ⇒ Object
- #stderr ⇒ Object
- #stdout(allow_fetch = true) ⇒ Object
Constructor Details
#initialize(response) ⇒ ModuleResponse
Returns a new instance of ModuleResponse.
5 6 7 8 9 10 11 12 13 |
# File 'lib/babl/module_response.rb', line 5 def initialize response @stdout_raw = response["Stdout"] @stderr_raw = response["Stderr"] @exitcode = response["Exitcode"].to_i if !response["PayloadUrl"].nil? and response["PayloadUrl"] != "" @payload_url = response["PayloadUrl"] end end |
Instance Attribute Details
#exitcode ⇒ Object (readonly)
Returns the value of attribute exitcode.
3 4 5 |
# File 'lib/babl/module_response.rb', line 3 def exitcode @exitcode end |
#payload_url ⇒ Object (readonly)
Returns the value of attribute payload_url.
3 4 5 |
# File 'lib/babl/module_response.rb', line 3 def payload_url @payload_url end |
Instance Method Details
#fetch_payload ⇒ Object
35 36 37 38 39 |
# File 'lib/babl/module_response.rb', line 35 def fetch_payload if payload_url Net::HTTP.get URI(payload_url) end end |
#raise_exception_when_unsuccessful! ⇒ Object
41 42 43 44 45 |
# File 'lib/babl/module_response.rb', line 41 def raise_exception_when_unsuccessful! if exitcode != 0 raise ModuleError.new(stdout: stdout(false), stderr: stderr, exitcode: exitcode, payload_url: payload_url) end end |
#stderr ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/babl/module_response.rb', line 27 def stderr @stderr ||= begin o = Base64.decode64(@stderr_raw) @stderr_raw = nil o end end |
#stdout(allow_fetch = true) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/babl/module_response.rb', line 15 def stdout allow_fetch = true @stdout ||= begin if payload_url fetch_payload if allow_fetch else o = Base64.decode64(@stdout_raw) @stdout_raw = nil o end end end |