colissimo_label 0.11.0 → 0.16.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 +20 -0
- data/lib/colissimo_label/generate_label.rb +35 -13
- data/lib/colissimo_label/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c66bd1f3e7fd14f452e096ec6dfdfe3f8818939a43b577c899a011c12bdf6b8b
|
4
|
+
data.tar.gz: 37708156fdaecc9ffe79f3aa991a75ab3d688cfb8c692048e9944966d94b9112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4239b31017b0deba9d4ad955f3fb7b42c2a01dbaaf592335f525e457059cd85b8ff4e1729712a2680e0bcabf260409a00291c9b581ac18b9ab67d792598f21b
|
7
|
+
data.tar.gz: '08f1e4e868e6f238b25b3cf60da9b7aa027eb2a38b61d7b51a7750cbff7721a27441e5657442bec3cbec25528b3a83eafb035689dbe980ba3795de11b40bcd90'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.16.0
|
2
|
+
|
3
|
+
- Use correct default value for insurance
|
4
|
+
|
5
|
+
## 0.15.0
|
6
|
+
|
7
|
+
- Comment insurance value
|
8
|
+
|
9
|
+
## 0.14.0
|
10
|
+
|
11
|
+
- Ensure local path is present
|
12
|
+
|
13
|
+
## 0.13.0
|
14
|
+
|
15
|
+
- Multiple improvements
|
16
|
+
|
17
|
+
## 0.12.0
|
18
|
+
|
19
|
+
- Add Austria to mandatory signature countries
|
20
|
+
|
1
21
|
## 0.11.0
|
2
22
|
|
3
23
|
- Add option to generate label with signature
|
@@ -12,9 +12,12 @@ class ColissimoLabel::GenerateLabel
|
|
12
12
|
@addressee_data = addressee_data
|
13
13
|
@pickup_id = options.fetch(:pickup_id, nil)
|
14
14
|
@pickup_type = options.fetch(:pickup_type, nil)
|
15
|
+
@total_weight = options.fetch(:total_weight, nil)
|
15
16
|
@customs_total_weight = options.fetch(:customs_total_weight, nil)
|
16
17
|
@customs_data = options.fetch(:customs_data, nil)
|
17
18
|
@with_signature = options.fetch(:with_signature, false)
|
19
|
+
@insurance_value = options.fetch(:insurance_value, nil)
|
20
|
+
@label_output_format = options.fetch(:label_output_format, 'PDF_10x15_300dpi')
|
18
21
|
@errors = []
|
19
22
|
end
|
20
23
|
|
@@ -22,13 +25,14 @@ class ColissimoLabel::GenerateLabel
|
|
22
25
|
response = perform_request
|
23
26
|
status = response.code
|
24
27
|
parts = response.to_a.last.force_encoding('BINARY').split('Content-ID: ')
|
25
|
-
label_filename = @filename + '.
|
28
|
+
label_filename = @filename + '.' + file_format
|
29
|
+
local_path = ColissimoLabel.colissimo_local_path&.chomp('/')
|
26
30
|
|
27
31
|
if ColissimoLabel.s3_bucket
|
28
32
|
colissimo_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + label_filename)
|
29
33
|
colissimo_pdf.put(acl: 'public-read', body: parts[2])
|
30
34
|
else
|
31
|
-
File.open(
|
35
|
+
File.open(local_path + '/' + label_filename, 'wb') do |file|
|
32
36
|
file.write(parts[2])
|
33
37
|
end
|
34
38
|
end
|
@@ -40,15 +44,17 @@ class ColissimoLabel::GenerateLabel
|
|
40
44
|
customs_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + customs_filename)
|
41
45
|
customs_pdf.put(acl: 'public-read', body: parts[3])
|
42
46
|
else
|
43
|
-
File.open(
|
47
|
+
File.open(local_path + '/' + customs_filename, 'wb') do |file|
|
44
48
|
file.write(parts[3])
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
49
|
-
if status == 400
|
53
|
+
if status == 400 || status == 500
|
50
54
|
error_message = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"messageContent":"(.*?)"/).last&.first
|
51
55
|
raise StandardError, error_message
|
56
|
+
elsif status == 503
|
57
|
+
raise StandardError, { message: 'Colissimo: Service Unavailable' }
|
52
58
|
else
|
53
59
|
if (response_message = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"parcelNumber":"(.*?)",/).last)
|
54
60
|
parcel_number = response_message.first
|
@@ -71,7 +77,7 @@ class ColissimoLabel::GenerateLabel
|
|
71
77
|
"outputFormat": {
|
72
78
|
"x": '0',
|
73
79
|
"y": '0',
|
74
|
-
"outputPrintingType":
|
80
|
+
"outputPrintingType": @label_output_format
|
75
81
|
},
|
76
82
|
"letter": {
|
77
83
|
"service": {
|
@@ -83,7 +89,8 @@ class ColissimoLabel::GenerateLabel
|
|
83
89
|
},
|
84
90
|
"parcel": {
|
85
91
|
"weight": format_weight,
|
86
|
-
"pickupLocationId": @pickup_id
|
92
|
+
"pickupLocationId": @pickup_id,
|
93
|
+
"insuranceValue": @insurance_value
|
87
94
|
}.compact,
|
88
95
|
"sender": {
|
89
96
|
"address": format_sender
|
@@ -105,14 +112,29 @@ class ColissimoLabel::GenerateLabel
|
|
105
112
|
"https://ws.colissimo.fr/sls-ws/SlsServiceWSRest/2.0/#{service}"
|
106
113
|
end
|
107
114
|
|
115
|
+
def file_format
|
116
|
+
case @label_output_format
|
117
|
+
when 'PDF_A4_300dpi', 'PDF_10x15_300dpi'
|
118
|
+
'pdf'
|
119
|
+
when 'ZPL_10x15_300dpi', 'ZPL_10x15_203dpi'
|
120
|
+
'zpl'
|
121
|
+
when 'DPL_10x15_300dpi', 'DPL_10x15_203dpi'
|
122
|
+
'dpl'
|
123
|
+
else
|
124
|
+
'pdf'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
108
128
|
def format_sender
|
109
129
|
{
|
110
130
|
"companyName": @sender_data[:company_name],
|
131
|
+
"lastName": @sender_data[:last_name],
|
132
|
+
"firstName": @sender_data[:first_name],
|
111
133
|
"line2": @sender_data[:address],
|
112
134
|
"city": @sender_data[:city],
|
113
135
|
"zipCode": @sender_data[:postcode],
|
114
136
|
"countryCode": @sender_data[:country_code]
|
115
|
-
}
|
137
|
+
}.compact.transform_values(&:strip)
|
116
138
|
end
|
117
139
|
|
118
140
|
def format_addressee
|
@@ -141,7 +163,7 @@ class ColissimoLabel::GenerateLabel
|
|
141
163
|
if require_customs?
|
142
164
|
@customs_total_weight
|
143
165
|
else
|
144
|
-
'0.1'
|
166
|
+
@total_weight ? @total_weight : '0.1'
|
145
167
|
end
|
146
168
|
end
|
147
169
|
|
@@ -155,9 +177,9 @@ class ColissimoLabel::GenerateLabel
|
|
155
177
|
"article": @customs_data.map { |customs|
|
156
178
|
{
|
157
179
|
"description": customs[:description],
|
158
|
-
"quantity": customs[:quantity],
|
159
|
-
"weight": customs[:weight],
|
160
|
-
"value": customs[:item_price],
|
180
|
+
"quantity": customs[:quantity]&.to_i,
|
181
|
+
"weight": customs[:weight]&.to_f.round(2),
|
182
|
+
"value": customs[:item_price]&.to_f.round(2),
|
161
183
|
"originCountry": customs[:country_code],
|
162
184
|
"currency": customs[:currency_code],
|
163
185
|
"hsCode": customs[:customs_code] # Objets d'art, de collection ou d'antiquité (https://pro.douane.gouv.fr/prodouane.asp)
|
@@ -182,7 +204,7 @@ class ColissimoLabel::GenerateLabel
|
|
182
204
|
end
|
183
205
|
|
184
206
|
def require_customs?
|
185
|
-
%w[CH].include?(@destination_country)
|
207
|
+
%w[CH NO US].include?(@destination_country)
|
186
208
|
end
|
187
209
|
|
188
210
|
# Certains pays, comme l'Allemagne, requiert une signature pour la livraison
|
@@ -192,7 +214,7 @@ class ColissimoLabel::GenerateLabel
|
|
192
214
|
# BPR : Colissimo - Point Retrait – en Bureau de Poste
|
193
215
|
# A2P : Colissimo - Point Retrait – en relais Pickup ou en consigne Pickup Station
|
194
216
|
def product_code
|
195
|
-
if %w[DE IT ES GB LU NL DK].include?(@destination_country)
|
217
|
+
if %w[DE IT ES GB LU NL DK AT].include?(@destination_country)
|
196
218
|
'DOS'
|
197
219
|
elsif !@pickup_id.nil? && %w[FR].include?(@destination_country)
|
198
220
|
@pickup_type || 'BPR'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colissimo_label
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FloXcoder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
|
-
rubygems_version: 3.1.
|
185
|
+
rubygems_version: 3.1.3
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Generate Colissimo label for all countries
|