czech_post_b2b_client 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +3 -0
  4. data/lib/czech_post_b2b_client/b2b_errors.rb +4 -2
  5. data/lib/czech_post_b2b_client/configuration.rb +1 -1
  6. data/lib/czech_post_b2b_client/post_services.rb +3 -2
  7. data/lib/czech_post_b2b_client/printing_templates.rb +0 -4
  8. data/lib/czech_post_b2b_client/request_builders/base_builder.rb +1 -0
  9. data/lib/czech_post_b2b_client/request_builders/get_parcel_state_builder.rb +1 -0
  10. data/lib/czech_post_b2b_client/request_builders/get_parcels_printing_builder.rb +1 -0
  11. data/lib/czech_post_b2b_client/request_builders/get_result_parcels_builder.rb +1 -0
  12. data/lib/czech_post_b2b_client/request_builders/get_stats_builder.rb +1 -0
  13. data/lib/czech_post_b2b_client/request_builders/parcel_service_sync_builder.rb +5 -4
  14. data/lib/czech_post_b2b_client/request_builders/send_parcels_builder.rb +6 -7
  15. data/lib/czech_post_b2b_client/response_codes.rb +38 -2
  16. data/lib/czech_post_b2b_client/response_parsers/base_parser.rb +14 -13
  17. data/lib/czech_post_b2b_client/response_parsers/get_parcel_state_parser.rb +1 -1
  18. data/lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb +9 -9
  19. data/lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb +2 -2
  20. data/lib/czech_post_b2b_client/response_parsers/get_stats_parser.rb +5 -8
  21. data/lib/czech_post_b2b_client/response_parsers/parcel_service_sync_parser.rb +4 -4
  22. data/lib/czech_post_b2b_client/response_parsers/send_parcels_parser.rb +2 -2
  23. data/lib/czech_post_b2b_client/services/address_sheets_generator.rb +6 -3
  24. data/lib/czech_post_b2b_client/services/api_caller.rb +7 -4
  25. data/lib/czech_post_b2b_client/services/delivering_inspector.rb +1 -0
  26. data/lib/czech_post_b2b_client/services/orchestrator.rb +1 -1
  27. data/lib/czech_post_b2b_client/services/parcels_async_sender.rb +5 -2
  28. data/lib/czech_post_b2b_client/services/parcels_send_process_updater.rb +8 -3
  29. data/lib/czech_post_b2b_client/services/parcels_submission_closer.rb +1 -1
  30. data/lib/czech_post_b2b_client/services/parcels_sync_sender.rb +9 -4
  31. data/lib/czech_post_b2b_client/services/time_period_statisticator.rb +10 -4
  32. data/lib/czech_post_b2b_client/services/xsds_downloader.rb +3 -1
  33. data/lib/czech_post_b2b_client/version.rb +1 -1
  34. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dbbe20befb04e719073a9ebda4cf114d8e546eb90d92a7e08a49fcc270f65c1
4
- data.tar.gz: 1de84b51f03160843a22541311f0dd410412bb64ca0cd6e5ef7410ed4d5790d1
3
+ metadata.gz: c3f8150daa70de566a1a90f4287c3bb29f1547e9269409e573b6e7521a446df5
4
+ data.tar.gz: 23a3271bcf33470fc45e85d4e1db58ee9ea192a864fc0266c887acc9a2d6b56b
5
5
  SHA512:
6
- metadata.gz: a2af402dee3c7b80de93d86af58d9feccb459ebf05c4eb8f35e6d75195e580575eb458a51e5962d32d643414892f2b939a6483e7b04afd86ca12c7af1550ef33
7
- data.tar.gz: cba547aac3305bcee6b7ac7e6d34557c8542fcafbfe46d5a746075593ae47dd097378c7cebd0d22c69dcd9dc33c3563ca56805c54a2b31e37f32c5887d42b258
6
+ metadata.gz: bbd09471e42a1af7f0f4bb7e8c6c34309e083dd224ad392ae11a84ec15c1aebedc178782f944a51d5be678a455daa769171dc02e2bf4d8cf50d18d0f98c9c643
7
+ data.tar.gz: 84bdfde9c41917ffa85c0f191123aca5a6d8b6373907c4969d3bf38c65b8782e6d4466e912a3a0db48c258cf089ca8ca74ea7d5b27f421b5f0ff7ae5c6615b85
data/.rubocop.yml CHANGED
@@ -2,6 +2,7 @@ require:
2
2
  # rubocop-minitest
3
3
 
4
4
  AllCops:
