diff --git a/lib/czech_post_b2b_client/services.rb b/lib/czech_post_b2b_client/services.rb index c63efab..2025f35 100644 --- a/lib/czech_post_b2b_client/services.rb +++ b/lib/czech_post_b2b_client/services.rb @@ -3,8 +3,9 @@ require 'czech_post_b2b_client/services/orchestrator' require 'czech_post_b2b_client/services/communicator' require 'czech_post_b2b_client/services/api_caller' -require 'czech_post_b2b_client/services/parcels_sender' +require 'czech_post_b2b_client/services/parcels_async_sender' require 'czech_post_b2b_client/services/parcels_immediate_sender' +require 'czech_post_b2b_client/services/parcels_sender' # deprecated require 'czech_post_b2b_client/services/parcels_send_process_updater' require 'czech_post_b2b_client/services/address_sheets_generator' require 'czech_post_b2b_client/services/parcels_submission_closer' diff --git a/lib/czech_post_b2b_client/services/parcels_async_sender.rb b/lib/czech_post_b2b_client/services/parcels_async_sender.rb new file mode 100644 index 0000000..80309c9 --- /dev/null +++ b/lib/czech_post_b2b_client/services/parcels_async_sender.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module CzechPostB2bClient + module Services + class ParcelsAsyncSender < CzechPostB2bClient::Services::Communicator + attr_reader :sending_data, :parcels + + def initialize(sending_data:, parcels:) + @sending_data = sending_data + @parcels = parcels + end + + private + + def request_builder_args + { common_data: common_data, parcels: parcels } + end + + def request_builder_class + CzechPostB2bClient::RequestBuilders::SendParcelsBuilder + end + + def api_caller_class + CzechPostB2bClient::Services::ApiCaller + end + + def response_parser_class + CzechPostB2bClient::ResponseParsers::SendParcelsParser + end + + def common_data + data_from_config.merge(sending_data) + end + + def data_from_config + { + contract_id: configuration.contract_id, + customer_id: configuration.customer_id, + sending_post_office_code: configuration.sending_post_office_code + } + end + + def endpoint_path + '/sendParcels' + end + + def build_result_from(response_hash) + OpenStruct.new(transaction_id: response_hash.dig(:async_result, :transaction_id), + processing_end_expected_at: response_hash.dig(:async_result, :processing_end_expected_at)) + end + end + end +end diff --git a/lib/czech_post_b2b_client/services/parcels_sender.rb b/lib/czech_post_b2b_client/services/parcels_sender.rb index d05deed..7adb7c8 100644 --- a/lib/czech_post_b2b_client/services/parcels_sender.rb +++ b/lib/czech_post_b2b_client/services/parcels_sender.rb @@ -2,51 +2,10 @@ module CzechPostB2bClient module Services - class ParcelsSender < CzechPostB2bClient::Services::Communicator - attr_reader :sending_data, :parcels - - def initialize(sending_data:, parcels:) - @sending_data = sending_data - @parcels = parcels - end - - private - - def request_builder_args - { common_data: common_data, parcels: parcels } - end - - def request_builder_class - CzechPostB2bClient::RequestBuilders::SendParcelsBuilder - end - - def api_caller_class - CzechPostB2bClient::Services::ApiCaller - end - - def response_parser_class - CzechPostB2bClient::ResponseParsers::SendParcelsParser - end - - def common_data - data_from_config.merge(sending_data) - end - - def data_from_config - { - contract_id: configuration.contract_id, - customer_id: configuration.customer_id, - sending_post_office_code: configuration.sending_post_office_code - } - end - - def endpoint_path - '/sendParcels' - end - - def build_result_from(response_hash) - OpenStruct.new(transaction_id: response_hash.dig(:async_result, :transaction_id), - processing_end_expected_at: response_hash.dig(:async_result, :processing_end_expected_at)) + class ParcelsSender < CzechPostB2bClient::Services::ParcelsAsyncSender + class << self + extend Gem::Deprecate + deprecate :call, 'CzechPostB2bClient::Services::ParcelsAsyncSender.call', 2020, 8 end end end