colissimo_label 0.9.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +6 -0
- data/lib/colissimo_label/generate_label.rb +37 -12
- 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: 564e96baddfb8b526dabff4637e429276260607de36d8cedb9eba0481d06a2b6
|
4
|
+
data.tar.gz: d26257b2781922ee6b754a83891bbc3cfc20b601de30ee84f0ef188508cb57b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dc4e1d6b1f179db83e007d469863d353c98958946b2fd6724fcda899fa482933d5e611936220efa2d459acb4fb95a5d4fc7ac1b46e23634250c593a5fe59d91
|
7
|
+
data.tar.gz: 26f97fa5cec2b359d45c06c0350445766f76142eaf36f3a9bfea2c28cdc8697aa1a44dc1b62ab339eb0f3708300148501a806aabe18e07de1a89f3f78e5f5807
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.14.0
|
2
|
+
|
3
|
+
- Ensure local path is present
|
4
|
+
|
5
|
+
## 0.13.0
|
6
|
+
|
7
|
+
- Multiple improvements
|
8
|
+
|
9
|
+
## 0.12.0
|
10
|
+
|
11
|
+
- Add Austria to mandatory signature countries
|
12
|
+
|
13
|
+
## 0.11.0
|
14
|
+
|
15
|
+
- Add option to generate label with signature
|
16
|
+
|
17
|
+
## 0.10.0
|
18
|
+
|
19
|
+
- Add Denmark to mandatory signature countries
|
20
|
+
|
1
21
|
## 0.9.0
|
2
22
|
|
3
23
|
- Add Netherlands to mandatory signature countries
|
data/README.md
CHANGED
@@ -138,6 +138,12 @@ parcel_number = ColissimoLabel::GenerateLabel.new(
|
|
138
138
|
).perform
|
139
139
|
```
|
140
140
|
|
141
|
+
You can add the following option to require the signature:
|
142
|
+
|
143
|
+
```
|
144
|
+
with_signature: true
|
145
|
+
```
|
146
|
+
|
141
147
|
For a national address and delivered to a relay point:
|
142
148
|
|
143
149
|
```ruby
|
@@ -12,8 +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)
|
18
|
+
@with_signature = options.fetch(:with_signature, false)
|
19
|
+
@insurance_value = options.fetch(:insurance_value, false)
|
20
|
+
@label_output_format = options.fetch(:label_output_format, 'PDF_10x15_300dpi')
|
17
21
|
@errors = []
|
18
22
|
end
|
19
23
|
|
@@ -21,13 +25,14 @@ class ColissimoLabel::GenerateLabel
|
|
21
25
|
response = perform_request
|
22
26
|
status = response.code
|
23
27
|
parts = response.to_a.last.force_encoding('BINARY').split('Content-ID: ')
|
24
|
-
label_filename = @filename + '.
|
28
|
+
label_filename = @filename + '.' + file_format
|
29
|
+
local_path = ColissimoLabel.colissimo_local_path&.chomp('/')
|
25
30
|
|
26
31
|
if ColissimoLabel.s3_bucket
|
27
32
|
colissimo_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + label_filename)
|
28
33
|
colissimo_pdf.put(acl: 'public-read', body: parts[2])
|
29
34
|
else
|
30
|
-
File.open(
|
35
|
+
File.open(local_path + '/' + label_filename, 'wb') do |file|
|
31
36
|
file.write(parts[2])
|
32
37
|
end
|
33
38
|
end
|
@@ -39,7 +44,7 @@ class ColissimoLabel::GenerateLabel
|
|
39
44
|
customs_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + customs_filename)
|
40
45
|
customs_pdf.put(acl: 'public-read', body: parts[3])
|
41
46
|
else
|
42
|
-
File.open(
|
47
|
+
File.open(local_path + '/' + customs_filename, 'wb') do |file|
|
43
48
|
file.write(parts[3])
|
44
49
|
end
|
45
50
|
end
|
@@ -48,6 +53,8 @@ class ColissimoLabel::GenerateLabel
|
|
48
53
|
if status == 400
|
49
54
|
error_message = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"messageContent":"(.*?)"/).last&.first
|
50
55
|
raise StandardError, error_message
|
56
|
+
elsif status == 503
|
57
|
+
raise StandardError, { message: 'Colissimo: Service Unavailable' }
|
51
58
|
else
|
52
59
|
if (response_message = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"parcelNumber":"(.*?)",/).last)
|
53
60
|
parcel_number = response_message.first
|
@@ -70,7 +77,7 @@ class ColissimoLabel::GenerateLabel
|
|
70
77
|
"outputFormat": {
|
71
78
|
"x": '0',
|
72
79
|
"y": '0',
|
73
|
-
"outputPrintingType":
|
80
|
+
"outputPrintingType": @label_output_format
|
74
81
|
},
|
75
82
|
"letter": {
|
76
83
|
"service": {
|
@@ -82,7 +89,8 @@ class ColissimoLabel::GenerateLabel
|
|
82
89
|
},
|
83
90
|
"parcel": {
|
84
91
|
"weight": format_weight,
|
85
|
-
"pickupLocationId": @pickup_id
|
92
|
+
"pickupLocationId": @pickup_id,
|
93
|
+
"insuranceValue": @insurance_value
|
86
94
|
}.compact,
|
87
95
|
"sender": {
|
88
96
|
"address": format_sender
|
@@ -104,14 +112,29 @@ class ColissimoLabel::GenerateLabel
|
|
104
112
|
"https://ws.colissimo.fr/sls-ws/SlsServiceWSRest/2.0/#{service}"
|
105
113
|
end
|
106
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
|
+
|
107
128
|
def format_sender
|
108
129
|
{
|
109
130
|
"companyName": @sender_data[:company_name],
|
131
|
+
"lastName": @sender_data[:last_name],
|
132
|
+
"firstName": @sender_data[:first_name],
|
110
133
|
"line2": @sender_data[:address],
|
111
134
|
"city": @sender_data[:city],
|
112
135
|
"zipCode": @sender_data[:postcode],
|
113
136
|
"countryCode": @sender_data[:country_code]
|
114
|
-
}
|
137
|
+
}.compact.transform_values(&:strip)
|
115
138
|
end
|
116
139
|
|
117
140
|
def format_addressee
|
@@ -140,7 +163,7 @@ class ColissimoLabel::GenerateLabel
|
|
140
163
|
if require_customs?
|
141
164
|
@customs_total_weight
|
142
165
|
else
|
143
|
-
'0.1'
|
166
|
+
@total_weight ? @total_weight : '0.1'
|
144
167
|
end
|
145
168
|
end
|
146
169
|
|
@@ -154,9 +177,9 @@ class ColissimoLabel::GenerateLabel
|
|
154
177
|
"article": @customs_data.map { |customs|
|
155
178
|
{
|
156
179
|
"description": customs[:description],
|
157
|
-
"quantity": customs[:quantity],
|
158
|
-
"weight": customs[:weight],
|
159
|
-
"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),
|
160
183
|
"originCountry": customs[:country_code],
|
161
184
|
"currency": customs[:currency_code],
|
162
185
|
"hsCode": customs[:customs_code] # Objets d'art, de collection ou d'antiquité (https://pro.douane.gouv.fr/prodouane.asp)
|
@@ -181,7 +204,7 @@ class ColissimoLabel::GenerateLabel
|
|
181
204
|
end
|
182
205
|
|
183
206
|
def require_customs?
|
184
|
-
%w[CH].include?(@destination_country)
|
207
|
+
%w[CH NO US].include?(@destination_country)
|
185
208
|
end
|
186
209
|
|
187
210
|
# Certains pays, comme l'Allemagne, requiert une signature pour la livraison
|
@@ -191,10 +214,12 @@ class ColissimoLabel::GenerateLabel
|
|
191
214
|
# BPR : Colissimo - Point Retrait – en Bureau de Poste
|
192
215
|
# A2P : Colissimo - Point Retrait – en relais Pickup ou en consigne Pickup Station
|
193
216
|
def product_code
|
194
|
-
if %w[DE IT ES GB LU NL].include?(@destination_country)
|
217
|
+
if %w[DE IT ES GB LU NL DK AT].include?(@destination_country)
|
195
218
|
'DOS'
|
196
219
|
elsif !@pickup_id.nil? && %w[FR].include?(@destination_country)
|
197
220
|
@pickup_type || 'BPR'
|
221
|
+
elsif @with_signature
|
222
|
+
'DOS'
|
198
223
|
else
|
199
224
|
'DOM'
|
200
225
|
end
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FloXcoder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.
|
185
|
+
rubygems_version: 3.1.3
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Generate Colissimo label for all countries
|