Class: RlmLogistics::Response

Inherits:
ActiveRecord::Remote::Response
  • Object
show all
Defined in:
lib/rlm_logistics/response.rb

Instance Method Summary collapse

Instance Method Details

#dataObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rlm_logistics/response.rb', line 23

def data
  if record_instance.class.to_s.match(/inventory|item|packed/i)
    parsed_response["RESPONSE"]["DATA"]["RECSET"]["REC"]
  elsif record_instance.class.to_s.match(/credit/i)
    return nil if parsed_response["RESPONSE"]["DATA"]["RECSET"].nil?
    parsed_response["RESPONSE"]["DATA"]["RECSET"]["REC"]["REC_DETAILS"]["DETAIL"]
  elsif record_instance.class.to_s.match(/salesorder/i)
    parsed_response["RESPONSE"]["ORDER_NUMBER"]
  else
    parsed_response
  end
end

#handle_response(response) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rlm_logistics/response.rb', line 4

def handle_response(response)
  body_string      = remove_junk(response.body)
  hash             = Hash.from_xml(body_string)
  soap_body        = hash["Envelope"]["Body"]
  @parsed_response = soap_body["#{operation}Response"]["#{operation}Return"]
  if valid? && record_instance.respond_to?(:parse)
    record_instance.parse(self)
  else
    record_instance.errors.add(:base, response_message)
  end
  self
rescue REXML::ParseException => e
  # The api returned an invalid response, html 500 error
end

#response_messageObject



19
20
21
# File 'lib/rlm_logistics/response.rb', line 19

def response_message
  parsed_response["RESPONSE"]["DESCRIPTION"]
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/rlm_logistics/response.rb', line 36

def valid?
  case response_code
  when "0"
    false
  when "1"
    true
  end
end