belpost 0.7.0 → 0.11.0
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/CHANGELOG.md +49 -1
- data/README.md +48 -0
- data/belpost.gemspec +1 -0
- data/lib/belpost/api_paths.rb +27 -0
- data/lib/belpost/api_service.rb +1 -2
- data/lib/belpost/client.rb +128 -14
- data/lib/belpost/configuration.rb +3 -3
- data/lib/belpost/models/batch.rb +42 -0
- data/lib/belpost/models/batch_item.rb +22 -0
- data/lib/belpost/models/customs_declaration.rb +2 -3
- data/lib/belpost/models/parcel_builder.rb +5 -9
- data/lib/belpost/postal_delivery_types.rb +158 -0
- data/lib/belpost/validations/batch_item_schema.rb +163 -0
- data/lib/belpost/validations/batch_schema.rb +52 -0
- data/lib/belpost/validations/parcel_schema.rb +142 -124
- data/lib/belpost/validations/postcode_schema.rb +18 -0
- data/lib/belpost/version.rb +1 -1
- data/lib/belpost.rb +15 -4
- metadata +24 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry-validation"
|
|
4
|
+
|
|
5
|
+
module Belpost
|
|
6
|
+
module Validation
|
|
7
|
+
# Schema for validating batch item data
|
|
8
|
+
class BatchItemSchema < Dry::Validation::Contract
|
|
9
|
+
params do
|
|
10
|
+
required(:items).array(:hash) do
|
|
11
|
+
optional(:recipient_id).maybe(:integer)
|
|
12
|
+
optional(:recipient_foreign_id).maybe(:string)
|
|
13
|
+
optional(:recipient_object).maybe(:hash) do
|
|
14
|
+
optional(:foreign_id).maybe(:string)
|
|
15
|
+
required(:type).filled(:string, included_in?: %w[legal individual individual_entrepreneur])
|
|
16
|
+
|
|
17
|
+
optional(:first_name).maybe(:string)
|
|
18
|
+
optional(:last_name).maybe(:string)
|
|
19
|
+
optional(:second_name).maybe(:string)
|
|
20
|
+
|
|
21
|
+
optional(:company_name).maybe(:string)
|
|
22
|
+
|
|
23
|
+
required(:address).hash do
|
|
24
|
+
required(:address_type).filled(:string, included_in?: %w[address on_demand subscriber_box])
|
|
25
|
+
required(:postcode).filled(:string)
|
|
26
|
+
optional(:ops_id).maybe(:string)
|
|
27
|
+
required(:country_code).filled(:string)
|
|
28
|
+
optional(:region).maybe(:string)
|
|
29
|
+
optional(:district).maybe(:string)
|
|
30
|
+
required(:city).filled(:string)
|
|
31
|
+
optional(:building).maybe(:string)
|
|
32
|
+
optional(:housing).maybe(:string)
|
|
33
|
+
optional(:apartment).maybe(:string)
|
|
34
|
+
optional(:cell_number).maybe(:string)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
optional(:phone).maybe(:string)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
optional(:s10code).maybe(:string)
|
|
41
|
+
optional(:notification_s10code).maybe(:string)
|
|
42
|
+
required(:notification).filled(:integer, included_in?: [0, 1, 2, 5, 7])
|
|
43
|
+
required(:category).filled(:integer, included_in?: [0, 1, 2])
|
|
44
|
+
required(:weight).filled(:integer, gt?: 0)
|
|
45
|
+
|
|
46
|
+
optional(:addons).maybe(:hash) do
|
|
47
|
+
optional(:declared_value).maybe(:float, gt?: 0)
|
|
48
|
+
optional(:cash_on_delivery).maybe(:float, gt?: 0)
|
|
49
|
+
optional(:careful_fragile).maybe(:bool)
|
|
50
|
+
optional(:hand_over_personally).maybe(:bool)
|
|
51
|
+
optional(:subpoena).maybe(:bool)
|
|
52
|
+
optional(:description).maybe(:bool)
|
|
53
|
+
optional(:bulky).maybe(:bool)
|
|
54
|
+
optional(:recipient_payment).maybe(:bool)
|
|
55
|
+
optional(:documents_return).maybe(:bool)
|
|
56
|
+
optional(:deliver_to_work).maybe(:bool)
|
|
57
|
+
optional(:open_upon_delivery).maybe(:bool)
|
|
58
|
+
optional(:time_of_delivery).maybe(:hash) do
|
|
59
|
+
required(:type).filled(:string, included_in?: %w[level1 level2 level3 level4])
|
|
60
|
+
optional(:time_interval).hash do
|
|
61
|
+
required(:from).filled(:string)
|
|
62
|
+
required(:to).filled(:string)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
optional(:free_return).maybe(:bool)
|
|
66
|
+
optional(:partial_return).maybe(:bool)
|
|
67
|
+
optional(:government).maybe(:bool)
|
|
68
|
+
optional(:military).maybe(:bool)
|
|
69
|
+
optional(:service).maybe(:bool)
|
|
70
|
+
optional(:shelf_life).maybe(:integer, included_in?: (10..30))
|
|
71
|
+
optional(:email).maybe(:string)
|
|
72
|
+
optional(:phone).maybe(:string)
|
|
73
|
+
optional(:coordinate_delivery_interval).maybe(:bool)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
rule('items[].recipient_object.first_name') do
|
|
79
|
+
if key? && value.is_a?(Array)
|
|
80
|
+
value.each_with_index do |item, idx|
|
|
81
|
+
if item[:recipient_object] && item[:recipient_object][:type] == 'individual' && item[:recipient_object][:first_name].nil?
|
|
82
|
+
key(:"items.#{idx}.recipient_object.first_name").failure('must be filled for individual type')
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
rule('items[].recipient_object.last_name') do
|
|
89
|
+
if key? && value.is_a?(Array)
|
|
90
|
+
value.each_with_index do |item, idx|
|
|
91
|
+
if item[:recipient_object] && item[:recipient_object][:type] == 'individual' && item[:recipient_object][:last_name].nil?
|
|
92
|
+
key(:"items.#{idx}.recipient_object.last_name").failure('must be filled for individual type')
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
rule('items[].recipient_object.company_name') do
|
|
99
|
+
if key? && value.is_a?(Array)
|
|
100
|
+
value.each_with_index do |item, idx|
|
|
101
|
+
if item[:recipient_object] &&
|
|
102
|
+
(item[:recipient_object][:type] == 'legal' || item[:recipient_object][:type] == 'individual_entrepreneur') &&
|
|
103
|
+
item[:recipient_object][:company_name].nil?
|
|
104
|
+
key(:"items.#{idx}.recipient_object.company_name").failure('must be filled for legal or individual_entrepreneur type')
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
rule('items[].recipient_object.address.ops_id') do
|
|
111
|
+
if key? && value.is_a?(Array)
|
|
112
|
+
value.each_with_index do |item, idx|
|
|
113
|
+
if item[:recipient_object] &&
|
|
114
|
+
item[:recipient_object][:address] &&
|
|
115
|
+
item[:recipient_object][:address][:address_type] == 'address' &&
|
|
116
|
+
item[:recipient_object][:address][:ops_id].nil?
|
|
117
|
+
key(:"items.#{idx}.recipient_object.address.ops_id").failure('must be filled for address type')
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
rule('items[].recipient_object.address.cell_number') do
|
|
124
|
+
if key? && value.is_a?(Array)
|
|
125
|
+
value.each_with_index do |item, idx|
|
|
126
|
+
if item[:recipient_object] &&
|
|
127
|
+
item[:recipient_object][:address] &&
|
|
128
|
+
item[:recipient_object][:address][:address_type] == 'subscriber_box' &&
|
|
129
|
+
item[:recipient_object][:address][:cell_number].nil?
|
|
130
|
+
key(:"items.#{idx}.recipient_object.address.cell_number").failure('must be filled for subscriber_box type')
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
rule('items[].recipient_object') do
|
|
137
|
+
if key? && value.is_a?(Array)
|
|
138
|
+
value.each_with_index do |item, idx|
|
|
139
|
+
if item[:recipient_id].nil? && item[:recipient_foreign_id].nil? && item[:recipient_object].nil?
|
|
140
|
+
key(:"items.#{idx}.recipient_object").failure('must be provided if recipient_id and recipient_foreign_id are null')
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Add validation to ensure e-commerce has the proper notifications
|
|
147
|
+
rule('items[].notification') do
|
|
148
|
+
if key? && value.is_a?(Array)
|
|
149
|
+
value.each_with_index do |item, idx|
|
|
150
|
+
if item[:notification] == 5 && (!item[:addons] || !item[:addons][:email])
|
|
151
|
+
key(:"items.#{idx}.addons.email").failure('email is required for electronic notification (5)')
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Add class method to make it callable directly
|
|
158
|
+
def self.call(params)
|
|
159
|
+
new.call(params)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry-validation"
|
|
4
|
+
|
|
5
|
+
module Belpost
|
|
6
|
+
module Validation
|
|
7
|
+
# Schema for validating batch mailing data
|
|
8
|
+
class BatchSchema < Dry::Validation::Contract
|
|
9
|
+
params do
|
|
10
|
+
required(:postal_delivery_type).filled(:str?).value(
|
|
11
|
+
included_in?: Belpost::PostalDeliveryTypes.all.map(&:to_s)
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
required(:direction).filled(:str?).value(
|
|
15
|
+
included_in?: %w[internal CIS international]
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
required(:payment_type).filled(:str?).value(
|
|
19
|
+
included_in?: %w[
|
|
20
|
+
not_specified
|
|
21
|
+
cash
|
|
22
|
+
payment_order
|
|
23
|
+
electronic_personal_account
|
|
24
|
+
4
|
|
25
|
+
5
|
|
26
|
+
commitment_letter
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
required(:negotiated_rate).filled(:bool?)
|
|
31
|
+
|
|
32
|
+
optional(:name).maybe(:str?)
|
|
33
|
+
optional(:card_number).maybe(:str?)
|
|
34
|
+
optional(:postal_items_in_ops).maybe(:bool?)
|
|
35
|
+
optional(:category).maybe(:int?)
|
|
36
|
+
optional(:is_document).maybe(:bool?)
|
|
37
|
+
optional(:is_declared_value).maybe(:bool?)
|
|
38
|
+
optional(:is_partial_receipt).maybe(:bool?)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
rule(:postal_delivery_type) do
|
|
42
|
+
if key? && value
|
|
43
|
+
errors = Belpost::PostalDeliveryTypes.validate_params(
|
|
44
|
+
value,
|
|
45
|
+
values
|
|
46
|
+
)
|
|
47
|
+
errors.each { |error| key.failure(error) }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -1,154 +1,172 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "dry
|
|
3
|
+
require "dry-validation"
|
|
4
4
|
|
|
5
5
|
module Belpost
|
|
6
6
|
# rubocop:disable Metrics/ModuleLength
|
|
7
7
|
module Validation
|
|
8
8
|
# Validation schema for parcel_data
|
|
9
9
|
# rubocop:disable Metrics/BlockLength
|
|
10
|
-
ParcelSchema
|
|
11
|
-
|
|
12
|
-
required(:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
required(:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
required(:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
required(:
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
class ParcelSchema < Dry::Validation::Contract
|
|
11
|
+
params do
|
|
12
|
+
required(:parcel).hash do
|
|
13
|
+
required(:type).filled(:string, included_in?: %w[package small_package small_valued_package ems])
|
|
14
|
+
required(:attachment_type).filled(:string, included_in?: %w[products documents])
|
|
15
|
+
required(:measures).hash do
|
|
16
|
+
required(:weight).filled(:integer, gt?: 0)
|
|
17
|
+
optional(:long).value(:integer, gt?: 0)
|
|
18
|
+
optional(:width).value(:integer, gt?: 0)
|
|
19
|
+
optional(:height).value(:integer, gt?: 0)
|
|
20
|
+
end
|
|
21
|
+
required(:departure).hash do
|
|
22
|
+
required(:country).filled(:string, eql?: "BY")
|
|
23
|
+
required(:place).filled(:string, included_in?: %w[post_office])
|
|
24
|
+
optional(:place_uuid).maybe(:string)
|
|
25
|
+
end
|
|
26
|
+
required(:arrival).hash do
|
|
27
|
+
required(:country).filled(:string)
|
|
28
|
+
required(:place).filled(:string, included_in?: %w[post_office])
|
|
29
|
+
optional(:place_uuid).maybe(:string)
|
|
30
|
+
end
|
|
31
|
+
optional(:s10code).maybe(:string)
|
|
29
32
|
end
|
|
30
|
-
optional(:s10code).maybe(:string)
|
|
31
|
-
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
34
|
+
optional(:addons).hash do
|
|
35
|
+
optional(:cash_on_delivery).maybe(:hash) do
|
|
36
|
+
required(:currency).filled(:string, eql?: "BYN")
|
|
37
|
+
required(:value).filled(:float, gt?: 0)
|
|
38
|
+
end
|
|
39
|
+
optional(:declared_value).maybe(:hash) do
|
|
40
|
+
required(:currency).filled(:string, eql?: "BYN")
|
|
41
|
+
required(:value).filled(:float, gt?: 0)
|
|
42
|
+
end
|
|
43
|
+
optional(:IOSS).maybe(:string)
|
|
44
|
+
optional(:registered_notification).maybe(:string)
|
|
45
|
+
optional(:simple_notification).maybe(:bool)
|
|
46
|
+
optional(:sms_notification).maybe(:bool)
|
|
47
|
+
optional(:email_notification).maybe(:bool)
|
|
48
|
+
optional(:priority_parcel).maybe(:bool)
|
|
49
|
+
optional(:attachment_inventory).maybe(:bool)
|
|
50
|
+
optional(:paid_shipping).maybe(:bool)
|
|
51
|
+
optional(:careful_fragile).maybe(:bool)
|
|
52
|
+
optional(:bulky).maybe(:bool)
|
|
53
|
+
optional(:ponderous).maybe(:bool)
|
|
54
|
+
optional(:payment_upon_receipt).maybe(:bool)
|
|
55
|
+
optional(:hand_over_personally).maybe(:bool)
|
|
56
|
+
optional(:return_of_documents).maybe(:bool)
|
|
57
|
+
optional(:open_upon_delivery).maybe(:bool)
|
|
58
|
+
optional(:delivery_to_work).maybe(:bool)
|
|
59
|
+
optional(:time_of_delivery).maybe(:hash) do
|
|
60
|
+
required(:type).filled(:string, included_in?: %w[level1 level2 level3 level4])
|
|
61
|
+
optional(:time_interval).hash do
|
|
62
|
+
required(:from).filled(:string)
|
|
63
|
+
required(:to).filled(:string)
|
|
64
|
+
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
|
-
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
required(:region).filled(:string)
|
|
79
|
-
required(:district).filled(:string)
|
|
80
|
-
required(:locality).hash do
|
|
81
|
-
required(:type).filled(:string)
|
|
82
|
-
required(:name).filled(:string)
|
|
68
|
+
optional(:sender).hash do
|
|
69
|
+
required(:type).filled(:string, included_in?: %w[legal_person natural_person])
|
|
70
|
+
required(:info).hash do
|
|
71
|
+
optional(:organization_name).maybe(:string)
|
|
72
|
+
optional(:taxpayer_number).maybe(:string)
|
|
73
|
+
optional(:IBAN).maybe(:string)
|
|
74
|
+
optional(:BIC).maybe(:string)
|
|
75
|
+
optional(:bank).maybe(:string)
|
|
76
|
+
optional(:first_name).maybe(:string)
|
|
77
|
+
optional(:second_name).maybe(:string)
|
|
78
|
+
optional(:last_name).maybe(:string)
|
|
83
79
|
end
|
|
84
|
-
required(:
|
|
85
|
-
required(:
|
|
86
|
-
required(:
|
|
80
|
+
required(:location).hash do
|
|
81
|
+
required(:code).filled(:string)
|
|
82
|
+
required(:region).filled(:string)
|
|
83
|
+
required(:district).filled(:string)
|
|
84
|
+
required(:locality).hash do
|
|
85
|
+
required(:type).filled(:string)
|
|
86
|
+
required(:name).filled(:string)
|
|
87
|
+
end
|
|
88
|
+
required(:road).hash do
|
|
89
|
+
required(:type).filled(:string)
|
|
90
|
+
required(:name).filled(:string)
|
|
91
|
+
end
|
|
92
|
+
required(:building).filled(:string)
|
|
93
|
+
optional(:housing).maybe(:string)
|
|
94
|
+
optional(:apartment).maybe(:string)
|
|
87
95
|
end
|
|
88
|
-
|
|
89
|
-
optional(:
|
|
90
|
-
optional(:apartment).maybe(:string)
|
|
96
|
+
optional(:email).maybe(:string)
|
|
97
|
+
optional(:phone).maybe(:string)
|
|
91
98
|
end
|
|
92
|
-
required(:email).filled(:string)
|
|
93
|
-
required(:phone).filled(:string)
|
|
94
|
-
end
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
optional(:district).maybe(:string)
|
|
108
|
-
optional(:locality).maybe(:hash) do
|
|
109
|
-
optional(:type).maybe(:string)
|
|
110
|
-
optional(:name).maybe(:string)
|
|
100
|
+
optional(:recipient).hash do
|
|
101
|
+
required(:type).filled(:string, included_in?: %w[legal_person natural_person])
|
|
102
|
+
required(:info).hash do
|
|
103
|
+
optional(:organization_name).maybe(:string)
|
|
104
|
+
optional(:taxpayer_number).maybe(:string)
|
|
105
|
+
optional(:IBAN).maybe(:string)
|
|
106
|
+
optional(:BIC).maybe(:string)
|
|
107
|
+
optional(:bank).maybe(:string)
|
|
108
|
+
optional(:first_name).maybe(:string)
|
|
109
|
+
optional(:second_name).maybe(:string)
|
|
110
|
+
optional(:last_name).maybe(:string)
|
|
111
111
|
end
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
required(:location).hash do
|
|
113
|
+
required(:code).filled(:string)
|
|
114
|
+
required(:region).filled(:string)
|
|
115
|
+
required(:district).filled(:string)
|
|
116
|
+
required(:locality).hash do
|
|
117
|
+
required(:type).filled(:string)
|
|
118
|
+
required(:name).filled(:string)
|
|
119
|
+
end
|
|
120
|
+
required(:road).hash do
|
|
121
|
+
required(:type).filled(:string)
|
|
122
|
+
required(:name).filled(:string)
|
|
123
|
+
end
|
|
124
|
+
required(:building).filled(:string)
|
|
125
|
+
optional(:housing).maybe(:string)
|
|
126
|
+
optional(:apartment).maybe(:string)
|
|
115
127
|
end
|
|
116
|
-
optional(:
|
|
117
|
-
optional(:
|
|
118
|
-
optional(:apartment).maybe(:string)
|
|
119
|
-
optional(:address).maybe(:string)
|
|
128
|
+
optional(:email).maybe(:string)
|
|
129
|
+
optional(:phone).maybe(:string)
|
|
120
130
|
end
|
|
121
|
-
optional(:email).maybe(:string)
|
|
122
|
-
required(:phone).filled(:string)
|
|
123
|
-
end
|
|
124
131
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
required(:local).filled(:string)
|
|
129
|
-
required(:unit).hash do
|
|
132
|
+
optional(:cp72).hash do
|
|
133
|
+
optional(:items).array(:hash) do
|
|
134
|
+
required(:name).filled(:string)
|
|
130
135
|
required(:local).filled(:string)
|
|
131
|
-
required(:
|
|
136
|
+
required(:unit).hash do
|
|
137
|
+
required(:local).filled(:string)
|
|
138
|
+
required(:en).filled(:string)
|
|
139
|
+
end
|
|
140
|
+
required(:count).filled(:integer, gt?: 0)
|
|
141
|
+
required(:weight).filled(:integer, gt?: 0)
|
|
142
|
+
required(:price).hash do
|
|
143
|
+
required(:currency).filled(:string)
|
|
144
|
+
required(:value).filled(:float, gt?: 0)
|
|
145
|
+
end
|
|
146
|
+
optional(:code).maybe(:string)
|
|
147
|
+
optional(:country).maybe(:string)
|
|
132
148
|
end
|
|
133
|
-
|
|
134
|
-
required(:weight).filled(:integer, gt?: 0)
|
|
135
|
-
required(:price).hash do
|
|
149
|
+
optional(:price).hash do
|
|
136
150
|
required(:currency).filled(:string)
|
|
137
151
|
required(:value).filled(:float, gt?: 0)
|
|
138
152
|
end
|
|
139
|
-
optional(:
|
|
140
|
-
optional(:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
optional(:category).filled(:string, included_in?: %w[gift documents sample returned_goods merchandise other])
|
|
154
|
+
optional(:explanation).maybe(:string)
|
|
155
|
+
optional(:comments).maybe(:string)
|
|
156
|
+
optional(:invoice).maybe(:string)
|
|
157
|
+
optional(:licences).array(:string)
|
|
158
|
+
optional(:certificates).array(:string)
|
|
145
159
|
end
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Add class method to make it compatible with the tests
|
|
163
|
+
def self.call(params)
|
|
164
|
+
new.call(params)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Add validation rule for organization_name when sender type is legal_person
|
|
168
|
+
rule('sender.info.organization_name') do
|
|
169
|
+
key.failure('must be filled') if values[:sender] && values[:sender][:type] == 'legal_person' && !values.dig(:sender, :info, :organization_name)
|
|
152
170
|
end
|
|
153
171
|
end
|
|
154
172
|
# rubocop:enable Metrics/BlockLength
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry-validation"
|
|
4
|
+
|
|
5
|
+
module Belpost
|
|
6
|
+
module Validation
|
|
7
|
+
# Schema for validating postcode parameters
|
|
8
|
+
class PostcodeSchema < Dry::Validation::Contract
|
|
9
|
+
params do
|
|
10
|
+
required(:postcode).filled(:string)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
rule(:postcode) do
|
|
14
|
+
key.failure("must be 6 digits") unless value.match?(/^\d{6}$/)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/belpost/version.rb
CHANGED
data/lib/belpost.rb
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "dotenv/load"
|
|
4
|
-
|
|
5
3
|
require_relative "belpost/version"
|
|
6
4
|
require_relative "belpost/configuration"
|
|
7
|
-
require_relative "belpost/client"
|
|
8
5
|
require_relative "belpost/errors"
|
|
9
6
|
require_relative "belpost/retry"
|
|
10
|
-
require_relative "belpost/
|
|
7
|
+
require_relative "belpost/api_paths"
|
|
8
|
+
require_relative "belpost/api_service"
|
|
9
|
+
|
|
10
|
+
# Load models
|
|
11
11
|
require_relative "belpost/models/api_response"
|
|
12
|
+
require_relative "belpost/models/batch"
|
|
12
13
|
require_relative "belpost/models/customs_declaration"
|
|
14
|
+
require_relative "belpost/models/parcel"
|
|
13
15
|
require_relative "belpost/models/parcel_builder"
|
|
16
|
+
|
|
17
|
+
# Load types and validations
|
|
18
|
+
require_relative "belpost/postal_delivery_types"
|
|
19
|
+
require_relative "belpost/validations/batch_schema"
|
|
14
20
|
require_relative "belpost/validations/parcel_schema"
|
|
21
|
+
require_relative "belpost/validations/address_schema"
|
|
22
|
+
require_relative "belpost/validations/postcode_schema"
|
|
23
|
+
|
|
24
|
+
# Load client last as it depends on other files
|
|
25
|
+
require_relative "belpost/client"
|
|
15
26
|
|
|
16
27
|
# Module for working with Belpochta API.
|
|
17
28
|
# Provides an interface for configuring and interacting with the API.
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: belpost
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- KuberLite
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: dotenv
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: dry-schema
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: dry-validation
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -55,17 +69,24 @@ files:
|
|
|
55
69
|
- Rakefile
|
|
56
70
|
- belpost.gemspec
|
|
57
71
|
- lib/belpost.rb
|
|
72
|
+
- lib/belpost/api_paths.rb
|
|
58
73
|
- lib/belpost/api_service.rb
|
|
59
74
|
- lib/belpost/client.rb
|
|
60
75
|
- lib/belpost/configuration.rb
|
|
61
76
|
- lib/belpost/errors.rb
|
|
62
77
|
- lib/belpost/models/api_response.rb
|
|
78
|
+
- lib/belpost/models/batch.rb
|
|
79
|
+
- lib/belpost/models/batch_item.rb
|
|
63
80
|
- lib/belpost/models/customs_declaration.rb
|
|
64
81
|
- lib/belpost/models/parcel.rb
|
|
65
82
|
- lib/belpost/models/parcel_builder.rb
|
|
83
|
+
- lib/belpost/postal_delivery_types.rb
|
|
66
84
|
- lib/belpost/retry.rb
|
|
67
85
|
- lib/belpost/validations/address_schema.rb
|
|
86
|
+
- lib/belpost/validations/batch_item_schema.rb
|
|
87
|
+
- lib/belpost/validations/batch_schema.rb
|
|
68
88
|
- lib/belpost/validations/parcel_schema.rb
|
|
89
|
+
- lib/belpost/validations/postcode_schema.rb
|
|
69
90
|
- lib/belpost/version.rb
|
|
70
91
|
homepage: https://github.com/KuberLite/belpost
|
|
71
92
|
licenses:
|
|
@@ -90,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
111
|
- !ruby/object:Gem::Version
|
|
91
112
|
version: '0'
|
|
92
113
|
requirements: []
|
|
93
|
-
rubygems_version: 3.6.
|
|
114
|
+
rubygems_version: 3.6.7
|
|
94
115
|
specification_version: 4
|
|
95
116
|
summary: Belpost API wrapper
|
|
96
117
|
test_files: []
|