czech_post_b2b_client 1.0.0 → 1.0.2
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 +4 -4
- data/.rubocop.yml +15 -3
- data/CHANGELOG.md +8 -0
- data/README.md +5 -5
- data/lib/czech_post_b2b_client.rb +2 -0
- data/lib/czech_post_b2b_client/b2b_errors.rb +6 -4
- data/lib/czech_post_b2b_client/post_services.rb +767 -0
- data/lib/czech_post_b2b_client/printing_templates.rb +5 -8
- data/lib/czech_post_b2b_client/request_builders/get_parcels_printing_builder.rb +1 -1
- data/lib/czech_post_b2b_client/request_builders/send_parcels_builder.rb +2 -2
- data/lib/czech_post_b2b_client/response_codes.rb +21 -21
- data/lib/czech_post_b2b_client/response_parsers/base_parser.rb +8 -6
- data/lib/czech_post_b2b_client/response_parsers/get_parcel_state_parser.rb +1 -1
- data/lib/czech_post_b2b_client/response_parsers/get_parcels_printing_parser.rb +2 -1
- data/lib/czech_post_b2b_client/response_parsers/get_result_parcels_parser.rb +4 -2
- data/lib/czech_post_b2b_client/services.rb +2 -0
- data/lib/czech_post_b2b_client/services/delivering_inspector.rb +4 -4
- data/lib/czech_post_b2b_client/services/orchestrator.rb +0 -1
- data/lib/czech_post_b2b_client/services/parcels_immediate_sender.rb +87 -0
- data/lib/czech_post_b2b_client/services/parcels_send_process_updater.rb +1 -1
- data/lib/czech_post_b2b_client/services/time_period_statisticator.rb +1 -1
- data/lib/czech_post_b2b_client/version.rb +1 -1
- metadata +8 -6
@@ -1,17 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# Available printing templates, which can be used in AdressSheetsGenerator `options[:template_id]`
|
3
4
|
#
|
4
|
-
# Do not miss `CzechPostB2bClient::
|
5
|
+
# Do not miss `CzechPostB2bClient::PrintingTemplates.all_classes` method,
|
5
6
|
# it has to be at end of module to work properly
|
6
7
|
module CzechPostB2bClient
|
7
8
|
module PrintingTemplates
|
8
9
|
class Base
|
9
10
|
class << self
|
10
|
-
attr_reader :id
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
attr_reader :description
|
11
|
+
attr_reader :id, :description
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
@@ -158,9 +155,9 @@ module CzechPostB2bClient
|
|
158
155
|
end
|
159
156
|
|
160
157
|
# has to be at the end, to load all subcasses before
|
161
|
-
def
|
158
|
+
def all_classes
|
162
159
|
ObjectSpace.each_object(CzechPostB2bClient::PrintingTemplates::Base.singleton_class)
|
163
160
|
end
|
164
|
-
module_function :
|
161
|
+
module_function :all_classes
|
165
162
|
end
|
166
163
|
end
|
@@ -12,7 +12,7 @@ module CzechPostB2bClient
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.allowed_printing_template_classes
|
15
|
-
@allowed_printing_template_classes ||= CzechPostB2bClient::PrintingTemplates.
|
15
|
+
@allowed_printing_template_classes ||= CzechPostB2bClient::PrintingTemplates.all_classes
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -34,7 +34,7 @@ module CzechPostB2bClient
|
|
34
34
|
[:sending_post_office_code]].each do |key_chain|
|
35
35
|
value = common_data.dig(*key_chain)
|
36
36
|
if value.nil? || value == ''
|
37
|
-
errors.add(:common_data, "Missing value for key { :#{key_chain.join(' => :')
|
37
|
+
errors.add(:common_data, "Missing value for key { :#{key_chain.join(' => :')} }!")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -260,7 +260,7 @@ module CzechPostB2bClient
|
|
260
260
|
'ns2:city' => address_data[:city], # Nepovinne: Obec
|
261
261
|
'ns2:zipCode' => address_data[:post_code], # Nepovinne: PSC
|
262
262
|
'ns2:isoCountry' => address_data[:country_iso_code], # Nepovinne, default 'CZ': ISO kod zeme
|
263
|
-
'ns2:subIsoCountry' => address_data[:subcountry_iso_code]
|
263
|
+
'ns2:subIsoCountry' => address_data[:subcountry_iso_code] # Nepovinne: ISO kod uzemi
|
264
264
|
}
|
265
265
|
end
|
266
266
|
|
@@ -1,25 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Codes, which can be returned in response nodes `doParcelStateResponse`
|
2
4
|
#
|
3
|
-
# Do not miss `CzechPostB2bClient::ResponseCodes.
|
5
|
+
# Do not miss `CzechPostB2bClient::ResponseCodes.all_classes` and `CzechPostB2bClient::ResponseCodes.new_by_code`,
|
4
6
|
# they have to be at end of module to work properly
|
5
7
|
module CzechPostB2bClient
|
6
8
|
module ResponseCodes
|
7
9
|
class BaseCode
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
@code = 'undefined'
|
11
|
+
@text = '_NONE_'
|
12
|
+
@decription = 'Unspecified B2B response code, is it listed in /doc/.../ResponseCodes.ods'
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
class << self
|
15
|
+
attr_reader :code
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
class << self
|
19
|
+
attr_reader :text
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
class << self
|
23
|
+
attr_reader :description
|
24
|
+
end
|
23
25
|
|
24
26
|
def self.error?
|
25
27
|
@type == :error
|
@@ -29,9 +31,9 @@ module CzechPostB2bClient
|
|
29
31
|
@type == :info
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
class << self
|
35
|
+
attr_reader :type
|
36
|
+
end
|
35
37
|
|
36
38
|
def self.to_s
|
37
39
|
"ResponseCode[#{code} #{text}] #{description}"
|
@@ -1061,7 +1063,6 @@ module CzechPostB2bClient
|
|
1061
1063
|
@type = :chyba
|
1062
1064
|
end
|
1063
1065
|
|
1064
|
-
|
1065
1066
|
class AddressSuitableForLocalDelivery < CzechPostB2bClient::ResponseCodes::BaseCode
|
1066
1067
|
@code = 257
|
1067
1068
|
@text = 'INVALID_ADRESS' # no kidding! Like 6 times same text?
|
@@ -1881,14 +1882,14 @@ module CzechPostB2bClient
|
|
1881
1882
|
@type = :info
|
1882
1883
|
end
|
1883
1884
|
|
1884
|
-
def
|
1885
|
+
def all_classes
|
1885
1886
|
ObjectSpace.each_object(CzechPostB2bClient::ResponseCodes::BaseCode.singleton_class)
|
1886
1887
|
end
|
1887
1888
|
|
1888
|
-
module_function :
|
1889
|
+
module_function :all_classes
|
1889
1890
|
|
1890
1891
|
def new_by_code(code)
|
1891
|
-
klass =
|
1892
|
+
klass = all_classes.detect { |k| k.code == code }
|
1892
1893
|
raise "ResponseCode with code: #{code} is unknown!" unless klass
|
1893
1894
|
|
1894
1895
|
klass.new
|
@@ -1897,4 +1898,3 @@ module CzechPostB2bClient
|
|
1897
1898
|
module_function :new_by_code
|
1898
1899
|
end
|
1899
1900
|
end
|
1900
|
-
|
@@ -22,14 +22,14 @@ module CzechPostB2bClient
|
|
22
22
|
strip_namespace: true,
|
23
23
|
symbolize_keys: false,
|
24
24
|
mode: :hash_no_attrs)
|
25
|
-
rescue Ox::ParseError =>
|
26
|
-
handle_parsing_error(
|
25
|
+
rescue Ox::ParseError => e
|
26
|
+
handle_parsing_error(e)
|
27
27
|
end
|
28
28
|
|
29
29
|
def safely_build_result
|
30
30
|
build_result
|
31
|
-
rescue NoMethodError =>
|
32
|
-
handle_result_building_error(
|
31
|
+
rescue NoMethodError => e # NoMethodError: undefined method `dig' for nil:NilClass
|
32
|
+
handle_result_building_error(e)
|
33
33
|
end
|
34
34
|
|
35
35
|
def build_result
|
@@ -50,7 +50,9 @@ module CzechPostB2bClient
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def response_root_node
|
53
|
-
|
53
|
+
if response_service_data.keys.include?(response_root_node_name)
|
54
|
+
return response_service_data.dig(response_root_node_name)
|
55
|
+
end
|
54
56
|
|
55
57
|
errors.add(:xml, "Cannot find `#{response_root_node_name}` in `serviceData` node.")
|
56
58
|
fail_on_structure_parsing
|
@@ -71,7 +73,7 @@ module CzechPostB2bClient
|
|
71
73
|
state_hash = hash || { 'responseCode' => '999', 'responseText' => 'Unknown' }
|
72
74
|
state_hash = state_hash.first if state_hash.is_a?(Array) # more <doParcelStateResponse> elements
|
73
75
|
|
74
|
-
{ code: state_hash['responseCode'].to_i, text: state_hash['responseText'].to_s}
|
76
|
+
{ code: state_hash['responseCode'].to_i, text: state_hash['responseText'].to_s }
|
75
77
|
end
|
76
78
|
|
77
79
|
def handle_parsing_error(error)
|
@@ -27,7 +27,7 @@ module CzechPostB2bClient
|
|
27
27
|
def parcel_data_from(rp_hash)
|
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,
|
30
|
+
weight_in_kg: rp_hash['weight'].nil? ? nil : rp_hash['weight'].to_f, # hopefully it is in KG
|
31
31
|
cash_on_delivery: { amount: (rp_hash['amount'] || 0).to_f, currency_iso_code: rp_hash['currency'].to_s },
|
32
32
|
pieces: (rp_hash['quantityParcel'] || 1).to_i,
|
33
33
|
deposited_until: rp_hash['depositTo'].nil? ? nil : Date.parse(rp_hash['depositTo']),
|
@@ -38,7 +38,7 @@ module CzechPostB2bClient
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def updated_result_value_for(value, parcel_params_result_hash)
|
41
|
-
pd_hash=parcel_data_from(parcel_params_result_hash)
|
41
|
+
pd_hash = parcel_data_from(parcel_params_result_hash)
|
42
42
|
|
43
43
|
return pd_hash if value.nil?
|
44
44
|
|
@@ -47,7 +47,9 @@ module CzechPostB2bClient
|
|
47
47
|
new_p_code = pd_hash[:parcel_code]
|
48
48
|
|
49
49
|
value[:states] = (value[:states] + pd_hash[:states]).sort { |a, b| a[:code] <=> b[:code] }
|
50
|
-
|
50
|
+
if old_p_code != new_p_code
|
51
|
+
raise "Two different parcel_codes [#{old_p_code}, #{new_p_code}] for parcel_id:'#{parcel_id}'"
|
52
|
+
end
|
51
53
|
|
52
54
|
value
|
53
55
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'czech_post_b2b_client/services/orchestrator'
|
3
4
|
require 'czech_post_b2b_client/services/communicator'
|
4
5
|
require 'czech_post_b2b_client/services/api_caller'
|
5
6
|
require 'czech_post_b2b_client/services/parcels_sender'
|
7
|
+
require 'czech_post_b2b_client/services/parcels_immediate_sender'
|
6
8
|
require 'czech_post_b2b_client/services/parcels_send_process_updater'
|
7
9
|
require 'czech_post_b2b_client/services/address_sheets_generator'
|
8
10
|
require 'czech_post_b2b_client/services/parcels_submission_closer'
|
@@ -36,10 +36,10 @@ module CzechPostB2bClient
|
|
36
36
|
result_hash = {}
|
37
37
|
response_hash[:parcels].each_pair do |parcel_code, delivering_hash|
|
38
38
|
result_hash[parcel_code] = {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
deposited_until: delivering_hash[:deposited_until],
|
40
|
+
deposited_for_days: delivering_hash[:deposited_for_days],
|
41
|
+
current_state: delivering_hash[:states].last,
|
42
|
+
all_states: delivering_hash[:states]
|
43
43
|
}
|
44
44
|
end
|
45
45
|
puts("RESULT_HASH: #{result_hash}")
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CzechPostB2bClient
|
4
|
+
module Services
|
5
|
+
# Combination of ParcelsSender + ParcelsSendProcessUpdater for fast SYNC registering parcel at CPOST
|
6
|
+
# It accept all parcels or none!
|
7
|
+
# It should be used for instant one parcel registration.
|
8
|
+
class ParcelsImmediateSender < CzechPostB2bClient::Services::Communicator
|
9
|
+
attr_reader :sending_data, :parcels
|
10
|
+
|
11
|
+
def initialize(sending_data:, parcels:)
|
12
|
+
@sending_data = sending_data
|
13
|
+
@parcels = parcels
|
14
|
+
end
|
15
|
+
|
16
|
+
def steps
|
17
|
+
super + %i[check_for_state_errors]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request_builder_args
|
23
|
+
{ common_data: common_data, parcels: parcels }
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_builder_class
|
27
|
+
CzechPostB2bClient::RequestBuilders::SendParcelsBuilder
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_caller_class
|
31
|
+
CzechPostB2bClient::Services::ApiCaller
|
32
|
+
end
|
33
|
+
|
34
|
+
def response_parser_class
|
35
|
+
CzechPostB2bClient::ResponseParsers::GetResultParcelsParser
|
36
|
+
end
|
37
|
+
|
38
|
+
def common_data
|
39
|
+
data_from_config.merge(sending_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def data_from_config
|
43
|
+
{
|
44
|
+
contract_id: configuration.contract_id,
|
45
|
+
customer_id: configuration.customer_id,
|
46
|
+
sending_post_office_code: configuration.sending_post_office_code
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def endpoint_path
|
51
|
+
'/sendParcelsSync'
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_result_from(response_hash)
|
55
|
+
OpenStruct.new(parcels_hash: response_hash[:parcels],
|
56
|
+
state_text: response_hash.dig(:response, :state, :text),
|
57
|
+
state_code: response_hash.dig(:response, :state, :code))
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_for_state_errors
|
61
|
+
return if result.state_code == CzechPostB2bClient::ResponseCodes::Ok.code
|
62
|
+
|
63
|
+
r_code = CzechPostB2bClient::ResponseCodes.new_by_code(result.state_code)
|
64
|
+
errors.add(:response_state, r_code.to_s)
|
65
|
+
|
66
|
+
collect_parcel_errors
|
67
|
+
|
68
|
+
fail! unless r_code.info?
|
69
|
+
end
|
70
|
+
|
71
|
+
def collect_parcel_errors
|
72
|
+
result.parcels_hash.each_pair do |parcel_id, parcel_hash|
|
73
|
+
add_errors_for_failed_states(parcel_id, parcel_hash[:states])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_errors_for_failed_states(parcel_id, response_states)
|
78
|
+
response_states.each do |response_state|
|
79
|
+
response_code = response_state[:code]
|
80
|
+
next if response_code == CzechPostB2bClient::ResponseCodes::Ok.code
|
81
|
+
|
82
|
+
errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -61,7 +61,7 @@ module CzechPostB2bClient
|
|
61
61
|
def add_errors_for_failed_states(parcel_id, response_states)
|
62
62
|
response_states.each do |response_state|
|
63
63
|
response_code = response_state[:code]
|
64
|
-
next if
|
64
|
+
next if response_code == CzechPostB2bClient::ResponseCodes::Ok.code
|
65
65
|
|
66
66
|
errors.add(:parcels, "Parcel[#{parcel_id}] => #{CzechPostB2bClient::ResponseCodes.new_by_code(response_code)}")
|
67
67
|
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.0.
|
4
|
+
version: 1.0.2
|
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-
|
11
|
+
date: 2020-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -508,6 +508,7 @@ files:
|
|
508
508
|
- lib/czech_post_b2b_client.rb
|
509
509
|
- lib/czech_post_b2b_client/b2b_errors.rb
|
510
510
|
- lib/czech_post_b2b_client/configuration.rb
|
511
|
+
- lib/czech_post_b2b_client/post_services.rb
|
511
512
|
- lib/czech_post_b2b_client/printing_templates.rb
|
512
513
|
- lib/czech_post_b2b_client/request_builders.rb
|
513
514
|
- lib/czech_post_b2b_client/request_builders/base_builder.rb
|
@@ -530,6 +531,7 @@ files:
|
|
530
531
|
- lib/czech_post_b2b_client/services/communicator.rb
|
531
532
|
- lib/czech_post_b2b_client/services/delivering_inspector.rb
|
532
533
|
- lib/czech_post_b2b_client/services/orchestrator.rb
|
534
|
+
- lib/czech_post_b2b_client/services/parcels_immediate_sender.rb
|
533
535
|
- lib/czech_post_b2b_client/services/parcels_send_process_updater.rb
|
534
536
|
- lib/czech_post_b2b_client/services/parcels_sender.rb
|
535
537
|
- lib/czech_post_b2b_client/services/parcels_submission_closer.rb
|