5
+ NewCops: enable
5
6
  Include:
6
7
  - "**/Gemfile"
7
8
  - "**/Rakefile"
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  All changes to the gem are documented here.
4
4
 
5
+ ## [1.2.8] - 2022-03-22
6
+ - added new response codes
7
+
5
8
  ## [1.2.6] - 2020-10-27
6
9
 
7
10
  - fixed passing all errors from `parcelsServiceSync` response.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/AsciiComments, Layout/LineLength
3
+ # rubocop:disable Layout/LineLength
4
4
 
5
5
  # response <B2BFaultMessage>
6
6
  # Chybový kód | Detail chyby | Popis
@@ -36,10 +36,12 @@ module CzechPostB2bClient
36
36
  end
37
37
 
38
38
  def initialize(details = '')
39
+ super
39
40
  self.details = details
40
41
  end
41
42
 
42
43
  attr_accessor :details
44
+
43
45
  def code
44
46
  self.class.code
45
47
  end
@@ -108,4 +110,4 @@ module CzechPostB2bClient
108
110
  end
109
111
  end
110
112
 
111
- # rubocop:enable Style/AsciiComments, Layout/LineLength
113
+ # rubocop:enable Layout/LineLength
@@ -32,7 +32,7 @@ module CzechPostB2bClient
32
32
  }
33
33
 
34
34
  @language = :cs
35
- @logger = defined?(Rails) ? ::Rails.logger : ::Logger.new(STDOUT)
35
+ @logger = defined?(Rails) ? ::Rails.logger : ::Logger.new($stdout)
36
36
  @b2b_api_base_uri = 'https://b2b.postaonline.cz/services/POLService/v1'
37
37
  @sending_post_office_location_number = 1
38
38
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Layout/LineLength, Style/AsciiComments
3
+ # rubocop:disable Layout/LineLength
4
4
 
5
5
  # Hopefully complete list of services which can be assigned to parcels
6
6
  # It is hard to get list of current services and even harder to find out what does they mean (so You pick right name in English).
@@ -84,6 +84,7 @@ module CzechPostB2bClient
84
84
  @description = 'Cenný obsah'
85
85
  # ; Balík Do ruky (DR, DV, DE) ; Balík Na poštu (NP, NV) |
86
86
  end
87
+
87
88
  class EconomyDelivery < Base
88
89
  @code = '1K'
89
90
  @abbreviation = 'EK'
@@ -774,4 +775,4 @@ module CzechPostB2bClient
774
775
  end
775
776
  end
776
777
 
777
- # rubocop:enable Layout/LineLength, Style/AsciiComments
778
+ # rubocop:enable Layout/LineLength
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/AsciiComments
4
-
5
3
  # Available printing templates, which can be used in AdressSheetsGenerator `options[:template_id]`
6
4
  #
7
5
  # Do not miss `CzechPostB2bClient::PrintingTemplates.all_classes` method,
@@ -261,5 +259,3 @@ module CzechPostB2bClient
261
259
  end
262
260
  end
263
261
  end
264
-
265
- # rubocop:enable Style/AsciiComments
@@ -10,6 +10,7 @@ module CzechPostB2bClient
10
10
  TIME_FORMAT = '%FT%T.%L%:z' # '2014-03-12T13:33:34.573+01:00'
11
11
 
12
12
  def initialize(request_id: 1)
13
+ super()
13
14
  @request_id = request_id
14
15
  end
15
16
 
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :parcel_codes
7
7
 
8
8
  def initialize(parcel_codes:, request_id: 1)
9
+ super()
9
10
  @parcel_codes = parcel_codes
10
11
  @request_id = request_id
11
12
  end
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :parcel_codes, :options
7
7
 
8
8
  def initialize(parcel_codes:, options:, request_id: 1)
9
+ super()
9
10
  @parcel_codes = parcel_codes
10
11
  @options = options
11
12
  @request_id = request_id
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :transaction_id
7
7
 
8
8
  def initialize(transaction_id:, request_id: 1)
9
+ super()
9
10
  @transaction_id = transaction_id
10
11
  @request_id = request_id
11
12
  end
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :from_date, :to_date
7
7
 
8
8
  def initialize(from_date:, to_date:, request_id: 1)
9
+ super()
9
10
  @from_date = from_date.to_time
10
11
  @to_date = to_date.to_time
11
12
  @request_id = request_id
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Layout/LineLength, Style/AsciiComments
3
+ # rubocop:disable Layout/LineLength
4
4
 
5
5
  module CzechPostB2bClient
6
6
  module RequestBuilders
