Sha256: 5456affb487ab7d40aa44dd891c5eadd779ee0fdc9f9123fae53891b35173c37

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module CzechPostB2bClient
  module RequestBuilders
    class GetParcelStateBuilder < BaseBuilder
      attr_reader :parcel_codes

      def initialize(parcel_codes:, request_id: 1)
        @parcel_codes = parcel_codes
        @request_id = request_id
      end

      private

      def validate_data
        if parcel_codes.empty?
          errors.add(:parcel_codes, 'Minimum of 1 parcel code is required!')
          fail!
        end

        return if parcel_codes.size <= 10

        errors.add(:parcel_codes, 'Maximum of 10 parcel codes are allowed!')
        fail!
      end

      def service_data_struct
        new_element('serviceData').tap do |srv_data|
          add_element_to(srv_data, get_parcel_state)
        end
      end

      def get_parcel_state # rubocop:disable Naming/AccessorMethodName
        new_element('ns2:getParcelState').tap do |parcel_state|
          parcel_codes.each do |parcel_code|
            add_element_to(parcel_state, 'ns2:idParcel', value: parcel_code.to_s)
          end

          add_element_to(parcel_state, 'ns2:language', value: configuration.language.to_s)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
czech_post_b2b_client-1.2.7 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.6 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.5 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.4 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.3 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.2 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.2.1 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.1.0 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.0.3 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.0.2 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb
czech_post_b2b_client-1.0.0 lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb