Sha256: 5e1fe239383adeebdc1cccdb468a38c35989d034ff40ea51c063199114036f0a

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
czech_post_b2b_client-1.0.3 lib/czech_post_b2b_client/services/parcels_sender.rb
czech_post_b2b_client-1.0.2 lib/czech_post_b2b_client/services/parcels_sender.rb
czech_post_b2b_client-1.0.0 lib/czech_post_b2b_client/services/parcels_sender.rb