Class: GlobalCollect::Responses::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_responseObject (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_hashObject (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

#actionObject



20
21
22
# File 'lib/global_collect/responses/base.rb', line 20

def action
  request['ACTION']
end

#errorsObject



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/global_collect/responses/base.rb', line 42

def malformed?
  !response_hash['XML']
end

#request_idObject



28
29
30
# File 'lib/global_collect/responses/base.rb', line 28

def request_id
  meta['REQUESTID']
end

#response_datetimeObject



24
25
26
# File 'lib/global_collect/responses/base.rb', line 24

def response_datetime
  Time.parse(meta['RESPONSEDATETIME']) if meta['RESPONSEDATETIME']
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/global_collect/responses/base.rb', line 16

def success?
  RESPONSE_STATUS_SUCCESS[result]
end

#versionObject



32
33
34
# File 'lib/global_collect/responses/base.rb', line 32

def version
  meta['VERSION']
end