czech_post_b2b_client 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ccd8a99118f5ef7d0ecea94ff0f54fabcf9b463
4
- data.tar.gz: 48b1cf59bc7507cdf999300da9c808cb84039aba
3
+ metadata.gz: d7c296befdf3e8a0575b0855f80ddc0bfd730db4
4
+ data.tar.gz: 2c9519c8d7e5a483c60cf356bafe5dd652149763
5
5
  SHA512:
6
- metadata.gz: c5be2e12fc57bf7409f75401c50327ca07bae5120de0976ec6b190fd437031351f494106339876e1505ea55d975eabb1be3fec0a2c79260e2d6ffabe8e4b90bc
7
- data.tar.gz: 296c77c8b88f0ddb86d20d63d2ef5beee702b64d2231d32fc20437e803bcd28ea0f3f89b7815320010131dc458a8b8f8ae6742d5583731199ff2dbe3b9efd038
6
+ metadata.gz: a66d5f3d8160159490b7197cd0e1edf0107e7cb6610d019495a8ab02650118881f94d6c8deca7ef3bce55cdcfe3573392626e10220ec158876f807556f147b81
7
+ data.tar.gz: f0cdc245a2c4f58432475e7cb3afe32acb707d0710e150977e823418142424f955ae3301748aeae072cf994db52654d0c544d02257bfd8bdc6e6dc7219e16a94
data/.rubocop.yml CHANGED
@@ -50,3 +50,5 @@ Style/HashTransformKeys:
50
50
  Enabled: true
51
51
  Style/HashTransformValues:
52
52
  Enabled: true
53
+ Naming/VariableNumber:
54
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -3,13 +3,17 @@
3
3
  All changes to the gem are documented here.
4
4
 
5
5
 
6
+ ## [1.0.3] - 2020-05-20
7
+
8
+ - Added Czech Post service DiscountForOnlinePosting.
9
+ - **Breaking**: Renamed Post service size classes `CzechPostB2bClient::PostServices::Size???` to `CzechPostB2bClient::PostServices::ParcelSize???` (eg. : `CzechPostB2bClient::PostServices::ParcelSizeXL`)
10
+ I know, that I have **breaking** in every new version, I hope You are not fast enough.
11
+
6
12
  ## [1.0.2] - 2020-05-08
7
13
 
8
14
  - Added Czech Post services as classes, not just list in docs.
9
15
  - **Breaking**: Renamed methods `CzechPostB2bClient::PrintingTemplate.all_template_classes` and `CzechPostB2bClient::ResponseCodes.all_code_classes` to `CzechPostB2bClient::PrintingTemplate.all_classes` , and `CzechPostB2bClient::ResponseCodes.all_classes`
10
16
 
11
-
12
-
13
17
  ## [1.0.0] - 2020-03-19
14
18
 
15
19
  Production ready release
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/AsciiComments
3
+ # rubocop:disable Style/AsciiComments, Layout/LineLength
4
4
 
5
5
  # response <B2BFaultMessage>
6
6
  # Chybový kód | Detail chyby | Popis
@@ -15,8 +15,6 @@
15
15
  # 9 | TRY_AGAIN_LATER | Překročen parametr maximálního počtu volání služby v daný okamžik
16
16
  # 10 | UNFINISHED_PROCESS | Zpracování není ještě ukončeno (u async operací)
17
17
 
18
- # rubocop:enable Style/AsciiComments
19
-
20
18
  # B2B errors, which can be returned in response `B2BFaultMessage`
21
19
  #
22
20
  # Do not miss `CzechPostB2bClient::B2BErrors.all_error_classes` and `CzechPostB2bClient::B2BErrors.new_by_code`,
@@ -91,17 +89,18 @@ module CzechPostB2bClient
91
89
  @message = 'Zpracování není ještě ukončeno (u async operací)'
92
90
  end
93
91
 
