colissimo_label 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e16af5dc9fedb8d91145c4bf01874659595749a05b03a9fe36555fc2b7c9f4fb
4
+ data.tar.gz: 11258c819b04b35b6e63d66498dd0fb77057647192e6fa6fd36078ccef201c1a
5
+ SHA512:
6
+ metadata.gz: d2cf7ff66046eec71c95468ea0056f52f211dc4ce5dc241ef2c41594fa1e6762a5e13d8d628963571bbb4f39ce4cc25a72a10b96077f1fc714fd4124eb75402c
7
+ data.tar.gz: effe719b0accd8c4a1423f4f974e4bc5e591b2679f0ad80ebf57151d0334a20f7d285a211f757f6b8d9e4b4ee02e12d608bc8d775b8a7ebea274f234a9e8b283
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.config/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/data/generated
11
+ /tmp/
12
+ .ruby-version
13
+ .ruby-gemset
14
+ Gemfile.lock
15
+ tmp
16
+
17
+ # rspec failure tracking
18
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,127 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ LineLength:
8
+ Enabled: false
9
+
10
+ Bundler/OrderedGems:
11
+ Enabled: false
12
+
13
+ Layout/AlignHash:
14
+ Enabled: false
15
+
16
+ Layout/AlignParameters:
17
+ Enabled: false
18
+
19
+ Layout/CaseIndentation:
20
+ Enabled: false
21
+
22
+ Layout/EmptyLinesAroundClassBody:
23
+ Enabled: false
24
+
25
+ Layout/ExtraSpacing:
26
+ Enabled: false
27
+ AllowForAlignment: true
28
+
29
+ Layout/IndentFirstHashElement:
30
+ Enabled: false
31
+
32
+ Layout/IndentFirstArgument:
33
+ Enabled: false
34
+
35
+ Layout/LeadingCommentSpace:
36
+ Enabled: false
37
+
38
+ Layout/MultilineBlockLayout:
39
+ Enabled: false
40
+
41
+ Layout/MultilineMethodCallBraceLayout:
42
+ Enabled: false
43
+
44
+ Layout/MultilineMethodCallIndentation:
45
+ Enabled: false
46
+
47
+ Layout/MultilineOperationIndentation:
48
+ Enabled: false
49
+
50
+ Layout/SpaceAroundOperators:
51
+ Enabled: false
52
+
53
+ Layout/SpaceInLambdaLiteral:
54
+ Enabled: false
55
+
56
+ Layout/TrailingWhitespace:
57
+ Enabled: false
58
+
59
+ Lint/AmbiguousBlockAssociation:
60
+ Enabled: false
61
+
62
+ Metrics/AbcSize:
63
+ # The ABC size is a calculated magnitude, so this number can be a Fixnum or a Float.
64
+ Max: 240
65
+
66
+ Metrics/BlockLength:
67
+ Max: 90
68
+
69
+ Metrics/BlockNesting:
70
+ Max: 4
71
+
72
+ Metrics/ClassLength:
73
+ CountComments: false # count full line comments?
74
+ Max: 600
75
+
76
+ Metrics/CyclomaticComplexity:
77
+ Enabled: false
78
+
79
+ Metrics/MethodLength:
80
+ CountComments: false # count full line comments?
81
+ Max: 120
82
+
83
+ Metrics/ParameterLists:
84
+ Max: 7
85
+
86
+ Metrics/PerceivedComplexity:
87
+ Enabled: false
88
+
89
+ Rails/OutputSafety:
90
+ Enabled: false
91
+
92
+ Style/AsciiComments:
93
+ Enabled: false
94
+
95
+ Style/ColonMethodCall:
96
+ Enabled: false
97
+
98
+ Style/CommandLiteral:
99
+ Enabled: false
100
+
101
+ Style/FrozenStringLiteralComment:
102
+ Enabled: false
103
+
104
+ Style/Lambda:
105
+ Enabled: false
106
+
107
+ Style/MultilineIfModifier:
108
+ Enabled: false
109
+
110
+ Style/NumericPredicate:
111
+ Enabled: false
112
+
113
+ Style/RedundantReturn:
114
+ Enabled: false
115
+ AllowMultipleReturnValues: true
116
+
117
+ Style/RedundantSelf:
118
+ Enabled: false
119
+
120
+ Style/RegexpLiteral:
121
+ Enabled: false
122
+
123
+ Style/RescueModifier:
124
+ Enabled: false
125
+
126
+ Style/SymbolArray:
127
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at flo@l-x.fr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,42 @@
1
+ # Contributing
2
+
3
+ First, thanks for wanting to contribute. You’re awesome! :heart:
4
+
5
+ ## Help
6
+
7
+ We’re not able to provide support through GitHub Issues. If you’re looking for help with your code, try posting on [Stack Overflow](https://stackoverflow.com/).
8
+
9
+ All features should be documented. If you don’t see a feature in the docs, assume it doesn’t exist.
10
+
11
+ ## Bugs
12
+
13
+ Think you’ve discovered a bug?
14
+
15
+ 1. Search existing issues to see if it’s been reported.
16
+ 2. Try the `master` branch to make sure it hasn’t been fixed.
17
+
18
+ ```rb
19
+ gem "colissimo_label", github: "floXcode/colissimo_label"
20
+ ```
21
+
22
+ If the above steps don’t help, create an issue. Include:
23
+
24
+ - Detailed steps to reproduce
25
+ - Complete backtraces for exceptions
26
+
27
+ ## New Features
28
+
29
+ If you’d like to discuss a new feature, create an issue and start the title with `[Idea]`.
30
+
31
+ ## Pull Requests
32
+
33
+ Fork the project and create a pull request. A few tips:
34
+
35
+ - Keep changes to a minimum. If you have multiple features or fixes, submit multiple pull requests.
36
+ - Follow the existing style. The code should read like it’s written by a single person.
37
+
38
+ Feel free to open an issue to get feedback on your idea before spending too much time on it.
39
+
40
+ ---
41
+
42
+ This contributing guide is released under [CCO](https://creativecommons.org/publicdomain/zero/1.0/) (public domain). Use it for your own project without attribution.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in colissimo_label.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 floXcoder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # ColissimoLabel
2
+
3
+ Generate Colissimo label for all countries with customs declaration :fire:
4
+
5
+ To use this gem, you need to have an WebService account in Colissimo. Ask for it when you set up a new contract with Colissimo.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'colissimo_label'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install colissimo_label
22
+
23
+ ```ruby
24
+ require 'colissimo_label'
25
+ ```
26
+
27
+ ## Options
28
+
29
+ Colissimo contract number (dedicated for webservices) (**required**):
30
+
31
+ ```ruby
32
+ ColissimoLabel.contract_number = ENV['COLISSIMO_CONTRACT_NUMBER']
33
+ ```
34
+
35
+ Colissimo password (dedicated for webservices) (**required**):
36
+
37
+ ```ruby
38
+ ColissimoLabel.contract_password = ENV['COLISSIMO_PASSWORD']
39
+ ```
40
+
41
+ I you want to save generated files on AWS S3, initialize the bucket:
42
+
43
+ ```ruby
44
+ ColissimoLabel.s3_bucket = Aws::S3::Resource.new.bucket('my_bucket_name')
45
+ ```
46
+
47
+ Define the directory to save files (**required** if s3_bucket used):
48
+
49
+ ```ruby
50
+ ColissimoLabel.s3_path = 'path/to/colissimo'
51
+ ```
52
+
53
+ Declare local path to save generated files (**required** if no use of S3):
54
+
55
+ ```ruby
56
+ ColissimoLabel.colissimo_local_path = Rails.root.join('public', 'colissimo')
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ To generate a new Colissimo label, use the following methods.
62
+
63
+ For a national address:
64
+
65
+ ```ruby
66
+ parcel_number = ColissimoLabel::GenerateLabel.new(
67
+ 'label_filename', # Name of the file generated
68
+ 'FR', # Normalized country code of the destination
69
+ 9.99, # Amount of the shipping fees (paid by the customer)
70
+ {
71
+ company_name: 'Sender company name',
72
+ address: 'Address',
73
+ city: 'City',
74
+ postcode: 'Postcode',
75
+ country_code: 'Normalized country code'
76
+ },
77
+ {
78
+ last_name: 'Last name of the addressee',
79
+ first_name: 'First name of the addressee',
80
+ address_bis: 'Address bis of the addressee',
81
+ address: 'Address of the addressee',
82
+ city: 'City of the addressee',
83
+ postcode: 'Postcode of the addressee',
84
+ country_code: 'Normalized country code of the addressee',
85
+ phone: 'Phone number of the addressee',
86
+ mobile: 'Mobile number of the addressee',
87
+ email: 'Email of the addressee'
88
+ }
89
+ ).call
90
+ ```
91
+
92
+ For a foreign address (which required customs declaration):
93
+
94
+ ```ruby
95
+ parcel_number = ColissimoLabel::GenerateLabel.new(
96
+ 'label_filename', # Name of the file generated
97
+ 'CH', # Normalized country code of the destination
98
+ 9.99, # Amount of the shipping fees (paid by the customer)
99
+ {
100
+ company_name: 'Sender company name',
101
+ address: 'Address',
102
+ city: 'City',
103
+ postcode: 'Postcode',
104
+ country_code: 'Normalized country code'
105
+ },
106
+ {
107
+ last_name: 'Last name of the addressee',
108
+ first_name: 'First name of the addressee',
109
+ address_bis: 'Address bis of the addressee',
110
+ address: 'Address of the addressee',
111
+ city: 'City of the addressee',
112
+ postcode: 'Postcode of the addressee',
113
+ country_code: 'Normalized country code of the addressee',
114
+ phone: 'Phone number of the addressee',
115
+ mobile: 'Mobile number of the addressee',
116
+ email: 'Email of the addressee'
117
+ },
118
+ 2, # Total weight of the package
119
+ [ # Details content of your package
120
+ {
121
+ description: 'Product description',
122
+ quantity: 1,
123
+ weight: 2,
124
+ item_price: 100,
125
+ country_code: 'FR',
126
+ currency_code: 'EUR',
127
+ customs_code: 'hsCode' # Harmonized system code of your product
128
+ }
129
+ ]
130
+ ).call
131
+ ```
132
+
133
+ In both cases, if the label cannot be generated it raises a StandardError with the reason. Otherwise, the parcel number is returned and files saved in the specified folders.
134
+
135
+ ## Documentation
136
+
137
+ Colissimo documentation can be found here:
138
+
139
+ https://www.colissimo.entreprise.laposte.fr/system/files/imagescontent/docs/spec_ws_affranchissement.pdf
140
+
141
+ ## Contributing
142
+
143
+ Bug reports and pull requests are welcome on GitHub at https://github.com/floXcoder/colissimo_label. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
144
+
145
+ ## License
146
+
147
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
148
+
149
+ ## Code of Conduct
150
+
151
+ Everyone interacting in the ColissimoLabel project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/colissimo_label/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "colissimo_label"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'colissimo_label/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'colissimo_label'
7
+ spec.version = ColissimoLabel::VERSION
8
+ spec.authors = ['FloXcoder']
9
+ spec.email = ['flo@l-x.fr']
10
+
11
+ spec.summary = 'Generate Colissimo label for all countries'
12
+ spec.description = 'Generate Colissimo label for all countries with customs declaration (Colissimo webservice account required).'
13
+ spec.homepage = 'https://github.com/floXcoder/colissimo_label'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'activesupport', '~> 5'
24
+ spec.add_dependency 'rack', '~> 2'
25
+ spec.add_dependency 'railties', '~> 5'
26
+ spec.add_dependency 'http', '~> 4'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 2'
29
+ spec.add_development_dependency 'rake', '~> 12'
30
+ spec.add_development_dependency 'rspec', '~> 3'
31
+ spec.add_development_dependency 'simplecov', '~> 0.16'
32
+ spec.add_development_dependency 'webmock', '~> 3'
33
+ end
@@ -0,0 +1,188 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+
5
+ class ColissimoLabel::GenerateLabel
6
+
7
+ def initialize(filename, destination_country, shipping_fees, sender_data, addressee_data, customs_total_weight = nil, customs_data = nil)
8
+ @filename = filename
9
+ @destination_country = destination_country
10
+ @shipping_fees = shipping_fees
11
+ @sender_data = sender_data
12
+ @addressee_data = addressee_data
13
+ @customs_total_weight = customs_total_weight
14
+ @customs_data = customs_data
15
+ @errors = []
16
+ end
17
+
18
+ def perform
19
+ response = perform_request
20
+ status = response.code
21
+ parts = response.to_a.last.force_encoding('BINARY').split('Content-ID: ')
22
+ label_filename = @filename + '.pdf'
23
+
24
+ if ColissimoLabel.s3_bucket
25
+ colissimo_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + label_filename)
26
+ colissimo_pdf.put(acl: 'public-read', body: parts[2])
27
+ else
28
+ File.open(ColissimoLabel.colissimo_local_path.chomp('/') + '/' + label_filename, 'wb') do |file|
29
+ file.write(parts[2])
30
+ end
31
+ end
32
+
33
+ if require_customs?
34
+ customs_filename = @filename + '-customs.pdf'
35
+
36
+ if ColissimoLabel.s3_bucket
37
+ customs_pdf = ColissimoLabel.s3_bucket.object(ColissimoLabel.s3_path.chomp('/') + '/' + customs_filename)
38
+ customs_pdf.put(acl: 'public-read', body: parts[3])
39
+ else
40
+ File.open(ColissimoLabel.colissimo_local_path.chomp('/') + '/' + customs_filename, 'wb') do |file|
41
+ file.write(parts[3])
42
+ end
43
+ end
44
+ end
45
+
46
+ if status == 400
47
+ error_message = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"messageContent":"(.*?)"/).last.first
48
+ raise StandardError, error_message
49
+ else
50
+ parcel_number = response.body.to_s.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').scan(/"parcelNumber":"(.*?)",/).last.first
51
+
52
+ return parcel_number
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def perform_request(delivery_date = Date.today)
59
+ HTTP.post(service_url,
60
+ json: {
61
+ "contractNumber": ColissimoLabel.contract_number,
62
+ "password": ColissimoLabel.contract_password,
63
+ "outputFormat": {
64
+ "x": '0',
65
+ "y": '0',
66
+ "outputPrintingType": 'PDF_10x15_300dpi'
67
+ },
68
+ "letter": {
69
+ "service": {
70
+ "productCode": product_code,
71
+ "depositDate": delivery_date.strftime('%F'),
72
+ "totalAmount": (@shipping_fees * 100).to_i,
73
+ # "returnTypeChoice": '2' # Retour à la maison en prioritaire
74
+ },
75
+ "parcel": {
76
+ "weight": format_weight
77
+ },
78
+ "sender": {
79
+ "address": format_sender
80
+ },
81
+ "addressee": {
82
+ "address": format_addressee
83
+ }
84
+ }.merge(customs)
85
+ }.compact)
86
+ end
87
+
88
+ # Services =>
89
+ # generateLabel : Génère une expédition : annonce informatique du colis + documents associés (étiquette et déclarations douanières)
90
+ # checkGenerateLabel : Permet de tester les requêtes web service
91
+ # getProductInter : Utile uniquement dans le cas de certaines destinations internationales
92
+ # getListMailBoxPickingDates : Fonctionne avec le produit Retour Colissimo France (numéro de colis généré via WS ou toute autre solution avec annonce)
93
+ # planPickup : Fonctionne avec le produit Retour Colissimo France (n° colis généré via WS ou toute autre solution avec annonce)
94
+ def service_url(service = 'generateLabel')
95
+ "https://ws.colissimo.fr/sls-ws/SlsServiceWSRest/2.0/#{service}"
96
+ end
97
+
98
+ def format_sender
99
+ {
100
+ "companyName": @sender_data[:company_name],
101
+ "line2": @sender_data[:address],
102
+ "city": @sender_data[:city],
103
+ "zipCode": @sender_data[:postcode],
104
+ "countryCode": @sender_data[:country_code]
105
+ }
106
+ end
107
+
108
+ def format_addressee
109
+ {
110
+ "companyName": @addressee_data[:company_name], # Raison sociale
111
+ "lastName": @addressee_data[:last_name], # Nom
112
+ "firstName": @addressee_data[:last_name], # Prénom
113
+ "line0": @addressee_data[:apartment], # Etage, couloir, escalier, appartement
114
+ "line1": @addressee_data[:address_bis], # Entrée, bâtiment, immeuble, résidence
115
+ "line2": @addressee_data[:address], # Numéro et libellé de voie
116
+ "line3": @addressee_data[:address_ter], # Lieu-dit ou autre mention
117
+ "countryCode": @addressee_data[:country_code], # Code ISO du pays
118
+ "city": @addressee_data[:city], # Ville
119
+ "zipCode": @addressee_data[:postcode], # Code postal
120
+ "phoneNumber": @addressee_data[:phone], # Numéro de téléphone
121
+ "mobileNumber": @addressee_data[:mobile], # Numéro de portable
122
+ "doorCode1": @addressee_data[:door_code_1], # Code porte 1
123
+ "doorCode2": @addressee_data[:door_code_2], # Code porte 2
124
+ "email": @addressee_data[:email], # Adresse courriel
125
+ "intercom": @addressee_data[:intercom] # Interphone
126
+ }.compact.transform_values(&:strip)
127
+ end
128
+
129
+ # weight: Colissimo weigh themselves all packages (so not relevant here)
130
+ def format_weight
131
+ if require_customs?
132
+ @customs_total_weight
133
+ else
134
+ '0.1'
135
+ end
136
+ end
137
+
138
+ # Déclaration douanière de type CN23
139
+ def customs
140
+ if require_customs?
141
+ {
142
+ "customsDeclarations": {
143
+ "includeCustomsDeclarations": 1, # Inclure déclaration
144
+ "contents": {
145
+ "article": @customs_data.map { |customs|
146
+ {
147
+ "description": customs[:description],
148
+ "quantity": customs[:quantity],
149
+ "weight": customs[:weight],
150
+ "value": customs[:item_price],
151
+ "originCountry": customs[:country_code],
152
+ "currency": customs[:currency_code],
153
+ "hsCode": customs[:customs_code] # Objets d'art, de collection ou d'antiquité (https://pro.douane.gouv.fr/prodouane.asp)
154
+ }
155
+ },
156
+ "category": {
157
+ # Nature de l'envoi
158
+ # 1 => Cadeau
159
+ # 2 => Echantillon commercial
160
+ # 3 => Envoi commercial
161
+ # 4 => Document
162
+ # 5 => Autre
163
+ # 6 => Retour de marchandise
164
+ "value": 3
165
+ }
166
+ }
167
+ }
168
+ }
169
+ else
170
+ {}
171
+ end
172
+ end
173
+
174
+ def require_customs?
175
+ %w[CH].include?(@destination_country)
176
+ end
177
+
178
+ # DOM : Colissimo France et International sans signature / DOS : Colissimo France et International avec signature
179
+ # Certains pays, comme l'Allemagne, requiert une signature pour la livraison
180
+ def product_code
181
+ if %w[DE IT GB LU].include?(@destination_country)
182
+ 'DOS'
183
+ else
184
+ 'DOM'
185
+ end
186
+ end
187
+
188
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'logger'
5
+
6
+ module ColissimoLabel
7
+ class Logger
8
+ extend Forwardable
9
+ include ::Logger::Severity
10
+
11
+ def_delegators :@logger, :debug, :debug?,
12
+ :info, :info?,
13
+ :warn, :warn?,
14
+ :error, :error?,
15
+ :fatal, :fatal?,
16
+ :level
17
+
18
+ def initialize(logger_path = nil)
19
+ @logger = create_logger(logger_path || $stdout)
20
+ end
21
+
22
+ def output=(io)
23
+ # `Logger#reopen` was added in Ruby 2.3
24
+ if @logger.respond_to?(:reopen)
25
+ @logger.reopen(io)
26
+ else
27
+ @logger = create_logger(io)
28
+ end
29
+ end
30
+
31
+ #
32
+ # For Ruby < 2.3 compatibility
33
+ # Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
34
+ #
35
+
36
+ def level=(severity)
37
+ if severity.is_a?(Integer)
38
+ @logger.level = severity
39
+ else
40
+ case severity.to_s.downcase
41
+ when 'debug'
42
+ @logger.level = DEBUG
43
+ when 'info'
44
+ @logger.level = INFO
45
+ when 'warn'
46
+ @logger.level = WARN
47
+ when 'error'
48
+ @logger.level = ERROR
49
+ when 'fatal'
50
+ @logger.level = FATAL
51
+ when 'unknown'
52
+ @logger.level = UNKNOWN
53
+ else
54
+ raise ArgumentError, "invalid log level: #{severity}"
55
+ end
56
+ end
57
+ end
58
+
59
+ #
60
+ # Returns IO object used by logger internally.
61
+ #
62
+ # Normally, we would have never needed it, but we want to
63
+ # use it as IO object for all child processes to ensure their
64
+ # output is redirected there.
65
+ #
66
+ # It is only used in debug level, in other cases output is suppressed.
67
+ #
68
+ # @api private
69
+ #
70
+ def io
71
+ @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
72
+ end
73
+
74
+ #
75
+ # Marks code as deprecated with replacement.
76
+ #
77
+ # @param [String] old
78
+ # @param [String] new
79
+ #
80
+ def deprecate(old, new)
81
+ warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
82
+ end
83
+
84
+ private
85
+
86
+ def create_logger(output)
87
+ logger = ::Logger.new(output)
88
+ logger.progname = 'ColissimoLabel'
89
+ logger.level = ($DEBUG ? DEBUG : INFO)
90
+ logger.formatter = proc do |severity, time, progname, msg|
91
+ "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
92
+ end
93
+
94
+ logger
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColissimoLabel
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ require 'colissimo_label/version'
6
+ require 'colissimo_label/generate_label'
7
+
8
+ module ColissimoLabel
9
+
10
+ mattr_accessor :contract_number
11
+ self.contract_number = nil
12
+ mattr_accessor :contract_password
13
+ self.contract_password = nil
14
+
15
+ mattr_accessor :s3_bucket
16
+ self.s3_bucket = nil
17
+ mattr_accessor :s3_path
18
+ self.s3_path = nil
19
+
20
+ mattr_accessor :colissimo_local_path
21
+ self.colissimo_local_path = nil
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colissimo_label
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - FloXcoder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.16'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.16'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3'
139
+ description: Generate Colissimo label for all countries with customs declaration (Colissimo
140
+ webservice account required).
141
+ email:
142
+ - flo@l-x.fr
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - CONTRIBUTING.md
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - bin/console
158
+ - bin/setup
159
+ - colissimo_label.gemspec
160
+ - lib/colissimo_label.rb
161
+ - lib/colissimo_label/generate_label.rb
162
+ - lib/colissimo_label/logger.rb
163
+ - lib/colissimo_label/version.rb
164
+ homepage: https://github.com/floXcoder/colissimo_label
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.7.9
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Generate Colissimo label for all countries
188
+ test_files: []