class CzechPostB2bClient::Services::ParcelsSyncSender
Combination of ParcelsAsyncSender
+ ParcelsSendProcessUpdater
for fast SYNC registering parcel at CPOST It accept only one parcel! It should be used for instant one parcel registration.
Attributes
parcels[R]
sending_data[R]
Public Class Methods
new(sending_data:, parcels:)
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 11 def initialize(sending_data:, parcels:) @sending_data = sending_data @parcels = parcels end
Public Instance Methods
steps()
click to toggle source
Calls superclass method
CzechPostB2bClient::Services::Communicator#steps
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 16 def steps super + %i[check_for_state_errors] end
Private Instance Methods
add_errors_for_failed_states(parcel_id, response_states)
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 78 def add_errors_for_failed_states(parcel_id, response_states) response_states.each do |response_state| response_code = response_state[:code] next if response_code == CzechPostB2bClient::ResponseCodes::Ok.code errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}") end end
api_caller_class()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 30 def api_caller_class CzechPostB2bClient::Services::ApiCaller end
build_result_from(response_hash)
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 54 def build_result_from(response_hash) OpenStruct.new(parcels_hash: response_hash[:parcel], pdf_content: response_hash[:parcel].values.first.dig(:printings, :pdf_content), state_text: response_hash.dig(:response, :state, :text), state_code: response_hash.dig(:response, :state, :code)) end
check_for_state_errors()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 61 def check_for_state_errors return if result.state_code == CzechPostB2bClient::ResponseCodes::Ok.code r_code = CzechPostB2bClient::ResponseCodes.new_by_code(result.state_code) errors.add(:response_state, r_code.to_s) collect_parcel_errors fail! unless r_code.info? end
collect_parcel_errors()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 72 def collect_parcel_errors result.parcels_hash.each_pair do |parcel_id, parcel_hash| add_errors_for_failed_states(parcel_id, parcel_hash[:states]) end end
common_data()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 38 def common_data data_from_config.merge(sending_data) end
data_from_config()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 42 def data_from_config { contract_id: configuration.contract_id, customer_id: configuration.customer_id, sending_post_office_code: configuration.sending_post_office_code } end
endpoint_path()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 50 def endpoint_path '/parcelServiceSync' end
request_builder_args()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 22 def request_builder_args { common_data: common_data, parcel: parcels.first } end
request_builder_class()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 26 def request_builder_class CzechPostB2bClient::RequestBuilders::ParcelServiceSyncBuilder end
response_parser_class()
click to toggle source
# File lib/czech_post_b2b_client/services/parcels_sync_sender.rb, line 34 def response_parser_class CzechPostB2bClient::ResponseParsers::ParcelServiceSyncParser end