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.
11 12 13 14 |
# File 'lib/global_collect/responses/base.rb', line 11 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.
10 11 12 |
# File 'lib/global_collect/responses/base.rb', line 10 def raw_response @raw_response end |
#response_hash ⇒ Object (readonly)
Returns the value of attribute response_hash.
10 11 12 |
# File 'lib/global_collect/responses/base.rb', line 10 def response_hash @response_hash end |
Instance Method Details
#action ⇒ Object
20 21 22 |
# File 'lib/global_collect/responses/base.rb', line 20 def action request['ACTION'] end |
#errors ⇒ Object
36 37 38 39 40 |
# File 'lib/global_collect/responses/base.rb', line 36 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
42 43 44 |
# File 'lib/global_collect/responses/base.rb', line 42 def malformed? !response_hash['XML'] end |
#request_id ⇒ Object
28 29 30 |
# File 'lib/global_collect/responses/base.rb', line 28 def request_id ['REQUESTID'] end |
#response_datetime ⇒ Object
24 25 26 |
# File 'lib/global_collect/responses/base.rb', line 24 def response_datetime Time.parse(['RESPONSEDATETIME']) if ['RESPONSEDATETIME'] end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/global_collect/responses/base.rb', line 16 def success? RESPONSE_STATUS_SUCCESS[result] end |
#version ⇒ Object
32 33 34 |
# File 'lib/global_collect/responses/base.rb', line 32 def version ['VERSION'] end |