94
- def all_error_classes
92
+ # have t be at end of file, to collect all classes defined before
93
+ def self.all_error_classes
95
94
  ObjectSpace.each_object(CzechPostB2bClient::B2BErrors::BaseError.singleton_class)
96
95
  end
97
- module_function :all_error_classes
98
96
 
99
- def new_by_code(code)
97
+ def self.new_by_code(code)
100
98
  klass = all_error_classes.detect { |k| k.code == code }
101
99
  raise "B2BError with code: #{code} is unknown!" unless klass
102
100
 
103
101
  klass.new
104
102
  end
105
- module_function :new_by_code
106
103
  end
107
104
  end
105
+
106
+ # rubocop:enable Style/AsciiComments, Layout/LineLength
@@ -19,12 +19,16 @@ module CzechPostB2bClient
19
19
  def initialize
20
20
  # set defaults here
21
21
 
22
- # ours, accessible, but maybe oout of date
23
- @namespaces = { 'xmlns' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/doc/20181023/B2BCommon-v1.1.xsd',
24
- 'xmlns:ns2' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/doc/20181023/B2B-POLServices-v1.6.xsd' }
25
- # original, not functioning
26
- @namespaces = { 'xmlns' => 'https://b2b.postaonline.cz/schema/B2BCommon-v1',
27
- 'xmlns:ns2' => 'https://b2b.postaonline.cz/schema/POLServices-v1' }
22
+ # ours, accessible, but maybe out of date, for test usage
23
+ @namespaces = {
24
+ 'xmlns' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/doc/20181023/B2BCommon-v1.1.xsd',
25
+ 'xmlns:ns2' => 'https://raw.githubusercontent.com/foton/czech_post_b2b_client/master/doc/20181023/B2B-POLServices-v1.6.xsd'
26
+ }
27
+ # original, accessible only with setup certificates
28
+ @namespaces = {
29
+ 'xmlns' => 'https://b2b.postaonline.cz/schema/B2BCommon-v1',
30
+ 'xmlns:ns2' => 'https://b2b.postaonline.cz/schema/POLServices-v1'
31
+ }
28
32
  @language = :cs
29
33
  @logger = defined?(Rails) ? ::Rails.logger : ::Logger.new(STDOUT)
30
34
  @b2b_api_base_uri = 'https://b2b.postaonline.cz/services/POLService/v1'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Layout/LineLength, Style/AsciiComments
4
+
3
5
  # Hopefully complete list of services which can be assigned to parcels
4
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).
5
7
  # They have SAME CODES! for different services (depending on which parcel You send).
@@ -7,7 +9,7 @@
7
9
 
8
10
  # source: https://www.postaonline.cz/podanionline/ePOST-dokumentace/20prilohy.html and older one
9
11
  # Old services are commented out
10
- # omments at end of line mostly describes which type of parcels can 'afford' such service
12
+ # Comments at end of line mostly describes which type of parcels can 'afford' such service
11
13
  #
12
14
  # Do not miss `CzechPostB2bClient::PostServices.all_classes` method,
13
15
  # it has to be at end of module to work properly
@@ -20,31 +22,31 @@ module CzechPostB2bClient
20
22
  end
21
23
  end
22
24
 
23
- class SizeS < Base
25
+ class ParcelSizeS < Base
24
26
  @code = 'S'
25
27
  @abbreviation = 'S'
26
- @description = 'Velkost S'
28
+ @description = 'Velikost S (nejdelší strana do 35cm)'
27
29
  # ; Balík Do ruky (DR, DV, DE) ; Balík Na poštu (NP, NV, NA) ; Cenný balík ((B, BD, BB, V, VD, VV) ; EMS (EE) ; Doporučený balíček (BA) ; Balík Expres (BE) ; Obyčejný balík (O)
28
30
  end
29
31
 
30
- class SizeM < Base
32
+ class ParcelSizeM < Base
31
33
  @code = 'M'
