colissimo_label 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b20cf6d60590b5b229d08dca579e8526540718702f0818282369af8de9568d7
4
- data.tar.gz: 6138fdc5edc70493a52af72104ce6df8a5b8f6f060779d5eb3baf63821bae8ae
3
+ metadata.gz: b85e62f1503ab7a596c1f5fadb2f0a9e1ea0d94bc34e61c027961aeb9f2d5dd9
4
+ data.tar.gz: b9d1cc9d6c14b846b61f33804093e50b759322d07af2fdc49aa0dda7c3c8063f
5
5
  SHA512:
6
- metadata.gz: a4eb97e5a3e6d55a8fe22895bfb31b6cd7a5d5df0f7c6b21ee8edf40ed5b1e655c1aef84dd2d9017474ae240d51c96d49f46e4cdfef3dca7c8a3d505472b1bb0
7
- data.tar.gz: 2b68731fb099899fe85e593dcfc6412e857cc02eb5cd28fec1d838681e11cc1adfb67a12dbe1a5481877f96908f1f01122228a3a7d683096a0237ddf723be6a4
6
+ metadata.gz: b0282ebd5555cf445a89cdac2d320dc610ab4fa1d599bca81e305af3b68540c39fa0a41ae5dd18ceb89aa6ebf9ec36f6ac9c614089131ed893fabae0ab1aa2ea
7
+ data.tar.gz: 93167be7de54a135e7c15106c4e17aa7cba5e67932ee09a724db2bcc4c36fee7c529836d668bccf06949868d2daaa399746ae8945880a4cc29c67e96dd94e4e4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.0
2
+
3
+ - Add option to generate label with a pickup location id
4
+
1
5
  ## 0.4.0
2
6
 
3
7
  - Add `ColissimoLabel::FindRelayPoint` class to fetch available relay points around an address
data/README.md CHANGED
@@ -79,7 +79,7 @@ To get all available relay :
79
79
 
80
80
  It will return an array of relay points with the following data:
81
81
 
