Class: CzechPostB2bClient::ResponseParsers::SendParcelsParser

Inherits:
BaseParser show all
Defined in:
lib/czech_post_b2b_client/response_parsers/send_parcels_parser.rb

Instance Attribute Summary

Attributes inherited from SteppedService::Base

#result

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize, #steps

Methods inherited from SteppedService::Base

call, #call, #errors, #failure?, #finished?, #steps, #success?

Constructor Details

This class inherits a constructor from CzechPostB2bClient::ResponseParsers::BaseParser

Instance Method Details

#build_resultObject



6
7
8
9
10
11
12
13
# File 'lib/czech_post_b2b_client/response_parsers/send_parcels_parser.rb', line 6

def build_result
  super

  @result[:async_result] = {
    transaction_id: response_header.dig('idTransaction'),
    processing_end_expected_at: parse_time_with_correction(response_header.dig('timeStampProcessing'))
  }
end

#cpost_time_zoneObject

just for info



30
31
32
# File 'lib/czech_post_b2b_client/response_parsers/send_parcels_parser.rb', line 30

def cpost_time_zone
  timezone('Europe/Prague')
end

#parse_time_with_correction(b2b_time_str) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/czech_post_b2b_client/response_parsers/send_parcels_parser.rb', line 15

def parse_time_with_correction(b2b_time_str)
  # b2b time in XML is NOT CORRECT! They return CET time value with UTC timezone
  # Like `2016-02-25T09:30:03.678Z`, which is actually `2016-02-25T09:30:03.678+0100`  (CET)
  # Or   `2016-05-25T09:30:03.678Z`, which is actually `2016-05-25T09:30:03.678+0200` (CET + DST)
  # But we must be prepare for unnoticed fix by CPost

  # unfortunattely this can be done for only freshly generated XMLs (comparing b2b_time with Time.now.utc)
  # but we have to kepp it compatible for old XML
  # so we pass it up and leave comments in documenation
  # Users of this gem will have to care of it

  Time.parse(b2b_time_str)
end