32
34
  @abbreviation = 'M'
33
- @description = 'Velikost M'
35
+ @description = 'Velikost M (nejdelší strana do 50cm)'
34
36
  # ; Balík Do ruky (DR, DV, DE) ; Balík Na poštu (NP, NV, NA) ; Cenný balík ((B, BD, BB, V, VD, VV) ; EMS (EE) ; Doporučený balíček (BA) ; Balík Expres (BE) ; Obyčejný balík (O)
35
37
  end
36
38
 
37
- class SizeL < Base
39
+ class ParcelSizeL < Base
38
40
  @code = 'L'
39
41
  @abbreviation = 'L'
40
- @description = 'Velikost L'
42
+ @description = 'Velikost L (nejdelší strana do 100cm)'
41
43
  # ; Balík Do ruky (DR, DV, DE) ; Balík Na poštu (NP, NV, NA) ; Cenný balík ((B, BD, BB, V, VD, VV) ; EMS (EE) ; Doporučený balíček (BA) ; Obyčejný balík (O)
42
44
  end
43
45
 
44
- class SizeXL < Base
46
+ class ParcelSizeXL < Base
45
47
  @code = 'XL'
46
48
  @abbreviation = 'XL'
47
- @description = 'Velikost XL'
49
+ @description = 'Velikost XL (nejdelší strana do 240cm)'
48
50
  # ; Balík Do ruky (DR, DV, DE) ; Balík Na poštu (NP, NV, NA) ; Cenný balík ((B, BD, BB, V, VD, VV) ; Obyčejný balík (O) |
49
51
  end
50
52
 
@@ -739,6 +741,12 @@ module CzechPostB2bClient
739
741
  @description = 'Vrátit ekonomicky'
740
742
  end
741
743
 
744
+ class DiscountForOnlinePosting < Base
745
+ @code = '97'
746
+ @abbreviation = ''
747
+ @description = 'Sleva za elektronické předání dat'
748
+ end
749
+
742
750
  # **Pozn. U RR zásilek je vždy jedna ze služeb 50 až 60 povinná!!!!!!**
743
751
  # Čísla požadovaných služeb budou zadána do pole požadované služby k zásilce dle výše uvedeného číselníku v libovolném pořadí. Kombinace více služeb bude zadávána tímto způsobem, např. Dodejka, Pilně a Dobírka s Pk A: 3+4+15
744
752
  # U služeb pro elektronické avízo lze zadat vždy jen jednu z uvedených služeb 34 nebo 45 nebo 46. Kombinace těchto služeb není možná a bude na poště vyhodnocená jako chybná. Bez uvedení kontaktních údajů na adresáta (mobilní telefonní číslo nebo e-mail) není služba možná a na poště bude vyhodnocena jako chybná.
@@ -759,9 +767,10 @@ module CzechPostB2bClient
759
767
  # Podavatelé, kteří nemají sjednánu smluvní cenu, musí od 1. 3.2019 při podání zásilek Balík Do ruky, Balík Na poštu, Cenný Balík, Doporučený balíček, Balík Expres, Obyčejný balík a EMS uvádět povinně ve službách jednu z rozměrových služeb S, M, L, XL.
760
768
 
761
769
  # has to be at the end, to load all subcasses before
762
- def all_classes
770
+ def self.all_classes
763
771
  ObjectSpace.each_object(CzechPostB2bClient::PostServices::Base.singleton_class)
764
772
  end
765
- module_function :all_classes
766
773
  end
767
774
  end
775
+
776
+ # rubocop:enable Layout/LineLength, Style/AsciiComments
@@ -155,9 +155,8 @@ module CzechPostB2bClient
155
155
  end
156
156
 
157
157
  # has to be at the end, to load all subcasses before
158
- def all_classes
158
+ def self.all_classes
159
159
  ObjectSpace.each_object(CzechPostB2bClient::PrintingTemplates::Base.singleton_class)
