deliveries 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +19 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +127 -0
- data/LICENSE.txt +21 -0
- data/README.md +207 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/deliveries.gemspec +36 -0
- data/lib/deliveries/address.rb +71 -0
- data/lib/deliveries/checkpoint.rb +12 -0
- data/lib/deliveries/collection_point.rb +45 -0
- data/lib/deliveries/courier.rb +69 -0
- data/lib/deliveries/couriers/correos_express/address.rb +31 -0
- data/lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb +82 -0
- data/lib/deliveries/couriers/correos_express/collection_points/search.rb +56 -0
- data/lib/deliveries/couriers/correos_express/labels/generate.rb +68 -0
- data/lib/deliveries/couriers/correos_express/pickups/create/defaults.rb +60 -0
- data/lib/deliveries/couriers/correos_express/pickups/create/format_params.rb +95 -0
- data/lib/deliveries/couriers/correos_express/pickups/create.rb +66 -0
- data/lib/deliveries/couriers/correos_express/pickups/cutoff_time/format_params.rb +40 -0
- data/lib/deliveries/couriers/correos_express/pickups/cutoff_time.rb +61 -0
- data/lib/deliveries/couriers/correos_express/pickups/trace/correos.test.wsdl +163 -0
- data/lib/deliveries/couriers/correos_express/pickups/trace/correos.wsdl +163 -0
- data/lib/deliveries/couriers/correos_express/pickups/trace/format_response.rb +71 -0
- data/lib/deliveries/couriers/correos_express/pickups/trace.rb +49 -0
- data/lib/deliveries/couriers/correos_express/shipments/create/defaults.rb +80 -0
- data/lib/deliveries/couriers/correos_express/shipments/create/format_params.rb +99 -0
- data/lib/deliveries/couriers/correos_express/shipments/create.rb +101 -0
- data/lib/deliveries/couriers/correos_express/shipments/trace/format_response.rb +67 -0
- data/lib/deliveries/couriers/correos_express/shipments/trace.rb +65 -0
- data/lib/deliveries/couriers/correos_express.rb +162 -0
- data/lib/deliveries/couriers/dummy.rb +106 -0
- data/lib/deliveries/couriers/mondial_relay/address.rb +31 -0
- data/lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb +103 -0
- data/lib/deliveries/couriers/mondial_relay/labels/generate.rb +40 -0
- data/lib/deliveries/couriers/mondial_relay/pickups/create/format_params.rb +57 -0
- data/lib/deliveries/couriers/mondial_relay/shipments/create/defaults.rb +96 -0
- data/lib/deliveries/couriers/mondial_relay/shipments/create/format_params.rb +68 -0
- data/lib/deliveries/couriers/mondial_relay/shipments/create.rb +36 -0
- data/lib/deliveries/couriers/mondial_relay/shipments/trace/format_response.rb +94 -0
- data/lib/deliveries/couriers/mondial_relay/shipments/trace.rb +47 -0
- data/lib/deliveries/couriers/mondial_relay/status_codes.rb +105 -0
- data/lib/deliveries/couriers/mondial_relay.rb +189 -0
- data/lib/deliveries/couriers/mondial_relay_dual/address.rb +31 -0
- data/lib/deliveries/couriers/mondial_relay_dual/pickups/create/format_params.rb +39 -0
- data/lib/deliveries/couriers/mondial_relay_dual/shipments/create/format_params.rb +101 -0
- data/lib/deliveries/couriers/mondial_relay_dual/shipments/create.rb +133 -0
- data/lib/deliveries/couriers/mondial_relay_dual.rb +105 -0
- data/lib/deliveries/couriers/spring/address.rb +23 -0
- data/lib/deliveries/couriers/spring/labels/generate.rb +33 -0
- data/lib/deliveries/couriers/spring/request.rb +43 -0
- data/lib/deliveries/couriers/spring/shipments/create/defaults.rb +73 -0
- data/lib/deliveries/couriers/spring/shipments/create/format_params.rb +77 -0
- data/lib/deliveries/couriers/spring/shipments/create.rb +45 -0
- data/lib/deliveries/couriers/spring/shipments/trace/format_response.rb +79 -0
- data/lib/deliveries/couriers/spring/shipments/trace.rb +29 -0
- data/lib/deliveries/couriers/spring.rb +84 -0
- data/lib/deliveries/couriers/ups/collection_points/search.rb +142 -0
- data/lib/deliveries/couriers/ups/json_request.rb +40 -0
- data/lib/deliveries/couriers/ups/labels/generate.rb +72 -0
- data/lib/deliveries/couriers/ups/shipments/create.rb +210 -0
- data/lib/deliveries/couriers/ups/shipments/trace.rb +79 -0
- data/lib/deliveries/couriers/ups.rb +122 -0
- data/lib/deliveries/couriers.rb +14 -0
- data/lib/deliveries/delivery.rb +20 -0
- data/lib/deliveries/errors.rb +22 -0
- data/lib/deliveries/label.rb +20 -0
- data/lib/deliveries/label_utils.rb +67 -0
- data/lib/deliveries/labels.rb +40 -0
- data/lib/deliveries/pickup.rb +15 -0
- data/lib/deliveries/shipment.rb +15 -0
- data/lib/deliveries/tracking_info.rb +29 -0
- data/lib/deliveries/version.rb +5 -0
- data/lib/deliveries.rb +63 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2102df4101cad8142a4673ee79f2d18994309db3e7a5d70ea03281abb4d9c5c5
|
4
|
+
data.tar.gz: 7ffe9bf7dd2546132118c6e1d028cc36f216eb7e2eaad34b6543f76d4090452a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44eee42b323ffea42bbdb8d963a69084d5f9196b0b92fa3078954411bbf1e6d22a5e5229564edf53deefebc21cd6ab6e1a05cade53e80c83b214f1b7d4eb7e48
|
7
|
+
data.tar.gz: 7c07fb3e9f88692391d806b18960720f22cf1339574f335c10bce33cef2f14a123ea1ca5fe8cc116d2f5c5ffbee953861851cfacc85dd2a538353af93dad52f9
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.7
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
sudo apt-get install poppler-utils
|
17
|
+
gem install bundler -v 2.2.4
|
18
|
+
bundle install
|
19
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.6.7
|
4
|
+
Exclude:
|
5
|
+
- spec/**/*.rb
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: single_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: single_quotes
|
14
|
+
|
15
|
+
Metrics:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Layout/LineLength:
|
25
|
+
# We have a lot of very long lines in the code to fix,
|
26
|
+
# this is a start but we should aim to lower it to
|
27
|
+
# at least 120
|
28
|
+
Max: 155
|
29
|
+
|
30
|
+
Style/FormatStringToken:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/IfUnlessModifier:
|
34
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.1.0] - 2021-09-27
|
10
|
+
🎉 First release!
|
11
|
+
|
12
|
+
[Unreleased]: https://github.com/ecommerce-ventures/deliveries/compare/v0.1.0...HEAD
|
13
|
+
[0.1.0]: https://github.com/ecommerce-ventures/deliveries/releases/tag/v0.1.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
deliveries (0.1.0)
|
5
|
+
activesupport (>= 5.2.0)
|
6
|
+
hexapdf
|
7
|
+
httparty
|
8
|
+
mini_magick
|
9
|
+
nokogiri
|
10
|
+
savon (~> 2.8)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activesupport (6.1.4)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
addressable (2.8.0)
|
22
|
+
public_suffix (>= 2.0.2, < 5.0)
|
23
|
+
akami (1.3.1)
|
24
|
+
gyoku (>= 0.4.0)
|
25
|
+
nokogiri
|
26
|
+
ast (2.4.2)
|
27
|
+
builder (3.2.4)
|
28
|
+
byebug (11.1.3)
|
29
|
+
cmdparse (3.0.7)
|
30
|
+
concurrent-ruby (1.1.9)
|
31
|
+
crack (0.4.5)
|
32
|
+
rexml
|
33
|
+
diff-lcs (1.4.4)
|
34
|
+
geom2d (0.3.1)
|
35
|
+
gyoku (1.3.1)
|
36
|
+
builder (>= 2.1.2)
|
37
|
+
hashdiff (1.0.1)
|
38
|
+
hexapdf (0.15.8)
|
39
|
+
cmdparse (~> 3.0, >= 3.0.3)
|
40
|
+
geom2d (~> 0.3)
|
41
|
+
httparty (0.18.1)
|
42
|
+
mime-types (~> 3.0)
|
43
|
+
multi_xml (>= 0.5.2)
|
44
|
+
httpi (2.4.5)
|
45
|
+
rack
|
46
|
+
socksify
|
47
|
+
i18n (1.8.10)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
mime-types (3.3.1)
|
50
|
+
mime-types-data (~> 3.2015)
|
51
|
+
mime-types-data (3.2021.0704)
|
52
|
+
mini_magick (4.11.0)
|
53
|
+
minitest (5.14.4)
|
54
|
+
multi_xml (0.6.0)
|
55
|
+
nokogiri (1.12.3-x86_64-linux)
|
56
|
+
racc (~> 1.4)
|
57
|
+
nori (2.6.0)
|
58
|
+
parallel (1.20.1)
|
59
|
+
parser (3.0.2.0)
|
60
|
+
ast (~> 2.4.1)
|
61
|
+
public_suffix (4.0.6)
|
62
|
+
racc (1.5.2)
|
63
|
+
rack (2.2.3)
|
64
|
+
rainbow (3.0.0)
|
65
|
+
rake (13.0.6)
|
66
|
+
regexp_parser (2.1.1)
|
67
|
+
rexml (3.2.5)
|
68
|
+
rspec (3.9.0)
|
69
|
+
rspec-core (~> 3.9.0)
|
70
|
+
rspec-expectations (~> 3.9.0)
|
71
|
+
rspec-mocks (~> 3.9.0)
|
72
|
+
rspec-core (3.9.3)
|
73
|
+
rspec-support (~> 3.9.3)
|
74
|
+
rspec-expectations (3.9.4)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.9.0)
|
77
|
+
rspec-mocks (3.9.1)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.9.0)
|
80
|
+
rspec-support (3.9.4)
|
81
|
+
rubocop (0.93.1)
|
82
|
+
parallel (~> 1.10)
|
83
|
+
parser (>= 2.7.1.5)
|
84
|
+
rainbow (>= 2.2.2, < 4.0)
|
85
|
+
regexp_parser (>= 1.8)
|
86
|
+
rexml
|
87
|
+
rubocop-ast (>= 0.6.0)
|
88
|
+
ruby-progressbar (~> 1.7)
|
89
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
90
|
+
rubocop-ast (1.10.0)
|
91
|
+
parser (>= 3.0.1.1)
|
92
|
+
ruby-progressbar (1.11.0)
|
93
|
+
savon (2.12.1)
|
94
|
+
akami (~> 1.2)
|
95
|
+
builder (>= 2.1.2)
|
96
|
+
gyoku (~> 1.2)
|
97
|
+
httpi (~> 2.3)
|
98
|
+
nokogiri (>= 1.8.1)
|
99
|
+
nori (~> 2.4)
|
100
|
+
wasabi (~> 3.4)
|
101
|
+
socksify (1.7.1)
|
102
|
+
tzinfo (2.0.4)
|
103
|
+
concurrent-ruby (~> 1.0)
|
104
|
+
unicode-display_width (1.7.0)
|
105
|
+
wasabi (3.6.1)
|
106
|
+
addressable
|
107
|
+
httpi (~> 2.0)
|
108
|
+
nokogiri (>= 1.4.2)
|
109
|
+
webmock (3.14.0)
|
110
|
+
addressable (>= 2.8.0)
|
111
|
+
crack (>= 0.3.2)
|
112
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
113
|
+
zeitwerk (2.4.2)
|
114
|
+
|
115
|
+
PLATFORMS
|
116
|
+
x86_64-linux
|
117
|
+
|
118
|
+
DEPENDENCIES
|
119
|
+
byebug
|
120
|
+
deliveries!
|
121
|
+
rake (~> 13.0)
|
122
|
+
rspec (~> 3.0)
|
123
|
+
rubocop (~> 0.80)
|
124
|
+
webmock (~> 3.5)
|
125
|
+
|
126
|
+
BUNDLED WITH
|
127
|
+
2.2.24
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021-present Micolet Web S.L.
|
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,207 @@
|
|
1
|
+
# Deliveries Gem
|
2
|
+
|
3
|
+
Deliveries is a gem that gives you the ability to integrate multiple shipping services through different couriers
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following line to your Gemfile
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem 'deliveries'
|
11
|
+
```
|
12
|
+
Then run:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
Each courier requires a different configuration, below we will leave some examples
|
21
|
+
|
22
|
+
#### 1. Mondial Relay
|
23
|
+
```bash
|
24
|
+
Deliveries.courier(:mondial_relay).configure do |config|
|
25
|
+
config.mondial_relay_merchant = '...'
|
26
|
+
config.mondial_relay_key = '...'
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
#### 2. Mondial Relay Dual
|
31
|
+
```bash
|
32
|
+
Deliveries.courier(:mondial_relay_dual).configure do |config|
|
33
|
+
config.dual_carrier_login = '...'
|
34
|
+
config.dual_carrier_password = '...'
|
35
|
+
config.dual_carrier_customer_id = '...'
|
36
|
+
config.countries = {
|
37
|
+
fr: {
|
38
|
+
home_delivery_mode: 'HOC'
|
39
|
+
},
|
40
|
+
de: {
|
41
|
+
home_delivery_mode: 'HOM'
|
42
|
+
},
|
43
|
+
gb: {
|
44
|
+
home_delivery_mode: 'HOM'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
#### 3. Correos Express
|
51
|
+
```bash
|
52
|
+
Deliveries.courier(:correos_express).configure do |config|
|
53
|
+
config.username = '...'
|
54
|
+
config.password = '...'
|
55
|
+
config.client_code = '...'
|
56
|
+
config.shipment_sender_code = '...'
|
57
|
+
config.pickup_receiver_code = '...'
|
58
|
+
config.countries = {
|
59
|
+
es: {
|
60
|
+
product: '93'
|
61
|
+
},
|
62
|
+
pt: {
|
63
|
+
product: '63'
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
#### 4. Spring
|
70
|
+
```bash
|
71
|
+
Deliveries.courier(:spring).configure do |config|
|
72
|
+
config.api_key = '...'
|
73
|
+
config.countries = {
|
74
|
+
gb: {
|
75
|
+
service: 'TRCK'
|
76
|
+
},
|
77
|
+
it: {
|
78
|
+
service: 'TRCK'
|
79
|
+
}
|
80
|
+
}
|
81
|
+
config.default_product = {
|
82
|
+
description: 'ROPA',
|
83
|
+
hs_code: '',
|
84
|
+
origin_country: 'ES',
|
85
|
+
quantity: 1,
|
86
|
+
value: 100
|
87
|
+
}
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
#### 5. UPS
|
92
|
+
```bash
|
93
|
+
Deliveries.courier(:ups).configure do |config|
|
94
|
+
config.license_number = '...'
|
95
|
+
config.username = '...'
|
96
|
+
config.password = '...'
|
97
|
+
config.point_account_number = '...'
|
98
|
+
config.home_account_number = '...'
|
99
|
+
config.default_product = {
|
100
|
+
description: 'clothes',
|
101
|
+
weight: '1'
|
102
|
+
}
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
## Usage
|
107
|
+
|
108
|
+
#### Get collection point by country and postcode
|
109
|
+
|
110
|
+
```bash
|
111
|
+
# Example Using Ups
|
112
|
+
|
113
|
+
Deliveries.courier(:ups).get_collection_points(postcode: '...', country: 'it')
|
114
|
+
```
|
115
|
+
#### Get collection point info
|
116
|
+
|
117
|
+
```bash
|
118
|
+
# Example Using Mondial Relay
|
119
|
+
|
120
|
+
Deliveries.courier(:mondial_relay).get_collection_point(global_point_id: 'mondial_relay~fr~00000~XXXXXX')
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Create a Shipment
|
124
|
+
```bash
|
125
|
+
# Example Using Correos Express
|
126
|
+
|
127
|
+
sender = Deliveries::Address.new(
|
128
|
+
name: '...',
|
129
|
+
email: 'sender@example.com',
|
130
|
+
phone: '...',
|
131
|
+
country: 'ES',
|
132
|
+
state: '...',
|
133
|
+
city: '...',
|
134
|
+
street: '...',
|
135
|
+
postcode: '...'
|
136
|
+
)
|
137
|
+
|
138
|
+
receiver = Deliveries::Address.new(
|
139
|
+
name: '...',
|
140
|
+
email: 'receiver@example.com',
|
141
|
+
phone: '...',
|
142
|
+
country: 'ES',
|
143
|
+
state: '...',
|
144
|
+
city: '...',
|
145
|
+
street: '...',
|
146
|
+
postcode: '...'
|
147
|
+
)
|
148
|
+
|
149
|
+
response = Deliveries.courier(:correos_express).create_shipment(
|
150
|
+
sender: sender,
|
151
|
+
receiver: receiver,
|
152
|
+
collection_point: nil,
|
153
|
+
parcels: 1,
|
154
|
+
reference_code: '...',
|
155
|
+
shipment_date: Date.tomorrow,
|
156
|
+
remarks: nil
|
157
|
+
)
|
158
|
+
```
|
159
|
+
|
160
|
+
#### Create a Pickup
|
161
|
+
```bash
|
162
|
+
# Example Using Spring
|
163
|
+
|
164
|
+
sender = Deliveries::Address.new(
|
165
|
+
name: '...',
|
166
|
+
email: 'sender@example.com',
|
167
|
+
phone: '...',
|
168
|
+
country: 'ES',
|
169
|
+
state: '...',
|
170
|
+
city: '...',
|
171
|
+
street: '...',
|
172
|
+
postcode: '...'
|
173
|
+
)
|
174
|
+
|
175
|
+
receiver = Deliveries::Address.new(
|
176
|
+
name: '...',
|
177
|
+
email: 'receiver@example.com',
|
178
|
+
phone: '...',
|
179
|
+
country: 'ES',
|
180
|
+
state: '...',
|
181
|
+
city: '...',
|
182
|
+
street: '...',
|
183
|
+
postcode: '...'
|
184
|
+
)
|
185
|
+
|
186
|
+
response = Deliveries.courier(:spring).create_pickup(
|
187
|
+
sender: sender,
|
188
|
+
receiver: receiver,
|
189
|
+
parcels: 1,
|
190
|
+
reference_code: '...',
|
191
|
+
pickup_date: 2.days.since.to_date
|
192
|
+
)
|
193
|
+
```
|
194
|
+
|
195
|
+
#### Download a Label
|
196
|
+
```bash
|
197
|
+
# Example Using Spring
|
198
|
+
|
199
|
+
label = Deliveries.courier(:spring).get_label(tracking_code: '...')
|
200
|
+
|
201
|
+
# And then, we can use it as follows
|
202
|
+
|
203
|
+
File.write('label.pdf', label.raw)
|
204
|
+
```
|
205
|
+
|
206
|
+
## License
|
207
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'deliveries'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/deliveries.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/deliveries/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'deliveries'
|
7
|
+
spec.version = Deliveries::VERSION
|
8
|
+
spec.authors = ['Fran Vega', 'Raúl Rodríguez', 'Roberto Martínez', 'Pedro Guerra']
|
9
|
+
spec.email = ['admin@micolet.com']
|
10
|
+
|
11
|
+
spec.summary = 'Library to abstract multiple courier web services.'
|
12
|
+
spec.homepage = 'https://github.com/ecommerce-ventures/deliveries'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.7')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ecommerce-ventures/deliveries'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ecommerce-ventures/deliveries/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_dependency 'activesupport', '>= 5.2.0'
|
28
|
+
spec.add_dependency 'hexapdf'
|
29
|
+
spec.add_dependency 'httparty'
|
30
|
+
spec.add_dependency 'mini_magick'
|
31
|
+
spec.add_dependency 'nokogiri'
|
32
|
+
spec.add_dependency 'savon', '~> 2.8'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'byebug'
|
35
|
+
spec.add_development_dependency 'webmock', '~> 3.5'
|
36
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Deliveries
|
2
|
+
class Address
|
3
|
+
attr_accessor :name, :email, :phone, :country, :state, :city, :street, :postcode
|
4
|
+
|
5
|
+
COUNTRY_PHONE_PREFIXES = {
|
6
|
+
be: 32,
|
7
|
+
fr: 33,
|
8
|
+
es: 34,
|
9
|
+
it: 39,
|
10
|
+
gb: 44,
|
11
|
+
de: 49,
|
12
|
+
pt: 351
|
13
|
+
}.freeze
|
14
|
+
COUNTRY_TRUNK_PREFIXES = {
|
15
|
+
be: 0,
|
16
|
+
fr: 0,
|
17
|
+
es: nil,
|
18
|
+
it: nil,
|
19
|
+
gb: 0,
|
20
|
+
de: 0,
|
21
|
+
pt: nil
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def initialize(**attributes)
|
25
|
+
self.name = attributes[:name]
|
26
|
+
self.email = attributes[:email]
|
27
|
+
self.phone = attributes[:phone]
|
28
|
+
self.country = attributes[:country]
|
29
|
+
self.state = attributes[:state]
|
30
|
+
self.city = attributes[:city]
|
31
|
+
self.street = attributes[:street]
|
32
|
+
self.postcode = attributes[:postcode]
|
33
|
+
end
|
34
|
+
|
35
|
+
def courierize(courier_id)
|
36
|
+
courier_address = %(Deliveries::Couriers::#{courier_id.to_s.camelize}::Address).safe_constantize.new
|
37
|
+
instance_variables.each do |iv|
|
38
|
+
courier_address.instance_variable_set(iv, instance_variable_get(iv))
|
39
|
+
end
|
40
|
+
courier_address
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def format_international_phone
|
46
|
+
return '' if @phone.blank? || @country.blank?
|
47
|
+
|
48
|
+
country = @country.downcase.to_sym
|
49
|
+
prefix = COUNTRY_PHONE_PREFIXES[country]
|
50
|
+
trunk_prefix = COUNTRY_TRUNK_PREFIXES[country]
|
51
|
+
|
52
|
+
# Remove white spaces.
|
53
|
+
tmp_phone = @phone.gsub(' ', '')
|
54
|
+
|
55
|
+
# Remove current prefix if present.
|
56
|
+
tmp_phone.gsub!(/\A(00|\+)#{prefix}/, '')
|
57
|
+
|
58
|
+
# Remove trunk prefix to convert it to international.
|
59
|
+
tmp_phone.gsub!(/\A#{trunk_prefix}/, '') if trunk_prefix
|
60
|
+
|
61
|
+
"+#{prefix}#{tmp_phone}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def format_email
|
65
|
+
return '' if @email.blank?
|
66
|
+
|
67
|
+
matches = @email.split(/[+@]/)
|
68
|
+
%(#{matches.first}@#{matches.last})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Deliveries
|
2
|
+
class Checkpoint
|
3
|
+
attr_accessor :status, :location, :tracked_at, :description
|
4
|
+
|
5
|
+
def initialize(status: nil, location: nil, tracked_at: nil, description: nil)
|
6
|
+
self.status = status
|
7
|
+
self.location = location
|
8
|
+
self.tracked_at = tracked_at
|
9
|
+
self.description = description
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Deliveries
|
2
|
+
class CollectionPoint < Address
|
3
|
+
attr_accessor :courier_id, :point_id, :latitude, :longitude, :url_map, :url_photo
|
4
|
+
attr_writer :timetable
|
5
|
+
|
6
|
+
def initialize(**attributes)
|
7
|
+
super(**attributes)
|
8
|
+
|
9
|
+
self.courier_id = attributes[:courier_id]
|
10
|
+
self.point_id = attributes[:point_id]
|
11
|
+
self.latitude = attributes[:latitude]
|
12
|
+
self.longitude = attributes[:longitude]
|
13
|
+
self.timetable = attributes[:timetable]
|
14
|
+
self.url_map = attributes[:url_map]
|
15
|
+
self.url_photo = attributes[:url_photo]
|
16
|
+
end
|
17
|
+
|
18
|
+
def global_point_id
|
19
|
+
"#{courier_id}~#{country}~#{postcode}~#{point_id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def timetable(start_day: :monday)
|
23
|
+
raise Error, "Invalid week start day: #{start_day}" unless %i[monday sunday].include?(start_day)
|
24
|
+
|
25
|
+
@timetable&.sort_by do |wday, _slots|
|
26
|
+
if wday.zero? && start_day == :monday
|
27
|
+
7
|
28
|
+
else
|
29
|
+
wday
|
30
|
+
end
|
31
|
+
end&.to_h
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse_global_point_id(global_point_id:)
|
35
|
+
global_point = global_point_id.split('~')
|
36
|
+
|
37
|
+
OpenStruct.new(
|
38
|
+
courier_id: global_point[0],
|
39
|
+
country: global_point[1],
|
40
|
+
postcode: global_point[2],
|
41
|
+
point_id: global_point[3]
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|