@@ -8,6 +8,7 @@ module CzechPostB2bClient
8
8
  attr_reader :common_data, :parcel
9
9
 
10
10
  def initialize(common_data:, parcel:, request_id: 1)
11
+ super()
11
12
  @common_data = common_data
12
13
  @parcel = parcel
13
14
  @request_id = request_id
@@ -207,7 +208,7 @@ module CzechPostB2bClient
207
208
  add_element_to(do_parcel_address, 'ns2:custCardNum', value: addressee_data[:custom_card_number]) # Nepovinne: cislo zakaznicke karty
208
209
 
209
210
  (addressee_data[:advice_informations] || []).each_with_index do |adv_info, index|
210
- add_element_to(do_parcel_address, 'ns2:adviceInformation' + (index + 1).to_s, value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
211
+ add_element_to(do_parcel_address, "ns2:adviceInformation#{index + 1}", value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
211
212
  end
212
213
  add_element_to(do_parcel_address, 'ns2:adviceNote', value: addressee_data[:advice_note]) # Nepovinne: Poznamka k dodejce
213
214
  end
@@ -258,7 +259,7 @@ module CzechPostB2bClient
258
259
  def add_bank_elements(parent_element, bank_account)
259
260
  return if bank_account.to_s == ''
260
261
 
261
- if (m = bank_account.match(%r{(?:(\d+)-)?(\d+)\/(\d+)}))
262
+ if (m = bank_account.match(%r{(?:(\d+)-)?(\d+)/(\d+)}))
262
263
  prefix = m[1]
263
264
  account = m[2]
264
265
  bank = m[3]
@@ -284,4 +285,4 @@ module CzechPostB2bClient
284
285
  end
285
286
  end
286
287
 
287
- # rubocop:enable Layout/LineLength, Style/AsciiComments
288
+ # rubocop:enable Layout/LineLength
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Layout/LineLength, Style/AsciiComments
3
+ # rubocop:disable Layout/LineLength
4
4
 
5
5
  module CzechPostB2bClient
6
6
  module RequestBuilders
@@ -8,6 +8,7 @@ module CzechPostB2bClient
8
8
  attr_reader :common_data, :parcels
9
9
 
10
10
  def initialize(common_data:, parcels:, request_id: 1)
11
+ super()
11
12
  @common_data = common_data
12
13
  @parcels = parcels
13
14
  @request_id = request_id
@@ -225,7 +226,7 @@ module CzechPostB2bClient
225
226
  add_element_to(do_parcel_address, 'ns2:custCardNum', value: addressee_data[:custom_card_number]) # Nepovinne: cislo zakaznicke karty
226
227
 
227
228
  (addressee_data[:advice_informations] || []).each_with_index do |adv_info, index|
228
- add_element_to(do_parcel_address, 'ns2:adviceInformation' + (index + 1).to_s, value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
229
+ add_element_to(do_parcel_address, "ns2:adviceInformation#{index + 1}", value: adv_info) # Nepovinne: Informace 1- 6 k dodejce
229
230
  end
230
231
  add_element_to(do_parcel_address, 'ns2:adviceNote', value: addressee_data[:advice_note]) # Nepovinne: Poznamka k dodejce
231
232
  end
@@ -263,9 +264,7 @@ module CzechPostB2bClient
263
264
  return if address_data.nil?
264
265
 
265
266
  address_tags_and_values(address_data).each_pair do |xml_tag, value|
266
- unless without.include?(xml_tag)
267
- add_element_to(parent_element, xml_tag, value: value) unless value.nil?
268
- end
267
+ add_element_to(parent_element, xml_tag, value: value) if !without.include?(xml_tag) && !value.nil?
269
268
  end
270
269
  end
271
270
 
@@ -289,7 +288,7 @@ module CzechPostB2bClient
289
288
  def add_bank_elements(parent_element, bank_account)
290
289
  return if bank_account.to_s == ''
291
290
 
292
- if (m = bank_account.match(%r{(?:(\d+)-)?(\d+)\/(\d+)}))
291
+ if (m = bank_account.match(%r{(?:(\d+)-)?(\d+)/(\d+)}))
293
292
  prefix = m[1]
294
293
  account = m[2]
295
294
  bank = m[3]
@@ -315,4 +314,4 @@ module CzechPostB2bClient
315
314
  end
316
315
  end
317
316
 
318
- # rubocop:enable Layout/LineLength, Style/AsciiComments
317
+ # rubocop:enable Layout/LineLength
@@ -24,6 +24,7 @@ module CzechPostB2bClient
24
24
  end
25
25
 
26
26
  attr_reader :details
27
+
27
28
  def initialize(details = '')
28
29
  @details = details
29
30
  end
@@ -2001,10 +2002,45 @@ module CzechPostB2bClient
2001
2002
  @type = :info
2002
2003
  end
2003
2004
 
2004
- class InfoNonexistingZipCodeWasReplacedByConstant < CzechPostB2bClient::ResponseCodes::BaseCode
2005
+ class InfoService40CanceledDueMissingContactToAddressee < CzechPostB2bClient::ResponseCodes::BaseCode
2006
+ @code = 424
2007
+ @text = 'INFO_CANCEL_SERVICE_40'
2008
+ @description = 'Zrušena služba 40 - neuveden kontaktní údaj adresáta'
2009
+ @type = :info
2010
+ end
2011
+
2012
+ class InfoService29CanceledDueMissingContactToAddressee < CzechPostB2bClient::ResponseCodes::BaseCode
2013
+ @code = 425
2014
+ @text = 'INFO_CANCEL_SERVICE_29'
2015
+ @description = 'Zrušena dopl. sl. 29 – neuveden kontaktní údaj'
2016
+ @type = :info
2017
+ end
2018
+
2019
+ class InfoService40CanceledNotAllowedTogetherWithService29 < CzechPostB2bClient::ResponseCodes::BaseCode
2020
+ @code = 426
2021
+ @text = 'INFO_CANCEL_SERVICE_40'
2022
+ @description = 'Zrušena služba 40 – nepovolena se sl. 29'
2023
+ @type = :info
2024
+ end
2025
+
2026
+ class InfoService40CanceledPackageIsPosteRestante < CzechPostB2bClient::ResponseCodes::BaseCode
2027
+ @code = 427
2028
+ @text = 'INFO_CANCEL_SERVICE_40'
2029
+ @description = 'Zrušena služba 40 – zásilka Poste restante'
2030
+ @type = :info
2031
+ end
2032
+
2033
+ class InfoService7KCancelledNotArrangedForClient < CzechPostB2bClient::ResponseCodes::BaseCode
2034
+ @code = 428
2035
+ @text = 'INFO_CANCEL_SERVICE_7K'
2036
+ @description = 'Zrušena služba 7K - nesjednaná služba pro zákaznické řešení'
2037
+ @type = :info
2038
+ end
2039
+
2040
+ class InfoAvizoServiceAppended < CzechPostB2bClient::ResponseCodes::BaseCode
2005
2041
  @code = 429
2006
2042
  @text = 'INFO_NOTIFICIATON_WAS_MODIFIED'
2007
- @description = 'Zatím není text, dokumentace je zastaralá: INFO_NOTIFICIATON_WAS_MODIFIED'
2043
+ @description = 'Služba avizování přiřazena dle kontaktních údajů'
2008
2044
  @type = :info
2009
2045
  end
2010
2046
 
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  module ResponseParsers
7
7
  class BaseParser < SteppedService::Base
8
8
  def initialize(xml:)
9
+ super()
9
10
  @response_xml = xml
10
11
  end
11
12
 
@@ -34,41 +35,41 @@ module CzechPostB2bClient
34
35
 
35
36
  def build_result
36
37
  @result = {
37
- request: { created_at: request_data.time_stamp,
38
- contract_id: request_data.id_contract,
39
- request_id: request_data.id_ext_transaction },
38
+ request: { created_at: request_data[:time_stamp],
39
+ contract_id: request_data[:id_contract],
40
+ request_id: request_data[:id_ext_transaction] },
40
41
  response: { created_at: response_time }
41
42
  }
42
43
  end
43
44
 
44
45
  def response_service_data
45
- b2b_response_hash.dig('serviceData')
46
+ b2b_response_hash['serviceData']
46
47
  end
47
48
 
48
49
  def response_header
49
- b2b_response_hash.dig('header')
50
+ b2b_response_hash['header']
50
51
  end
51
52
 
52
53
  def response_root_node
53
- return response_service_data.dig(response_root_node_name) if response_service_data.keys.include?(response_root_node_name)
54
+ return response_service_data[response_root_node_name] if response_service_data.keys.include?(response_root_node_name)
54
55
 
55
56
  errors.add(:xml, "Cannot find `#{response_root_node_name}` in `serviceData` node.")
56
57
  fail_on_structure_parsing
57
58
  end
58
59
 
59
60
  def b2b_response_hash
60
- response_hash.dig('b2bSyncResponse') || response_hash.dig('b2bASyncResponse')
61
+ response_hash['b2bSyncResponse'] || response_hash['b2bASyncResponse']
61
62
  end
62
63
 
63
64
  def request_data
64
- b2b_request_hash = response_header.dig('b2bRequestHeader')
65
- OpenStruct.new(id_ext_transaction: b2b_request_hash.dig('idExtTransaction').to_s,
66
- time_stamp: Time.parse(b2b_request_hash.dig('timeStamp')),
67
- id_contract: b2b_request_hash.dig('idContract').to_s)
65
+ b2b_request_hash = response_header['b2bRequestHeader']
66
+ { id_ext_transaction: b2b_request_hash['idExtTransaction'].to_s,
67
+ time_stamp: Time.parse(b2b_request_hash['timeStamp']),
68
+ id_contract: b2b_request_hash['idContract'].to_s }
68
69
  end
69
70
 
70
71
  def response_time
71
- Time.parse(response_header.dig('timeStamp'))
72
+ Time.parse(response_header['timeStamp'])
72
73
  rescue TypeError
73
74
  Time.now.utc
74
75
  end
@@ -87,7 +88,7 @@ module CzechPostB2bClient
87
88
  end
88
89
 
89
90
  def handle_result_building_error(error)
90
- @result = { result_builder_error: error.message + ' at line: ' + error.backtrace.first,
91
+ @result = { result_builder_error: "#{error.message} at line: #{error.backtrace.first}",
91
92
  response_hash: response_hash }
92
93
  fail_on_structure_parsing
93
94
  end
@@ -21,7 +21,7 @@ module CzechPostB2bClient
21
21
  def response_parcel_hashes
22
22
  return [] if response_root_node.nil?
23
23
 
24
- [response_root_node.dig('parcel')].flatten.compact # to always get array of hash(es)
24
+ [response_root_node['parcel']].flatten.compact # to always get array of hash(es)
25
25
  end
26
26
 
27
27
  def parcel_data_from(rp_hash) # rubocop:disable Metrics/AbcSize
@@ -7,20 +7,20 @@ module CzechPostB2bClient
7
7
  class GetParcelsPrintingParser < BaseParser
8
8
  def build_result
9
9
  super
10
- @result[:response][:state] = state_hash_from(printing_response_header_result.dig('doPrintingStateResponse'))
10
+ @result[:response][:state] = state_hash_from(printing_response_header_result['doPrintingStateResponse'])
11
11
  @result[:printings] = { options: options_hash,
12
12
  pdf_content: pdf_content }
13
13
  end
14
14
 
15
15
  def options_hash
16
- options_response = printing_response_header_result.dig('doPrintingHeader')
16
+ options_response = printing_response_header_result['doPrintingHeader']
17
17
  {
18
- customer_id: options_response.dig('customerID'),
19
- contract_number: options_response.dig('contractNumber'),
20
- template_id: options_response.dig('idForm').to_i,
21
- margin_in_mm: { top: options_response.dig('shiftVertical').to_i,
22
- left: options_response.dig('shiftHorizontal').to_i },
23
- position_order: options_response.dig('position').to_i
18
+ customer_id: options_response['customerID'],
19
+ contract_number: options_response['contractNumber'],
20
+ template_id: options_response['idForm'].to_i,
21
+ margin_in_mm: { top: options_response['shiftVertical'].to_i,
22
+ left: options_response['shiftHorizontal'].to_i },
23
+ position_order: options_response['position'].to_i
24
24
  }
25
25
  end
26
26
 
@@ -36,7 +36,7 @@ module CzechPostB2bClient
36
36
  end
37
37
 
38
38
  def printing_response_header_result
39
- response_root_node.dig('doPrintingHeaderResult')
39
+ response_root_node['doPrintingHeaderResult']
40
40
  end
41
41
  end
42
42
  end
@@ -25,7 +25,7 @@ module CzechPostB2bClient
25
25
  end
26
26
 
27
27
  def response_parcel_hashes
28
- [response_root_node.dig('doParcelParamResult')].flatten.compact # to always get array of hash(es)
28
+ [response_root_node['doParcelParamResult']].flatten.compact # to always get array of hash(es)
29
29
  end
30
30
 
31
31
  def parcel_parcel_id_from(rp_hash)
@@ -34,7 +34,7 @@ module CzechPostB2bClient
34
34
 
35
35
  def parcel_data_from(rp_hash)
36
36
  { parcel_code: rp_hash['parcelCode'],
37
- states: [state_hash_from(rp_hash.dig('doParcelStateResponse'))] }
37
+ states: [state_hash_from(rp_hash['doParcelStateResponse'])] }
38
38
  end
39
39
 
40
40
  def updated_result_value_for(value, parcel_params_result_hash)
@@ -5,18 +5,15 @@ module CzechPostB2bClient
5
5
  class GetStatsParser < BaseParser
6
6
  def build_result
7
7
  super
8
- @result[:imports] = { requested: imports.all,
9
- with_errors: imports.err,
10
- successful: imports.ok,
11
- imported_parcels: imports.parcels }
8
+ @result[:imports] = imports
12
9
  end
13
10
 
14
11
  def imports
15
12
  imports_hash = response_root_node
16
- OpenStruct.new(all: imports_hash.dig('importAll').to_i,
17
- err: imports_hash.dig('importErr').to_i,
18
- ok: imports_hash.dig('importOk').to_i,
19
- parcels: imports_hash.dig('parcels').to_i)
13
+ { requested: imports_hash['importAll'].to_i,
14
+ with_errors: imports_hash['importErr'].to_i,
15
+ successful: imports_hash['importOk'].to_i,
16
+ imported_parcels: imports_hash['parcels'].to_i }
20
17
  end
21
18
 
22
19
  def response_root_node_name
@@ -35,7 +35,7 @@ module CzechPostB2bClient
35
35
  end
36
36
 
37
37
  def response_print_hash
38
- response_root_node.dig('responsePrintParams')
38
+ response_root_node['responsePrintParams']
39
39
  end
40
40
 
41
41
  def parcel_parcel_id_from(rp_hash)
@@ -44,7 +44,7 @@ module CzechPostB2bClient
44
44
 
45
45
  def parcel_data_from(rp_hash)
46
46
  { parcel_code: rp_hash['parcelCode'],
47
- states: parcel_states_form(rp_hash.dig('parcelDataResponse')) }
47
+ states: parcel_states_form(rp_hash['parcelDataResponse']) }
48
48
  end
49
49
 
50
50
  def parcel_states_form(data_responses)
@@ -54,8 +54,8 @@ module CzechPostB2bClient
54
54
  def print_data_from(print_hash)
55
55
  return nil if print_hash.nil? || print_hash.empty?
56
56
 
57
- { pdf_content: pdf_content_from(print_hash.dig('file')),
58
- state: state_hash_from(print_hash.dig('printParamsResponse')) }
57
+ { pdf_content: pdf_content_from(print_hash['file']),
58
+ state: state_hash_from(print_hash['printParamsResponse']) }
59
59
  end
60
60
 
61
61
  def pdf_content_from(pdf_content_encoded)
@@ -7,8 +7,8 @@ module CzechPostB2bClient
7
7
  super
8
8
 
9
9
  @result[:async_result] = {
10
- transaction_id: response_header.dig('idTransaction'),
11
- processing_end_expected_at: parse_time_with_correction(response_header.dig('timeStampProcessing'))
10
+ transaction_id: response_header['idTransaction'],
11
+ processing_end_expected_at: parse_time_with_correction(response_header['timeStampProcessing'])
12
12
  }
13
13
  end
14
14
 
@@ -5,7 +5,10 @@ module CzechPostB2bClient
5
5
  class AddressSheetsGenerator < CzechPostB2bClient::Services::Communicator
6
6
  attr_reader :parcel_codes, :options
7
7
 
8
+ AddressSheetsGeneratorResult = Struct.new(:pdf_content, :state_text, :state_code, keyword_init: true)
9
+
8
10
  def initialize(parcel_codes:, options: {})
11
+ super()
9
12
  @parcel_codes = parcel_codes
10
13
  @options = options
11
14
  end
@@ -37,9 +40,9 @@ module CzechPostB2bClient
37
40
  end
38
41
 
39
42
  def build_result_from(response_hash)
40
- OpenStruct.new(pdf_content: response_hash.dig(:printings, :pdf_content),
41
- state_text: response_hash.dig(:response, :state, :text),
42
- state_code: response_hash.dig(:response, :state, :code))
43
+ AddressSheetsGeneratorResult.new(pdf_content: response_hash.dig(:printings, :pdf_content),
44
+ state_text: response_hash.dig(:response, :state, :text),
45
+ state_code: response_hash.dig(:response, :state, :code))
43
46
  end
44
47
 
45
48
  def check_for_state_errors
@@ -18,7 +18,10 @@ module CzechPostB2bClient
18
18
  Net::ProtocolError
19
19
  ].freeze
20
20
 
21
+ ApiCallerResult = Struct.new(:code, :xml, keyword_init: true)
22
+
21
23
  def initialize(endpoint_path:, xml:)
24
+ super()
22
25
  @endpoint_path = endpoint_path
23
26
  @request_xml = xml
24
27
  end
@@ -40,7 +43,7 @@ module CzechPostB2bClient
40
43
  def handle_response
41
44
  CzechPostB2bClient.logger.debug("CzechPost B2B RESPONSE: #{response} with body:\n#{response.body}")
42
45
 
43
- @result = ::OpenStruct.new(code: response.code.to_i, xml: response.body)
46
+ @result = ApiCallerResult.new(code: response.code.to_i, xml: response.body)
44
47
  return unless b2b_error?
45
48
 
46
49
  errors.add(:b2b, b2b_error_text)
@@ -102,12 +105,12 @@ module CzechPostB2bClient
102
105
  end
103
106
 
104
107
  def b2b_error_text
105
- err_code_without_namespace_regexp = %r{<(?:\w+\:)?errorCode>(\d+)</(?:\w+\:)?errorCode>}
108
+ err_code_without_namespace_regexp = %r{<(?:\w+:)?errorCode>(\d+)</(?:\w+:)?errorCode>}
106
109
  error_match = result.xml.match(err_code_without_namespace_regexp)
107
110
  return 'error code not found in XML' unless error_match
108
111
 
109
112
  error_code = error_match[1].to_i
110
- error_details = result.xml.match(%r{<(?:\w+\:)?errorDescription>(.*)</(?:\w+\:)?errorDescription>})
113
+ error_details = result.xml.match(%r{<(?:\w+:)?errorDescription>(.*)</(?:\w+:)?errorDescription>})
111
114
  error = CzechPostB2bClient::B2BErrors.new_by_code(error_code, error_details[1])
112
115
  return "error code [#{error_code}] is unknown" unless error
113
116
 
@@ -115,7 +118,7 @@ module CzechPostB2bClient
115
118
  end
116
119
 
117
120
  def handle_connection_error(error)
118
- @result = OpenStruct.new(code: 500, xml: '')
121
+ @result = ApiCallerResult.new(code: 500, xml: '')
119
122
  errors.add(:connection, "#{error.class} > #{service_uri} - #{error}")
120
123
  fail!
121
124
  end
@@ -6,6 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :parcel_codes
7
7
 
8
8
  def initialize(parcel_codes:)
9
+ super()
9
10
  @parcel_codes = parcel_codes
10
11
  end
11
12
 
@@ -11,7 +11,7 @@ module CzechPostB2bClient
11
11
  service = service_class.call(service_hash.values.first)
12
12
 
13
13
  if service.failed?
14
- errors.add_from_hash(Hash[service_name, service.errors.full_messages])
14
+ errors.add_from_hash({ service_name => service.errors.full_messages })
15
15
  fail!
16
16
  end
17
17
 
@@ -5,7 +5,10 @@ module CzechPostB2bClient
5
5
  class ParcelsAsyncSender < CzechPostB2bClient::Services::Communicator
6
6
  attr_reader :sending_data, :parcels
7
7
 
8
+ ParcelsAsyncSenderResult = Struct.new(:transaction_id, :processing_end_expected_at, keyword_init: true)
9
+
8
10
  def initialize(sending_data:, parcels:)
11
+ super()
9
12
  @sending_data = sending_data
10
13
  @parcels = parcels
11
14
  end
@@ -45,8 +48,8 @@ module CzechPostB2bClient
45
48
  end
46
49
 
47
50
  def build_result_from(response_hash)
48
- OpenStruct.new(transaction_id: response_hash.dig(:async_result, :transaction_id),
49
- processing_end_expected_at: response_hash.dig(:async_result, :processing_end_expected_at))
51
+ ParcelsAsyncSenderResult.new(transaction_id: response_hash.dig(:async_result, :transaction_id),
52
+ processing_end_expected_at: response_hash.dig(:async_result, :processing_end_expected_at))
50
53
  end
51
54
  end
52
55
  end
@@ -5,7 +5,10 @@ module CzechPostB2bClient
5
5
  class ParcelsSendProcessUpdater < CzechPostB2bClient::Services::Communicator
6
6
  attr_reader :transaction_id
7
7
 
8
+ ParcelsSendProcessUpdaterResult = Struct.new(:parcels_hash, :state_text, :state_code, keyword_init: true)
9
+
8
10
  def initialize(transaction_id:)
11
+ super()
9
12
  @transaction_id = transaction_id
10
13
  end
11
14
 
@@ -36,9 +39,11 @@ module CzechPostB2bClient
36
39
  end
37
40
 
38
41
  def build_result_from(response_hash)
39
- OpenStruct.new(parcels_hash: response_hash[:parcels],
40
- state_text: response_hash.dig(:response, :state, :text),
41
- state_code: response_hash.dig(:response, :state, :code))
42
+ ParcelsSendProcessUpdaterResult.new(
43
+ parcels_hash: response_hash[:parcels],
44
+ state_text: response_hash.dig(:response, :state, :text),
45
+ state_code: response_hash.dig(:response, :state, :code)
46
+ )
42
47
  end
43
48
 
44
49
  def check_for_state_errors
@@ -6,7 +6,7 @@ module CzechPostB2bClient
6
6
  attr_reader :sending_data
7
7
 
8
8
  def initialize(sending_data:)
9
- @sending_data = sending_data
9
+ super(sending_data: sending_data, parcels: [])
10
10
  end
11
11
 
12
12
  private
@@ -8,7 +8,10 @@ module CzechPostB2bClient
8
8
  class ParcelsSyncSender < CzechPostB2bClient::Services::Communicator
9
9
  attr_reader :sending_data, :parcels
10
10
 
11
+ ParcelsSyncSenderResult = Struct.new(:parcels_hash, :state_text, :state_code, :pdf_content, keyword_init: true)
12
+
11
13
  def initialize(sending_data:, parcels:)
14
+ super()
12
15
  @sending_data = sending_data
13
16
  @parcels = parcels
14
17
  end
@@ -52,10 +55,12 @@ module CzechPostB2bClient
52
55
  end
53
56
 
54
57
  def build_result_from(response_hash)
55
- OpenStruct.new(parcels_hash: response_hash[:parcel],
56
- pdf_content: response_hash[:parcel].values.first.dig(:printings, :pdf_content),
57
- state_text: response_hash.dig(:response, :state, :text),
58
- state_code: response_hash.dig(:response, :state, :code))
58
+ ParcelsSyncSenderResult.new(
59
+ parcels_hash: response_hash[:parcel],
60
+ pdf_content: response_hash[:parcel].values.first.dig(:printings, :pdf_content),
61
+ state_text: response_hash.dig(:response, :state, :text),
62
+ state_code: response_hash.dig(:response, :state, :code)
63
+ )
59
64
  end
60
65
 
61
66
  def check_for_state_errors
@@ -5,7 +5,11 @@ module CzechPostB2bClient
5
5
  class TimePeriodStatisticator < CzechPostB2bClient::Services::Communicator
6
6
  attr_reader :from_date, :to_date
7
7
 
8
+ TimePeriodStatisticatorResult = Struct.new(:requests, :imported_parcels, keyword_init: true)
9
+ TimePeriodStatisticatorRequestsResult = Struct.new(:total, :with_errors, :successful, keyword_init: true)
10
+
8
11
  def initialize(from_date:, to_date:)
12
+ super()
9
13
  @from_date = from_date
10
14
  @to_date = to_date
11
15
  end
@@ -34,10 +38,12 @@ module CzechPostB2bClient
34
38
 
35
39
  def build_result_from(response_hash)
36
40
  imports = response_hash[:imports]
37
- OpenStruct.new(requests: OpenStruct.new(total: imports[:requested],
38
- with_errors: imports[:with_errors],
39
- successful: imports[:successful]),
40
- imported_parcels: imports[:imported_parcels])
41
+ TimePeriodStatisticatorResult.new(
42
+ requests: TimePeriodStatisticatorRequestsResult.new(total: imports[:requested],
43
+ with_errors: imports[:with_errors],
44
+ successful: imports[:successful]),
45
+ imported_parcels: imports[:imported_parcels]
46
+ )
41
47
  end
42
48
  end
43
49
  end
@@ -6,7 +6,9 @@ require 'net/http'
6
6
  module CzechPostB2bClient
7
7
  module Services
8
8
  class XsdsDownloader < ApiCaller
9
- def initialize(_anything); end
9
+ def initialize(_anything)
10
+ super()
11
+ end
10
12
 
11
13
  def steps
12
14
  %i[download_xsds]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CzechPostB2bClient
4
- VERSION = '1.2.7'
4
+ VERSION = '1.2.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: czech_post_b2b_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Mlčoch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-17 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.80'
103
+ version: 1.26.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.80'
110
+ version: 1.26.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-minitest
113
113
  requirement: !ruby/object:Gem::Requirement