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.



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

#actionObject



18
19
20
# File 'lib/global_collect/responses/base.rb', line 18

def action
  request['ACTION']
end

#errorsObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/global_collect/responses/base.rb', line 40

def malformed?
  !response_hash['XML']
end

#request_idObject



26
27
28
# File 'lib/global_collect/responses/base.rb', line 26

def request_id
  meta['REQUESTID']
end

#response_datetimeObject



22
23
24
# File 'lib/global_collect/responses/base.rb', line 22

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

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/global_collect/responses/base.rb', line 14

def success?
  RESPONSE_STATUS_SUCCESS[result]
end

#versionObject



30
31
32
# File 'lib/global_collect/responses/base.rb', line 30

def version
  meta['VERSION']
end