160
160
  end
161
- module_function :all_classes
162
161
  end
163
162
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Layout/LineLength
4
+
3
5
  module CzechPostB2bClient
4
6
  module RequestBuilders
5
7
  class GetParcelsPrintingBuilder < BaseBuilder
@@ -44,7 +46,7 @@ module CzechPostB2bClient
44
46
  end
45
47
  end
46
48
 
47
- def do_printing_header
49
+ def do_printing_header # rubocop:disable Metrics/AbcSize
48
50
  new_element('ns2:doPrintingHeader').tap do |printing_header|
49
51
  add_element_to(printing_header, 'ns2:customerID', value: options[:customer_id]) # Technologicke cislo podavatele
50
52
  add_element_to(printing_header, 'ns2:contractNumber', value: options[:contract_number]) # Nepovine: ID CCK slozky podavatele
@@ -77,3 +79,5 @@ module CzechPostB2bClient
77
79
  end
78
80
  end
79
81
  end
82
+
83
+ # rubocop:enable Layout/LineLength
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Layout/LineLength, Style/AsciiComments
4
+
3
5
  module CzechPostB2bClient
4
6
  module RequestBuilders
5
- class SendParcelsBuilder < BaseBuilder
7
+ class SendParcelsBuilder < BaseBuilder # rubocop:disable Metrics/ClassLength
6
8
  attr_reader :common_data, :parcels
7
9
 
8
10
  def initialize(common_data:, parcels:, request_id: 1)
@@ -72,7 +74,7 @@ module CzechPostB2bClient
72
74
  end
73
75
  end
74
76
 
75
- def do_parcel_header
77
+ def do_parcel_header # rubocop:disable Metrics/AbcSize
76
78
  new_element('ns2:doParcelHeader').tap do |parcel_header|
77
79
  add_element_to(parcel_header, 'ns2:transmissionDate', value: common_data[:parcels_sending_date].strftime('%d.%m.%Y')) # Predpokladane datum podani (format DD.MM.YYYY !)
78
80
  add_element_to(parcel_header, 'ns2:customerID', value: common_data[:customer_id]) # Technologicke cislo podavatele
@@ -133,7 +135,7 @@ module CzechPostB2bClient
133
135
  end
134
136
  end
135
137
 