82
- ```ruby
82
+ ```
83
83
  {
84
84
  :pickup_id,
85
85
  :name,
@@ -138,6 +138,37 @@ parcel_number = ColissimoLabel::GenerateLabel.new(
138
138
  ).perform
139
139
  ```
140
140
 
141
+ For a national address and delivered to a relay point:
142
+
143
+ ```ruby
144
+ parcel_number = ColissimoLabel::GenerateLabel.new(
145
+ 'label_filename', # Name of the file generated
146
+ 'FR', # Normalized country code of the destination
147
+ 9.99, # Amount of the shipping fees (paid by the customer)
148
+ {
149
+ company_name: 'Sender company name',
150
+ address: 'Address',
151
+ city: 'City',
152
+ postcode: 'Postcode',
153
+ country_code: 'Normalized country code (ex: FR)'
154
+ },
155
+ {
156
+ last_name: 'Last name of the addressee',
157
+ first_name: 'First name of the addressee',
158
+ address_bis: 'Address bis of the addressee',
159
+ address: 'Address of the addressee',
160
+ city: 'City of the addressee',
161
+ postcode: 'Postcode of the addressee',
162
+ country_code: 'Normalized country code of the addressee',
163
+ phone: 'Phone number of the addressee',
164
+ mobile: 'Mobile number of the addressee',
165
+ email: 'Email of the addressee'
166
+ },
167
+ pickup_id: 'pickup ID',
168
+ pickup_type: 'BPR or A2P'
169
+ ).perform
170
+ ```
171
+
141
172
  For a foreign address (which required customs declaration):
142
173
 
143
174
  ```ruby
@@ -164,8 +195,8 @@ parcel_number = ColissimoLabel::GenerateLabel.new(
164
195
  mobile: 'Mobile number of the addressee',
165
196
  email: 'Email of the addressee'
166
197
  },
167
- 2, # Total weight of the package
168
- [ # Details content of your package
198
+ customs_total_weight: 2, # Total weight of the package
199
+ customs_data: [ # Details content of your package
169
200
  {
170
201
  description: 'Product description',
171
202
  quantity: 1,
@@ -28,6 +28,8 @@ class ColissimoLabel::FindRelayPoint
28
28
  root.xpath('//listePointRetraitAcheminement').map do |point|
29
29
  {
30
30
  pickup_id: point.at_xpath('identifiant').text,
31
+ pickup_type: point.at_xpath('typeDePoint
32
+ ').text,
31
33
  name: point.at_xpath('nom').text,
32
34
  address: [point.at_xpath('adresse1'), point.at_xpath('adresse2'), point.at_xpath('adresse3')].map(&:text).select(&:present?).join(' '),
33
35
  postcode: point.at_xpath('codePostal').text,
@@ -4,14 +4,16 @@ require 'http'
4
4
 
5
5
  class ColissimoLabel::GenerateLabel
6
6
 
7
- def initialize(filename, destination_country, shipping_fees, sender_data, addressee_data, customs_total_weight = nil, customs_data = nil)
7
+ def initialize(filename, destination_country, shipping_fees, sender_data, addressee_data, options = {})
8
8
  @filename = filename
9
9
  @destination_country = destination_country
10
10
  @shipping_fees = shipping_fees
11
11
  @sender_data = sender_data
12
12
  @addressee_data = addressee_data
13
- @customs_total_weight = customs_total_weight
14
- @customs_data = customs_data
13
+ @pickup_id = options.fetch(:pickup_id, nil)
14
+ @pickup_type = options.fetch(:pickup_type, nil)
15
+ @customs_total_weight = options.fetch(:customs_total_weight, nil)
16
+ @customs_data = options.fetch(:customs_data, nil)
15
17
  @errors = []
16
18
  end
17
19
 
@@ -67,14 +69,16 @@ class ColissimoLabel::GenerateLabel
67
69
  },
68
70
  "letter": {
69
71
  "service": {
70
- "productCode": product_code,
71
- "depositDate": delivery_date.strftime('%F'),
72
- "totalAmount": (@shipping_fees * 100).to_i,
72
+ "commercialName": @sender_data[:company_name],
73
+ "productCode": product_code,
74
+ "depositDate": delivery_date.strftime('%F'),
75
+ "totalAmount": (@shipping_fees * 100).to_i,
73
76
  # "returnTypeChoice": '2' # Retour à la maison en prioritaire
74
77
  },
75
78
  "parcel": {
76
- "weight": format_weight
77
- },
79
+ "weight": format_weight,
80
+ "pickupLocationId": @pickup_id
81
+ }.compact,
78
82
  "sender": {
79
83
  "address": format_sender
80
84
  },
@@ -118,7 +122,7 @@ class ColissimoLabel::GenerateLabel
118
122
  "city": @addressee_data[:city], # Ville
119
123
  "zipCode": @addressee_data[:postcode], # Code postal
120
124
  "phoneNumber": @addressee_data[:phone], # Numéro de téléphone
121
- "mobileNumber": @addressee_data[:mobile], # Numéro de portable
125
+ "mobileNumber": @addressee_data[:mobile], # Numéro de portable, obligatoire si pickup
122
126
  "doorCode1": @addressee_data[:door_code_1], # Code porte 1
123
127
  "doorCode2": @addressee_data[:door_code_2], # Code porte 2
124
128
  "email": @addressee_data[:email], # Adresse courriel
@@ -175,11 +179,17 @@ class ColissimoLabel::GenerateLabel
175
179
  %w[CH].include?(@destination_country)
176
180
  end
177
181
 
178
- # DOM : Colissimo France et International sans signature / DOS : Colissimo France et International avec signature
179
182
  # Certains pays, comme l'Allemagne, requiert une signature pour la livraison
183
+ # DOM : Colissimo France et International sans signature
184
+ # DOS : Colissimo France et International avec signature
185
+ # Pays avec Point Relais : https://www.colissimo.entreprise.laposte.fr/fr/offre-europe
186
+ # BPR : Colissimo - Point Retrait – en Bureau de Poste
187
+ # A2P : Colissimo - Point Retrait – en relais Pickup ou en consigne Pickup Station
180
188
  def product_code
181
189
  if %w[DE IT GB LU].include?(@destination_country)
182
190
  'DOS'
191
+ elsif !@pickup_id.nil? && %w[FR].include?(@destination_country)
192
+ @pickup_type || 'BPR'
183
193
  else
184
194
  'DOM'
185
195
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColissimoLabel
4
- VERSION = '0.4.0'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FloXcoder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-11 00:00:00.000000000 Z
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport