pombo 1.0.0.beta → 1.0.0.pre.alpha
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/.travis.yml +0 -1
- data/README.md +17 -205
- data/lib/pombo/configuration.rb +6 -29
- data/lib/pombo/exception.rb +1 -10
- data/lib/pombo/package/format.rb +10 -30
- data/lib/pombo/package/item.rb +0 -5
- data/lib/pombo/package.rb +5 -53
- data/lib/pombo/services.rb +35 -71
- data/lib/pombo/support.rb +1 -14
- data/lib/pombo/version.rb +1 -1
- data/lib/pombo/webservice/base.rb +1 -6
- data/lib/pombo/webservice/cpp/base_request.rb +0 -3
- data/lib/pombo/webservice/cpp/delivery_time_request.rb +1 -2
- data/lib/pombo/webservice/cpp/response.rb +2 -6
- data/lib/pombo/webservice/cpp/{service_response.rb → service.rb} +3 -6
- data/lib/pombo/webservice/cpp/shipping_request.rb +0 -2
- data/lib/pombo/webservice/cpp/shipping_value_request.rb +23 -2
- data/lib/pombo/webservice/cpp.rb +8 -9
- data/lib/pombo/webservice.rb +0 -1
- data/lib/pombo.rb +19 -32
- data/pombo.gemspec +15 -17
- metadata +7 -42
- data/CHANGELOG.md +0 -12
- data/lib/pombo/logger.rb +0 -17
- data/locales/en.yml +0 -87
- data/locales/pt-br.yml +0 -87
- data/readmes/README-EN.md +0 -223
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd144d6e1e25eb82dd55c488cd80f16a1c2f874b
|
4
|
+
data.tar.gz: 57544b7c52580cfed848aaeed9c8875f4139b8ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864dcbc1efce094de63fef6e5c89e3db5f428bcb4232cd525ec9cc603ba14878ca7ec9872bc7ec916fcda8204ac06738447bb088738b79cf93c457dcd9c13fa0
|
7
|
+
data.tar.gz: 3cb3a7a1dc2092e82664c2fbaad5b6bc613f18c4b42a15ee405c0dd4e3baf51dbf5704c53a2e95e848ab1d5c3037bcfcd995be3a2e41b6d8241a86c1fe37729b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
> ***
|
2
|
-
> Attention!
|
2
|
+
> Attention! It is strongly advised not to use this version in production
|
3
3
|
> ***
|
4
4
|
|
5
5
|
# Pombo
|
@@ -8,226 +8,38 @@
|
|
8
8
|
[](http://inch-ci.org/github/adenaecommerce/pombo)
|
9
9
|
[](http://www.rubydoc.info/github/adenaecommerce/pombo/master)
|
10
10
|
[](https://badge.fury.io/rb/pombo)
|
11
|
-
[](https://codeclimate.com/github/adenaecommerce/pombo)
|
12
11
|
|
13
|
-
|
14
|
-
de envio de encomendas
|
12
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pombo`. To experiment with that code, run `bin/console` for an interactive prompt.
|
15
13
|
|
16
|
-
|
14
|
+
TODO: Delete this and the text above, and describe your gem
|
17
15
|
|
18
|
-
|
19
|
-
* Permite consultar o valor do transporte de um pacote
|
20
|
-
* Permite consultar o prazo de envio de um pacote
|
21
|
-
* Permite consultar o valor e o prazo de envio de um pacote
|
22
|
-
* Suporta Internacionalização
|
23
|
-
* Aceita um logger compatível com a interface do [Log4r](http://log4r.rubyforge.org/index.html)
|
16
|
+
## Installation
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
$ gem install pombo
|
28
|
-
|
29
|
-
ou adiciona essa linha no seu Gemfile
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
gem 'pombo', '~> 1.0.0.beta'
|
33
|
-
```
|
34
|
-
|
35
|
-
e
|
36
|
-
|
37
|
-
$ bundle install
|
38
|
-
|
39
|
-
|
40
|
-
## Configuração
|
41
|
-
|
42
|
-
> Os dados retornados ao realizar uma consulta são os mesmos fornecidos em uma agência dos Correios. As empresas
|
43
|
-
> podem contratar um serviço diferenciado e usar o código do seu contrato ao utilizar o Pombo.
|
44
|
-
|
45
|
-
Para alterar as configurações padrão, utilize o `#setup`
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
Pombo.setup do |config|
|
49
|
-
config.contract_code = 'AA99BB'
|
50
|
-
config.password = '999999'
|
51
|
-
config.extends_delivery = 0
|
52
|
-
config.request_timeout = 5
|
53
|
-
config.log_level = Pombo::Logger::INFO
|
54
|
-
config.logger = Pombo::Logger.new(STDOUT)
|
55
|
-
config.locale = 'pt-BR'
|
56
|
-
end
|
57
|
-
```
|
58
|
-
|
59
|
-
Se você precisar modificar qualquer configuração em um determinado momento, use o `#set`
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
Pombo.set request_timeout: 10, locale: 'en'
|
63
|
-
```
|
64
|
-
|
65
|
-
> O `#set` não modifica as configurações default
|
66
|
-
|
67
|
-
## Formatos
|
68
|
-
|
69
|
-
Os formatos são objetos pré-definidos com informações fornecidas pelos Correios
|
70
|
-
Os Correios trabalha com os seguintes formatos: caixa, envelope e rolo. Todo item deve possuir um formato.
|
71
|
-
|
72
|
-
O formato do pacote é informado conforme os itens adicionado. Para mais de dois itens prevalece o formato caixa.
|
73
|
-
|
74
|
-
Listar todos os formatos suportados pelos serviços de entrega
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
Pombo::Package::Format.all
|
78
|
-
|
79
|
-
# => [
|
80
|
-
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
81
|
-
# => ....
|
82
|
-
# => ]
|
83
|
-
```
|
84
|
-
|
85
|
-
Encontrar um formato específico pelo código ou pelo nome
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
Pombo::Package::Format.find '3'
|
89
|
-
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
90
|
-
|
91
|
-
# ou
|
92
|
-
|
93
|
-
Pombo::Package::Format.find 'envelope'
|
94
|
-
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
95
|
-
```
|
96
|
-
|
97
|
-
## Serviços
|
98
|
-
|
99
|
-
Os serviços são objetos pré-definidos com informações fornecidas pelos Correios. Para saber mais [clique aqui](http://www.correios.com.br/para-voce/envio/encomendas/encomendas)
|
100
|
-
|
101
|
-
Listar todos os serviços de entrega suportados pelos Correios.
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
Pombo::Services.all
|
105
|
-
|
106
|
-
# => [
|
107
|
-
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">,
|
108
|
-
# => ....
|
109
|
-
# => ]
|
110
|
-
```
|
111
|
-
|
112
|
-
Listar todos os serviços de um grupo.
|
113
|
-
|
114
|
-
```ruby
|
115
|
-
Pombo::Services.all :pac
|
116
|
-
# => [
|
117
|
-
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">,
|
118
|
-
# => ....
|
119
|
-
# => ]
|
120
|
-
```
|
121
|
-
|
122
|
-
Encontrar um serviço pelo seu código.
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
Pombo::Services.find "41106"
|
126
|
-
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">
|
127
|
-
```
|
128
|
-
|
129
|
-
## Pacotes
|
130
|
-
|
131
|
-
Os pacotes são os objetos enviados ao webservice para que seja realizada a consulta. Ele é composto por vários
|
132
|
-
items, o CEP de origem e o CEP de destino e alguns serviços opcionais, [veja aqui](https://www.correios.com.br/para-voce/envio/encomendas/servicos-opcionais)
|
133
|
-
|
134
|
-
Criando um pacote:
|
18
|
+
Add this line to your application's Gemfile:
|
135
19
|
|
136
20
|
```ruby
|
137
|
-
|
138
|
-
destination_zip_code: '29160565',
|
139
|
-
origin_zip_code: '29108046',
|
140
|
-
services: "40010",
|
141
|
-
in_hand: false,
|
142
|
-
delivery_notice: false
|
143
|
-
})
|
144
|
-
# => <Pombo::Package:0x007fcfd32080f0 @items=[], @length=0, @height=0, @width=0, @declared_value=0, @destination_zip_code="29160565", @origin_zip_code="29108046">
|
21
|
+
gem 'pombo'
|
145
22
|
```
|
146
23
|
|
147
|
-
|
148
|
-
> `Pombo::Package.new services: ["40010", "41068", "40568"]`
|
24
|
+
And then execute:
|
149
25
|
|
150
|
-
|
26
|
+
$ bundle
|
151
27
|
|
152
|
-
|
153
|
-
item = Pombo::Package::Item.new weight: 10, length: 17, height: 22, width: 22
|
154
|
-
package.add_item item
|
155
|
-
```
|
156
|
-
|
157
|
-
ou pode ser informado um hash
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
package.add_item weight: 10, length: 15, height: 5, width: 10
|
161
|
-
```
|
162
|
-
|
163
|
-
Agora podemos obter várias informações
|
164
|
-
|
165
|
-
```ruby
|
166
|
-
package.in_hand? # => false
|
167
|
-
package.delivery_notice? # => false
|
168
|
-
package.weight # => 10
|
169
|
-
package.diameter # => 0
|
170
|
-
package.format # => 1
|
171
|
-
package.volume # => 8228.0
|
172
|
-
package.single_item? # => true
|
173
|
-
```
|
28
|
+
Or install it yourself as:
|
174
29
|
|
175
|
-
|
176
|
-
|
177
|
-
Para realizar uma consulta para saber o valor e o prazo de entrega
|
178
|
-
|
179
|
-
```ruby
|
180
|
-
Pombo.shipping package
|
181
|
-
# => [
|
182
|
-
# => [0] #<Pombo::Webservice::CPP::Service:0x007fae1cd9d1a0 @code="40010", @value=31.3, @delivery_time="1", @value_in_hand=0.0, @value_delivery_notice=0.0, @value_declared_value=0.0, @error_code="0", @value_without_additions=31.3, @delivery_home=true, @delivery_sartuday=true>
|
183
|
-
# => ]
|
184
|
-
```
|
185
|
-
|
186
|
-
Para realizar uma consulta para saber o prazo de entrega
|
187
|
-
|
188
|
-
```ruby
|
189
|
-
Pombo.delivery_time package
|
190
|
-
# => [
|
191
|
-
# => [0] #<Pombo::Webservice::CPP::Service:0x007fae1da0b040 @code="40010", @delivery_time="1", @delivery_home=true, @delivery_sartuday=true>
|
192
|
-
# => ]
|
193
|
-
```
|
194
|
-
|
195
|
-
Para realizar uma consulta para saber o valor da entrega
|
196
|
-
|
197
|
-
```ruby
|
198
|
-
Pombo.shipping_value package
|
199
|
-
# => [
|
200
|
-
# => [0] #<Pombo::Webservice::CPP::Service:0x007fae1d1cb740 @code="40010", @value=31.3, @value_in_hand=0.0, @value_delivery_notice=0.0, @value_declared_value=0.0, @value_without_additions=31.3>
|
201
|
-
# => ]
|
202
|
-
```
|
203
|
-
|
204
|
-
## Log
|
205
|
-
|
206
|
-
Pombo aceita qualquer sistema de logger compatível com a interface do [Log4r](http://log4r.rubyforge.org/index.html).
|
207
|
-
|
208
|
-
Temos nosso próprio objeto de logger, `Pombo::Logger`, que por padrão envia as mensagens para a `STDOUT` do sistema e o nível é INFO.
|
30
|
+
$ gem install pombo
|
209
31
|
|
210
|
-
|
211
|
-
Pombo.logger.info('event.namespace'){ 'Any error message' }
|
212
|
-
# => 2016-05-13 15:15:49 -0300 | POMBO | event.namespace | INFO: Any error message
|
213
|
-
```
|
32
|
+
## Usage
|
214
33
|
|
215
|
-
|
34
|
+
TODO: Write usage instructions here
|
216
35
|
|
217
|
-
|
218
|
-
Pombo.setup do |config|
|
219
|
-
config.log_level = Pombo::Logger::INFO
|
220
|
-
config.logger = Pombo::Logger.new('caminho do arquivo')
|
221
|
-
end
|
222
|
-
```
|
36
|
+
## Development
|
223
37
|
|
224
|
-
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
225
39
|
|
226
|
-
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
227
41
|
|
228
|
-
|
229
|
-
Você pode nos enviar a sua colaboração, mas deve aderir ao código de conduta [Contributor Covenant](http://contributor-covenant.org).
|
42
|
+
## Contributing
|
230
43
|
|
231
|
-
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pombo. 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.
|
232
45
|
|
233
|
-
MIT License. Veja o arquivo MIT-LICENSE.
|
data/lib/pombo/configuration.rb
CHANGED
@@ -1,59 +1,36 @@
|
|
1
1
|
module Pombo
|
2
|
-
# It allows you to modify the settings of Pombo
|
3
|
-
# @!attribute [rw] contract_code
|
4
|
-
# Its administrative code by the ECT
|
5
|
-
# @!attribute [rw] password
|
6
|
-
# Password to access the service, associated with its contract code
|
7
|
-
# @!attribute [rw] extends_delivery
|
8
|
-
# Days late on a package
|
9
|
-
# @!attribute [rw] request_timeout
|
10
|
-
# Second delay when accessing the webservice
|
11
|
-
# @!attribute [rw] log_level
|
12
|
-
# Level compatible with Ruby Logger
|
13
|
-
# @!attribute [rw] logger
|
14
|
-
# Object to trigger messages (defaults to +Pombo::Logger+)
|
15
|
-
# @!attribute [rw] locale
|
16
|
-
# Tells you what language will be used (defaults to `pt-BR`)
|
17
2
|
class Configuration
|
18
3
|
@@default = {
|
19
4
|
contract_code: nil,
|
20
5
|
password: nil,
|
21
6
|
extends_delivery: 0,
|
22
|
-
log_level:
|
23
|
-
logger:
|
24
|
-
request_timeout: 5
|
25
|
-
locale: 'pt-BR'
|
7
|
+
log_level: :info,
|
8
|
+
logger: :logger,
|
9
|
+
request_timeout: 5
|
26
10
|
}
|
27
11
|
|
28
|
-
attr_accessor :contract_code, :password, :extends_delivery, :log_level, :logger, :request_timeout
|
12
|
+
attr_accessor :contract_code, :password, :extends_delivery, :log_level, :logger, :request_timeout
|
29
13
|
|
30
14
|
def initialize(**args)
|
31
15
|
args = @@default.merge(args)
|
32
16
|
args.each { |key, value| __send__("#{ key }=", value) }
|
33
|
-
|
34
|
-
logger.level = log_level
|
35
17
|
end
|
36
18
|
|
37
19
|
# Saves the current state of the standard as an object
|
38
|
-
# @return [
|
20
|
+
# @return [Hash] The new default settings
|
39
21
|
def set_default
|
40
22
|
attributes = {}
|
41
23
|
instance_variables.each{ |v| attributes[v.to_s.delete('@').to_sym] = instance_variable_get(v) }
|
42
24
|
@@default.merge!(attributes)
|
43
|
-
Pombo.logger.info('update.configuration'){ 'Update the default settings' }
|
44
|
-
self
|
45
25
|
end
|
46
26
|
|
47
27
|
# Inform settings for persisting with default
|
48
|
-
# @
|
49
|
-
# @return [Pombo::Configuration] the updated settings
|
50
|
-
# @raise [Pombo::ConfigurationError] if not passed a block
|
28
|
+
# @see Pombo.setup
|
51
29
|
def self.setup(&block)
|
52
30
|
if block_given?
|
53
31
|
config = new
|
54
32
|
block.call config
|
55
33
|
config.set_default
|
56
|
-
self
|
57
34
|
else
|
58
35
|
raise Pombo::ConfigurationError, 'expected block the .setup'
|
59
36
|
end
|
data/lib/pombo/exception.rb
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
module Pombo
|
2
|
-
|
3
|
-
class Error < StandardError
|
4
|
-
def initializer(msg = nil)
|
5
|
-
super
|
2
|
+
class Error < StandardError; end
|
6
3
|
|
7
|
-
Pombo.logger.error('exception.pombo') { msg }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Exception triggered to manage settings
|
12
4
|
class ConfigurationError < Pombo::Error; end
|
13
5
|
|
14
|
-
# Exception triggered when managing the webservice
|
15
6
|
class WebserviceError < Pombo::Error; end
|
16
7
|
end
|
data/lib/pombo/package/format.rb
CHANGED
@@ -1,44 +1,24 @@
|
|
1
1
|
module Pombo
|
2
2
|
class Package
|
3
|
-
# The formats are pre-defined objects with the information provided by the Correios
|
4
3
|
module Format
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# # => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
12
|
-
# # => ....
|
13
|
-
# # => ]
|
14
|
-
#
|
4
|
+
@@all_formats = {
|
5
|
+
'1' => OpenStruct.new(code: 1, name: 'Caixa/Pacote', max_length: 105, min_length: 16, max_height: 105, min_height: 2, max_width: 105, min_width: 11, max_dimension: 200),
|
6
|
+
'2' => OpenStruct.new(code: 2, name: 'Rolo/Prisma', max_length: 105, min_length: 18, max_diameter: 91, min_diameter: 5, max_dimension: 200),
|
7
|
+
'3' => OpenStruct.new(code: 3, name: 'Envelope', max_length: 60, min_length: 16, max_width: 60, min_width: 11, max_weight: 1),
|
8
|
+
}
|
9
|
+
|
15
10
|
def self.all
|
16
|
-
|
17
|
-
OpenStruct.new(code: 1, name: Pombo.t('formats.1'), max_length: 105, min_length: 16, max_height: 105, min_height: 2, max_width: 105, min_width: 11, max_dimension: 200),
|
18
|
-
OpenStruct.new(code: 2, name: Pombo.t('formats.2'), max_length: 105, min_length: 18, max_diameter: 91, min_diameter: 5, max_dimension: 200),
|
19
|
-
OpenStruct.new(code: 3, name: Pombo.t('formats.3'), max_length: 60, min_length: 16, max_width: 60, min_width: 11, max_weight: 1),
|
20
|
-
]
|
11
|
+
@@all_formats.values
|
21
12
|
end
|
22
13
|
|
23
|
-
# Find a specific format by code or by name
|
24
|
-
# @return [OpenStruct] the data structure representing a format
|
25
|
-
# @param code [String] code or the format name, to box `1, box or package`, to roll `2, roll or prism` and to envelope `3 or envelope`
|
26
|
-
# @example
|
27
|
-
# Pombo::Package::Format.find '3'
|
28
|
-
# # => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
29
|
-
#
|
30
|
-
# # => Or
|
31
|
-
#
|
32
|
-
# Pombo::Package::Format.find 'envelope'
|
33
|
-
# # => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
34
14
|
def self.find(code)
|
35
15
|
case code.to_s
|
36
16
|
when '1', 'box', 'package'
|
37
|
-
|
17
|
+
@@all_formats.values_at('1').first
|
38
18
|
when '2', 'roll', 'prism'
|
39
|
-
|
19
|
+
@@all_formats.values_at('2').first
|
40
20
|
when '3', 'envelope'
|
41
|
-
|
21
|
+
@@all_formats.values_at('3').first
|
42
22
|
end
|
43
23
|
end
|
44
24
|
end
|
data/lib/pombo/package/item.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
module Pombo
|
2
|
-
# Item is the object that will be sent in the package through the Brazilian Post Service
|
3
|
-
#
|
4
|
-
# By default the quantity is 1 and the format is +Pombo::Package::Format.find(:box).code+
|
5
2
|
class Package::Item
|
6
3
|
attr_accessor :weight, :length, :height, :width, :diameter, :quantity, :format
|
7
4
|
|
@@ -10,8 +7,6 @@ module Pombo
|
|
10
7
|
args.each { |key, value| __send__("#{ key }=", value) }
|
11
8
|
end
|
12
9
|
|
13
|
-
# Calculates the volume item in accordance with the format
|
14
|
-
# @return [Float] the volume value
|
15
10
|
def volume
|
16
11
|
case format
|
17
12
|
when Pombo::Package::Format.find(:box).code
|
data/lib/pombo/package.rb
CHANGED
@@ -1,25 +1,4 @@
|
|
1
1
|
module Pombo
|
2
|
-
# This is the composite package of items that will be sent
|
3
|
-
#
|
4
|
-
# @example
|
5
|
-
# package = Pombo::Package.new ({
|
6
|
-
# destination_zip_code: '29999000',
|
7
|
-
# origin_zip_code: '28888000',
|
8
|
-
# services: "40010",
|
9
|
-
# in_hand: false,
|
10
|
-
# delivery_notice: false
|
11
|
-
# })
|
12
|
-
# # => <Pombo::Package:0x007fcfd32080f0 @items=[], @length=0, @height=0, @width=0, @declared_value=0, @destination_zip_code="29999000", @origin_zip_code="28888000">
|
13
|
-
#
|
14
|
-
# package.add_item weight: 5, length: 4, height: 3, width: 5, diameter: 0
|
15
|
-
# package.add_item weight: 4, length: 10, height: 5, width: 5, diameter: 5, format: Pombo::Package::Format.find(:roll).code
|
16
|
-
# package.in_hand? # => false
|
17
|
-
# package.delivery_notice? # => false
|
18
|
-
# package.weight # => 9
|
19
|
-
# package.diameter # => 0
|
20
|
-
# package.format # => 1
|
21
|
-
# package.volume # => 158.17000000000002
|
22
|
-
# package.single_item? # => false
|
23
2
|
class Package
|
24
3
|
attr_accessor :destination_zip_code, :origin_zip_code, :declared_value
|
25
4
|
attr_reader :items, :length, :height, :width, :services
|
@@ -30,10 +9,6 @@ module Pombo
|
|
30
9
|
args.each { |key, value| __send__("#{ key }=", value) }
|
31
10
|
end
|
32
11
|
|
33
|
-
# @!method in_hand?
|
34
|
-
# Informs you are contracted delivery in hand service
|
35
|
-
# @!method delivery_notice?
|
36
|
-
# Informs you are contracted delivery notice service
|
37
12
|
%i[in_hand delivery_notice].each do |method|
|
38
13
|
define_method("#{ method }?"){ instance_variable_get "@#{ method }" }
|
39
14
|
end
|
@@ -50,58 +25,40 @@ module Pombo
|
|
50
25
|
end
|
51
26
|
end
|
52
27
|
|
53
|
-
# The services used to send the package
|
54
|
-
# @return [Array<String>] codes services
|
55
28
|
def services=(services)
|
56
29
|
@services = services.kind_of?(Array) ? services : [services]
|
57
30
|
end
|
58
31
|
|
59
|
-
# It allows you to add an item to the package
|
60
|
-
# @return [Pombo::Package::Item] the added item
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
# item = Pombo::Package::Item.new weight: 5, length: 4, height: 3, width: 5, diameter: 0
|
64
|
-
# package.add_item item
|
65
|
-
#
|
66
|
-
# # => or
|
67
|
-
#
|
68
|
-
# package.add_item weight: 5, length: 4, height: 3, width: 5, diameter: 0
|
69
32
|
def add_item(item = nil, **args)
|
70
33
|
item = if item.kind_of?(Pombo::Package::Item)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
34
|
+
item
|
35
|
+
else
|
36
|
+
Pombo::Package::Item.new(args)
|
37
|
+
end
|
75
38
|
|
76
39
|
@items << item
|
77
40
|
update_measures
|
78
41
|
item
|
79
42
|
end
|
80
43
|
|
81
|
-
# @return [Float] the total weight of the items
|
82
44
|
def weight
|
83
45
|
@items.inject(0) { |sum, item| sum += item.weight }
|
84
46
|
end
|
85
47
|
|
86
|
-
# @return [Float] the total diameter of the items
|
87
48
|
def diameter
|
88
49
|
return @items.first.diameter if single_item? && format == Pombo::Package::Format.find(:roll).code
|
89
50
|
0
|
90
51
|
end
|
91
52
|
|
92
|
-
# @return [Fixnum] the code of the packet format
|
93
|
-
# For packages with more than one item format will be 1 (:box)
|
94
53
|
def format
|
95
54
|
return @items.first.format if single_item?
|
96
55
|
Pombo::Package::Format.find(:box).code
|
97
56
|
end
|
98
57
|
|
99
|
-
# @return [Float] the total volume of the items
|
100
58
|
def volume
|
101
59
|
@items.inject(0) { |sum, item| sum += item.volume }
|
102
60
|
end
|
103
61
|
|
104
|
-
# @return [Boolean] tells if the package contains only one item
|
105
62
|
def single_item?
|
106
63
|
@items.size == 1 && @items.first.quantity == 1
|
107
64
|
end
|
@@ -109,12 +66,7 @@ module Pombo
|
|
109
66
|
private
|
110
67
|
|
111
68
|
def update_measures
|
112
|
-
|
113
|
-
item = @items.first
|
114
|
-
@length, @height, @width = item.length, item.height, item.width
|
115
|
-
else
|
116
|
-
@length = @height = @width = Math.cbrt volume
|
117
|
-
end
|
69
|
+
@length = @height = @width = Math.cbrt volume
|
118
70
|
end
|
119
71
|
end
|
120
72
|
end
|
data/lib/pombo/services.rb
CHANGED
@@ -1,88 +1,52 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module Pombo
|
4
|
-
# Contains delivery services
|
5
4
|
module Services
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
5
|
+
@@all_pac = {
|
6
|
+
"41106" => OpenStruct.new(code: "41106", max_weight: 30, name: 'PAC', description: 'PAC (sem contrato)'),
|
7
|
+
"41068" => OpenStruct.new(code: "41068", max_weight: 50, name: 'PAC', description: 'PAC (com contrato)'),
|
8
|
+
"41300" => OpenStruct.new(code: "41300", max_weight: 600, name: 'PAC GF', description: 'PAC (grandes formatos)')
|
9
|
+
}
|
10
|
+
|
11
|
+
@@all_sedex = {
|
12
|
+
"40010" => OpenStruct.new(code: "40010", max_weight: 30, name: 'SEDEX', description: 'SEDEX (sem contrato)'),
|
13
|
+
"40045" => OpenStruct.new(code: "40045", max_weight: 30, name: 'SEDEX a cobrar', description: 'SEDEX a cobrar (sem contrato)'),
|
14
|
+
"40126" => OpenStruct.new(code: "40126", max_weight: 30, name: 'SEDEX a cobrar', description: 'SEDEX a cobrar (com contrato)'),
|
15
|
+
"40215" => OpenStruct.new(code: "40215", max_weight: 10, name: 'SEDEX 10', description: 'SEDEX 10 (sem contrato)'),
|
16
|
+
"40290" => OpenStruct.new(code: "40290", max_weight: 10, name: 'SEDEX hoje', description: 'SEDEX hoje (sem contrato)'),
|
17
|
+
"40096" => OpenStruct.new(code: "40096", max_weight: 30, name: 'SEDEX', description: 'SEDEX (com contrato)'),
|
18
|
+
"40436" => OpenStruct.new(code: "40436", max_weight: 30, name: 'SEDEX', description: 'SEDEX (com contrato)'),
|
19
|
+
"40444" => OpenStruct.new(code: "40444", max_weight: 30, name: 'SEDEX', description: 'SEDEX (com contrato)'),
|
20
|
+
"40568" => OpenStruct.new(code: "40568", max_weight: 30, name: 'SEDEX', description: 'SEDEX (com contrato)'),
|
21
|
+
"40606" => OpenStruct.new(code: "40606", max_weight: 30, name: 'SEDEX', description: 'SEDEX (com contrato)')
|
22
|
+
}
|
23
|
+
|
24
|
+
@@all_e_sedex = {
|
25
|
+
"81019" => OpenStruct.new(code: "81019", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX (com contrato)'),
|
26
|
+
"81027" => OpenStruct.new(code: "81027", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX Prioritário (com contrato)'),
|
27
|
+
"81035" => OpenStruct.new(code: "81035", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX Express (com contrato)'),
|
28
|
+
"81868" => OpenStruct.new(code: "81868", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX (com contrato, grupo 1)'),
|
29
|
+
"81833" => OpenStruct.new(code: "81833", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX (com contrato, grupo 2)'),
|
30
|
+
"81850" => OpenStruct.new(code: "81850", max_weight: 15, name: 'E-SEDEX', description: 'E-SEDEX (com contrato, grupo 3)')
|
31
|
+
}
|
32
|
+
|
33
|
+
@@all_services = @@all_pac.merge(@@all_sedex).merge(@@all_e_sedex)
|
34
|
+
|
26
35
|
def self.all(service = nil)
|
27
36
|
case service
|
28
37
|
when :pac
|
29
|
-
all_pac.values
|
38
|
+
@@all_pac.values
|
30
39
|
when :sedex
|
31
|
-
all_sedex.values
|
40
|
+
@@all_sedex.values
|
32
41
|
when :e_sedex
|
33
|
-
all_e_sedex.values
|
42
|
+
@@all_e_sedex.values
|
34
43
|
else
|
35
|
-
all_pac.values + all_sedex.values + all_e_sedex.values
|
44
|
+
@@all_pac.values + @@all_sedex.values + @@all_e_sedex.values
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
39
|
-
# Search for a service code
|
40
|
-
# @return [OpenStruct] the data structure representing a service
|
41
|
-
# @example
|
42
|
-
# Pombo::Services.find "41106"
|
43
|
-
# # => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (without contract)">
|
44
48
|
def self.find(code)
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def self.all_pac
|
51
|
-
{
|
52
|
-
"41106" => OpenStruct.new(code: "41106", max_weight: 30, name: 'PAC', description: Pombo.t('services.pac.41106')),
|
53
|
-
"41068" => OpenStruct.new(code: "41068", max_weight: 50, name: 'PAC', description: Pombo.t('services.pac.41068')),
|
54
|
-
"41300" => OpenStruct.new(code: "41300", max_weight: 600, name: 'PAC GF', description: Pombo.t('services.pac.41300'))
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.all_sedex
|
59
|
-
{
|
60
|
-
"40010" => OpenStruct.new(code: "40010", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40010')),
|
61
|
-
"40045" => OpenStruct.new(code: "40045", max_weight: 30, name: 'SEDEX a cobrar', description: Pombo.t('services.sedex.40045')),
|
62
|
-
"40126" => OpenStruct.new(code: "40126", max_weight: 30, name: 'SEDEX a cobrar', description: Pombo.t('services.sedex.40126')),
|
63
|
-
"40215" => OpenStruct.new(code: "40215", max_weight: 10, name: 'SEDEX 10', description: Pombo.t('services.sedex.40215')),
|
64
|
-
"40290" => OpenStruct.new(code: "40290", max_weight: 10, name: 'SEDEX hoje', description: Pombo.t('services.sedex.40290')),
|
65
|
-
"40096" => OpenStruct.new(code: "40096", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40096')),
|
66
|
-
"40436" => OpenStruct.new(code: "40436", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40436')),
|
67
|
-
"40444" => OpenStruct.new(code: "40444", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40444')),
|
68
|
-
"40568" => OpenStruct.new(code: "40568", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40568')),
|
69
|
-
"40606" => OpenStruct.new(code: "40606", max_weight: 30, name: 'SEDEX', description: Pombo.t('services.sedex.40606'))
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.all_e_sedex
|
74
|
-
{
|
75
|
-
"81019" => OpenStruct.new(code: "81019", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81019')),
|
76
|
-
"81027" => OpenStruct.new(code: "81027", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81027')),
|
77
|
-
"81035" => OpenStruct.new(code: "81035", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81035')),
|
78
|
-
"81868" => OpenStruct.new(code: "81868", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81868')),
|
79
|
-
"81833" => OpenStruct.new(code: "81833", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81833')),
|
80
|
-
"81850" => OpenStruct.new(code: "81850", max_weight: 15, name: 'E-SEDEX', description: Pombo.t('services.e_sedex.81850'))
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.all_services
|
85
|
-
all_pac.merge(all_sedex).merge(all_e_sedex)
|
49
|
+
@@all_services.values_at(code).first
|
86
50
|
end
|
87
51
|
end
|
88
52
|
end
|