136
- def do_parcel_params(parcel_data)
138
+ def do_parcel_params(parcel_data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
137
139
  params = parcel_data[:params]
138
140
  cod = parcel_data[:cash_on_delivery] || {}
139
141
  new_element('ns2:doParcelParams').tap do |parcel_params|
@@ -183,7 +185,7 @@ module CzechPostB2bClient
183
185
  add_parcel_adress_element('ns2:doParcelAddressDocument', parcel_data[:document_addressee])
184
186
  end
185
187
 
186
- def add_parcel_adress_element(element_name, addressee_data)
188
+ def add_parcel_adress_element(element_name, addressee_data) # rubocop:disable Metrics/AbcSize
187
189
  return nil if addressee_data.nil?
188
190
 
189
191
  address_data = addressee_data[:address]
@@ -237,7 +239,8 @@ module CzechPostB2bClient
237
239
  end
238
240
  end
239
241
 
240
- def add_address_elements(parent_element, address_data, without: []) # Nepovinne. Adresa
242
+ # Nepovinne. Adresa
243
+ def add_address_elements(parent_element, address_data, without: [])
241
244
  return if address_data.nil?
242
245
 
243
246
  address_tags_and_values(address_data).each_pair do |xml_tag, value|
@@ -292,3 +295,5 @@ module CzechPostB2bClient
292
295
  end
293
296
  end
294
297
  end
298
+
299
+ # rubocop:enable Layout/LineLength, Style/AsciiComments
@@ -5,7 +5,7 @@
5
5
  # Do not miss `CzechPostB2bClient::ResponseCodes.all_classes` and `CzechPostB2bClient::ResponseCodes.new_by_code`,
6
6
  # they have to be at end of module to work properly
7
7
  module CzechPostB2bClient
8
- module ResponseCodes
8
+ module ResponseCodes # rubocop:disable Metrics/ModuleLength
9
9
  class BaseCode
10
10
  @code = 'undefined'
11
11
  @text = '_NONE_'
@@ -281,7 +281,8 @@ module CzechPostB2bClient
281
281
  class InvalidAddressForBigPackage < CzechPostB2bClient::ResponseCodes::BaseCode
282
282
  @code = 119
283
283
  @text = 'INVALID_ADRESS'
284
- @description = 'Adresa odesílatele není vhodná pro produkt Nadrozměrná zásilka(adresa obsahuje údaj P.O.Box nebo Poste restante)!'
284
+ @description = 'Adresa odesílatele není vhodná pro produkt Nadrozměrná zásilka' \
285
+ '(adresa obsahuje údaj P.O.Box nebo Poste restante)!'
285
286
  @type = :chyba
286
287
  end
287
288
 
@@ -589,21 +590,24 @@ module CzechPostB2bClient
589
590
  class CODAmountTooBig < CzechPostB2bClient::ResponseCodes::BaseCode
590
591
  @code = 177
591
592
  @text = 'INVALID_AMOUNT'
592
- @description = 'Limit pro uložení zásilky na Výdejním místě je pro Dobírku max. 50.000,- Kč. Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
593
+ @description = 'Limit pro uložení zásilky na Výdejním místě je pro Dobírku max. 50.000,- Kč.' \
594
+ ' Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
593
595
  @type = :chyba
594
596
  end
595
597
 
596
598
  class PriceTooBig < CzechPostB2bClient::ResponseCodes::BaseCode
597
599
  @code = 178
598
600
  @text = 'INVALID_PRICE'
599
- @description = 'Limit pro uložení zásilky na Výdejním místě je pro Udanou cenu a Dobírku max. 50.000,- Kč. Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
601
+ @description = 'Limit pro uložení zásilky na Výdejním místě je pro Udanou cenu a Dobírku max. 50.000,- Kč.' \
602
+ ' Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
600
603
  @type = :chyba
601
604
  end
602
605
 
603
606
  class PriceAndCODAmountTooBig < CzechPostB2bClient::ResponseCodes::BaseCode
604
607
  @code = 179
605
608
  @text = 'INVALID_PRICE_AND_AMOUNT'
606
- @description = 'Limit pro uložení zásilky na Výdejním místě je pro Udanou cenu a Dobírku max. 50.000,- Kč. Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
609
+ @description = 'Limit pro uložení zásilky na Výdejním místě je pro Udanou cenu a Dobírku max. 50.000,- Kč.' \
610
+ ' Zásilka bude uložena na poště, která je Výdejnímu místu nadřízená.'
607
611
  @type = :chyba
608
612
  end
609
613
 
@@ -1290,7 +1294,8 @@ module CzechPostB2bClient
1290
1294
  class InfoService29And47 < CzechPostB2bClient::ResponseCodes::BaseCode
1291
1295
  @code = 324
1292
1296
  @text = 'INFO_SERVICE_29+47'
1293
- @description = 'Zásilku s výškou nad 150cm nelze podat jako Balík Do ruky se sl.47, ale musí být využit Balík Nadrozměr v kategorii NZ 2'
1297
+ @description = 'Zásilku s výškou nad 150cm nelze podat jako Balík Do ruky se sl.47,' \
1298
+ ' ale musí být využit Balík Nadrozměr v kategorii NZ 2'
1294
1299
  @type = :info
1295
1300
  end
1296
1301
 
@@ -1756,14 +1761,14 @@ module CzechPostB2bClient
1756
1761
  @type = :info
1757
1762
  end
1758
1763
 
1759
- class InfoMissingPartCityServiceDeliveryOnSundayOrHolidayMayNotBeRealized < CzechPostB2bClient::ResponseCodes::BaseCode
1764
+ class InfoMissingPartCityServiceDeliveryOnSundayOrHolidayMayNotBeRealized < CzechPostB2bClient::ResponseCodes::BaseCode # rubocop:disable Layout/LineLength
1760
1765
  @code = 391
1761
1766
  @text = 'INFO_MISSING_PART_CITY_SERVICE_DELIVERY_ON_SUNDAY/HOLIDAY_MAY_NOT_BE_REALIZED'
1762
- @description = 'Neuvedena část obce - sl. Gar. čas dodání v Ne/Sv nemusí být realizována'
1767
+ @description = 'Neuvedena část obce - služba Garantovaný čas dodání v Ne/Sv nemusí být realizována'
1763
1768
  @type = :info
1764
1769
  end
1765
1770
 
1766
- class NfoCancelService9 < CzechPostB2bClient::ResponseCodes::BaseCode
1771
+ class InfoCancelService9 < CzechPostB2bClient::ResponseCodes::BaseCode
1767
1772
  @code = 392
1768
1773
  @text = 'NFO_CANCEL_SERVICE_9'
1769
1774
  @description = 'Zrušena nepovolená služba 9 Prioritně'
@@ -1882,19 +1887,16 @@ module CzechPostB2bClient
1882
1887
  @type = :info
1883
1888
  end
1884
1889
 
1885
- def all_classes
1890
+ # must be at end to collect all classes defined before
1891
+ def self.all_classes
1886
1892
  ObjectSpace.each_object(CzechPostB2bClient::ResponseCodes::BaseCode.singleton_class)
1887
1893
  end
1888
1894
 
1889
- module_function :all_classes
1890
-
1891
- def new_by_code(code)
1895
+ def self.new_by_code(code)
1892
1896
  klass = all_classes.detect { |k| k.code == code }
1893
1897
  raise "ResponseCode with code: #{code} is unknown!" unless klass
1894
1898
 
1895
1899
  klass.new
1896
1900
  end
1897
-
1898
- module_function :new_by_code
1899
1901
  end
1900
1902
  end
@@ -24,11 +24,12 @@ module CzechPostB2bClient
24
24
  [response_root_node.dig('parcel')].flatten.compact # to always get array of hash(es)
25
25
  end
26
26
 
27
- def parcel_data_from(rp_hash)
27
+ def parcel_data_from(rp_hash) # rubocop:disable Metrics/AbcSize
28
28
  {
29
29
  parcel_type: rp_hash['parcelType'].to_s,
30
- weight_in_kg: rp_hash['weight'].nil? ? nil : rp_hash['weight'].to_f, # hopefully it is in KG
31
- cash_on_delivery: { amount: (rp_hash['amount'] || 0).to_f, currency_iso_code: rp_hash['currency'].to_s },
30
+ weight_in_kg: rp_hash['weight'].nil? ? nil : rp_hash['weight'].to_f,
31
+ cash_on_delivery: { amount: (rp_hash['amount'] || 0).to_f,
32
+ currency_iso_code: rp_hash['currency'].to_s },
32
33
  pieces: (rp_hash['quantityParcel'] || 1).to_i,
33
34
  deposited_until: rp_hash['depositTo'].nil? ? nil : Date.parse(rp_hash['depositTo']),
34
35
  deposited_for_days: rp_hash['timeDeposit'].nil? ? nil : rp_hash['timeDeposit'].to_i,
@@ -5,8 +5,30 @@ module CzechPostB2bClient
5
5
  class SendParcelsParser < BaseParser
6
6
  def build_result
7
7
  super
8
- @result[:async_result] = { transaction_id: response_header.dig('idTransaction'),
9
- processing_end_expected_at: Time.parse(response_header.dig('timeStampProcessing')) } # it is NOT CORRECT! They return CET time value with UTC timezone
8
+
9
+ @result[:async_result] = {
10
+ transaction_id: response_header.dig('idTransaction'),
11
+ processing_end_expected_at: parse_time_with_correction(response_header.dig('timeStampProcessing'))
12
+ }
13
+ end
14
+
15
+ def parse_time_with_correction(b2b_time_str)
16
+ # b2b time in XML is NOT CORRECT! They return CET time value with UTC timezone
17
+ # Like `2016-02-25T09:30:03.678Z`, which is actually `2016-02-25T09:30:03.678+0100` (CET)
18
+ # Or `2016-05-25T09:30:03.678Z`, which is actually `2016-05-25T09:30:03.678+0200` (CET + DST)
19
+ # But we must be prepare for unnoticed fix by CPost
20
+
21
+ # unfortunattely this can be done for only freshly generated XMLs (comparing b2b_time with Time.now.utc)
22
+ # but we have to kepp it compatible for old XML
23
+ # so we pass it up and leave comments in documenation
24
+ # Users of this gem will have to care of it
25
+
26
+ Time.parse(b2b_time_str)
27
+ end
28
+
29
+ # just for info
30
+ def cpost_time_zone
31
+ timezone('Europe/Prague')
10
32
  end
11
33
  end
12
34
  end
@@ -32,14 +32,9 @@ module CzechPostB2bClient
32
32
  attr_accessor :request_xml, :response, :endpoint_path
33
33
 
34
34
  def call_api
35
- request = Net::HTTP::Post.new service_uri.request_uri, headers
36
- request.body = request_xml
37
- CzechPostB2bClient.logger.debug("CzechPost B2B REQUEST: #{request} to #{service_uri.request_uri} with body:\n#{request.body}")
38
- begin
39
- self.response = https_conn.request(request)
40
- rescue *KNOWN_CONNECTION_ERRORS => e
41
- handle_connection_error(e)
42
- end
35
+ self.response = https_conn.request(request)
36
+ rescue *KNOWN_CONNECTION_ERRORS => e
37
+ handle_connection_error(e)
43
38
  end
44
39
 
45
40
  def handle_response
@@ -56,6 +51,16 @@ module CzechPostB2bClient
56
51
  @https_conn ||= Net::HTTP.start(service_uri.host, service_uri.port, connection_options)
57
52
  end
58
53
 
54
+ def request
55
+ request = Net::HTTP::Post.new service_uri.request_uri, headers
56
+ request.body = request_xml
57
+
58
+ debug_msg = "CzechPost B2B REQUEST: #{request} to #{service_uri.request_uri} with body:\n#{request.body}"
59
+ CzechPostB2bClient.logger.debug(debug_msg)
60
+
61
+ request
62
+ end
63
+
59
64
  def service_uri
60
65
  @service_uri ||= URI.parse(configuration.b2b_api_base_uri + endpoint_path)
61
66
  end
@@ -95,7 +100,8 @@ module CzechPostB2bClient
95
100
  end
96
101
 
97
102
  def b2b_error_text
98
- error_match = result.xml.match(%r{<(?:\w+\:)?errorCode>(\d+)</(?:\w+\:)?errorCode>}) # errorCode tag with stripped out namespace
103
+ err_code_without_namespace_regexp = %r{<(?:\w+\:)?errorCode>(\d+)</(?:\w+\:)?errorCode>}
104
+ error_match = result.xml.match(err_code_without_namespace_regexp)
99
105
  return 'error code not found in XML' unless error_match
100
106
 
101
107
  error_code = error_match[1].to_i
@@ -79,7 +79,7 @@ module CzechPostB2bClient
79
79
  response_code = response_state[:code]
80
80
  next if response_code == CzechPostB2bClient::ResponseCodes::Ok.code
81
81
 
82
- errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}")
82
+ errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}") # rubocop:disable Layout/LineLength
83
83
  end
