Class: GlobalCollect::Responses::Base
- Inherits:
-
Object
- Object
- GlobalCollect::Responses::Base
- Defined in:
- lib/global_collect/responses/base.rb
Overview
WDL §4 specifies the generalized response This base class is sufficient for many responses that don’t include anything more than the basic META, RESULT and/or ERROR nodes. It is also a useful fallback if you want basic hash access to the actual content of the response with just a few helper methods for traversal.
Defined Under Namespace
Classes: RequestError
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#response_hash ⇒ Object
readonly
Returns the value of attribute response_hash.
Instance Method Summary collapse
- #action ⇒ Object
- #errors ⇒ Object
-
#initialize(response_hash, raw_response) ⇒ Base
constructor
A new instance of Base.
- #malformed? ⇒ Boolean
- #request_id ⇒ Object
- #response_datetime ⇒ Object
- #success? ⇒ Boolean
- #version ⇒ Object
Constructor Details
#initialize(response_hash, raw_response) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/global_collect/responses/base.rb', line 9 def initialize(response_hash, raw_response) @response_hash = response_hash @raw_response = raw_response end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
8 9 10 |
# File 'lib/global_collect/responses/base.rb', line 8 def raw_response @raw_response end |
#response_hash ⇒ Object (readonly)
Returns the value of attribute response_hash.
8 9 10 |
# File 'lib/global_collect/responses/base.rb', line 8 def response_hash @response_hash end |
Instance Method Details
#action ⇒ Object
18 19 20 |
# File 'lib/global_collect/responses/base.rb', line 18 def action request['ACTION'] end |
#errors ⇒ Object
34 35 36 37 38 |
# File 'lib/global_collect/responses/base.rb', line 34 def errors return [] if success? errs = response['ERROR'].is_a?(Array) ? response['ERROR'] : [response['ERROR']] return errs.map{|err| RequestError.new(err['CODE'].to_i, err['MESSAGE']) } end |
#malformed? ⇒ Boolean
40 41 42 |
# File 'lib/global_collect/responses/base.rb', line 40 def malformed? !response_hash['XML'] end |
#request_id ⇒ Object
26 27 28 |
# File 'lib/global_collect/responses/base.rb', line 26 def request_id ['REQUESTID'] end |
#response_datetime ⇒ Object
22 23 24 |
# File 'lib/global_collect/responses/base.rb', line 22 def response_datetime Time.parse(['RESPONSEDATETIME']) if ['RESPONSEDATETIME'] end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/global_collect/responses/base.rb', line 14 def success? RESPONSE_STATUS_SUCCESS[result] end |
#version ⇒ Object
30 31 32 |
# File 'lib/global_collect/responses/base.rb', line 30 def version ['VERSION'] end |