84
84
  end
85
85
  end
@@ -63,7 +63,7 @@ module CzechPostB2bClient
63
63
  response_code = response_state[:code]
64
64
  next if response_code == CzechPostB2bClient::ResponseCodes::Ok.code
65
65
 
66
- errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}")
66
+ errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}") # rubocop:disable Layout/LineLength
67
67
  end
68
68
  end
69
69
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+ require 'net/http'
5
+
6
+ module CzechPostB2bClient
7
+ module Services
8
+ class XsdsDownloader < ApiCaller
9
+ def initialize(_anything); end
10
+
11
+ def steps
12
+ %i[download_xsds]
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :xsd_uri
18
+
19
+ def download_xsds
20
+ xsd_uris = configuration.namespaces.values
21
+ xsd_uris.each do |uri|
22
+ # check for `.xsd` at end?
23
+ @xsd_uri = URI.parse(uri)
24
+ download
25
+ end
26
+ end
27
+
28
+ def download # rubocop:disable Metrics/AbcSize
29
+ self.response = https_conn.request(request)
30
+
31
+ debug_msg = "CzechPost XSD REQUEST: #{request} to #{xsd_uri} with body:\n#{request.body} => #{response.code}"
32
+ CzechPostB2bClient.logger.debug(debug_msg)
33
+
34
+ raise "Error in downloading #{xsd_uri} => #{response}" unless response.code.to_i == 200
35
+
36
+ save_response_to_file
37
+ rescue *KNOWN_CONNECTION_ERRORS => e
38
+ raise "Error in downloading #{xsd_uri} => #{e.message}"
39
+ end
40
+
41
+ def https_conn
42
+ Net::HTTP.start(xsd_uri.host, xsd_uri.port, connection_options)
43
+ end
44
+
45
+ def request
46
+ Net::HTTP::Get.new xsd_uri.request_uri, headers
47
+ end
48
+
49
+ def save_response_to_file
50
+ filename = xsd_uri.request_uri.split('/').last
51
+ File.write(filename, response.body)
52
+ end
53
+
54
+ def headers
55
+ {}
56
+ end
57
+ end
58
+ end
59
+ end
@@ -10,3 +10,4 @@ require 'czech_post_b2b_client/services/address_sheets_generator'
10
10
  require 'czech_post_b2b_client/services/parcels_submission_closer'
11
11
  require 'czech_post_b2b_client/services/delivering_inspector'
12
12
  require 'czech_post_b2b_client/services/time_period_statisticator'
13
+ require 'czech_post_b2b_client/services/xsds_downloader'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CzechPostB2bClient
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
@@ -43,7 +43,8 @@
43
43
  # def put_tea_bags_into_kettle
44
44
  # self.teabags = get_teabags(tea_type, bags_into_kettle)
45
45
  # if teabags.empty?
46
- # errors.add(:teabags, "There is no #{bags_into_kettle} #{tea_type} tea teabags in storage, using fruit tea teabags.")
46
+ # errors.add(:teabags, "There is no #{bags_into_kettle} #{tea_type} tea teabags in storage," \
47
+ # " using fruit tea teabags.")
47
48
  # self.teabags = get_teabags(:fruit, bags_into_kettle)
48
49
  # if teabags.empty?
49
50
  # errors.add(:teabags, "There is no #{bags_into_kettle} fruit tea teabags in storage either!")
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.0.2
4
+ version: 1.0.3
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: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ox
@@ -536,6 +536,7 @@ files:
536
536
  - lib/czech_post_b2b_client/services/parcels_sender.rb
537
537
  - lib/czech_post_b2b_client/services/parcels_submission_closer.rb
538
538
  - lib/czech_post_b2b_client/services/time_period_statisticator.rb
539
+ - lib/czech_post_b2b_client/services/xsds_downloader.rb
539
540
  - lib/czech_post_b2b_client/version.rb
540
541
  - lib/stepped_service.rb
541
542
  - lib/stepped_service/base.rb