pombo 1.0.0.pre.alpha → 1.0.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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +13 -0
- data/README.md +209 -17
- data/lib/pombo.rb +32 -19
- data/lib/pombo/configuration.rb +42 -14
- data/lib/pombo/exception.rb +10 -1
- data/lib/pombo/logger.rb +17 -0
- data/lib/pombo/package.rb +74 -6
- data/lib/pombo/package/format.rb +30 -10
- data/lib/pombo/package/item.rb +5 -0
- data/lib/pombo/services.rb +71 -35
- data/lib/pombo/support.rb +14 -1
- data/lib/pombo/version.rb +1 -1
- data/lib/pombo/webservice.rb +1 -0
- data/lib/pombo/webservice/base.rb +6 -1
- data/lib/pombo/webservice/cpp.rb +9 -8
- data/lib/pombo/webservice/cpp/base_request.rb +3 -0
- data/lib/pombo/webservice/cpp/delivery_time_request.rb +2 -1
- data/lib/pombo/webservice/cpp/response.rb +6 -2
- data/lib/pombo/webservice/cpp/service_response.rb +67 -0
- data/lib/pombo/webservice/cpp/shipping_request.rb +2 -0
- data/lib/pombo/webservice/cpp/shipping_value_request.rb +2 -23
- data/locales/en.yml +87 -0
- data/locales/pt-br.yml +87 -0
- data/pombo.gemspec +18 -16
- data/readmes/README-EN.md +226 -0
- metadata +45 -9
- data/lib/pombo/webservice/cpp/service.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b0cfc72f11328171c4eb9ce98a535b8608cb506
|
4
|
+
data.tar.gz: 297396f9ddbe75fa891903851df087006aca8037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d2f7399f38be5b1530bf49ff1db6967b4846ddd0779013770b87dff76e5f5f09aa431cfe179e62f0c890bc6a8c42c029a8cd3396bf6354045bc59f63b80863
|
7
|
+
data.tar.gz: dba0c988653622fb9b247e0390dd45384b64e0ab87feea3668bcbe919b4bf3727245a8cd9dc214828df7f63d7348e8ba4df463277d8c13bece78b7cf48636218
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## v1.0.0
|
2
|
+
|
3
|
+
#### New features
|
4
|
+
|
5
|
+
* It allows you to change the default settings
|
6
|
+
* It allows you to change the runtime settings
|
7
|
+
* Allows the creation of packages with items
|
8
|
+
* It is used to quote a package even if it does not reach the minimum dimensions
|
9
|
+
* Allows the service value of consultation
|
10
|
+
* Allows consultation of service delivery time
|
11
|
+
* It allows you to see the value and service delivery time
|
12
|
+
* It supports internationalization
|
13
|
+
* Accepts a logger compatible with the interface [Log4r](http://log4r.rubyforge.org/index.html)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
> ***
|
2
|
-
> Attention!
|
2
|
+
> Attention! if you are looking for documentation in English, [click here!](readmes/README-EN.md)
|
3
3
|
> ***
|
4
4
|
|
5
5
|
# Pombo
|
@@ -8,38 +8,230 @@
|
|
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)
|
11
12
|
|
12
|
-
|
13
|
+
Pombo é uma gem que permite a utilização do webervice dos [Correios](http://correios.com.br/para-voce) para consulta de informacões
|
14
|
+
de envio de encomendas
|
13
15
|
|
14
|
-
|
16
|
+
## Funcionalidades
|
15
17
|
|
16
|
-
|
18
|
+
* Permite montar um pacote com vários itens
|
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)
|
17
24
|
|
18
|
-
|
25
|
+
## Instalação
|
26
|
+
|
27
|
+
$ gem install pombo
|
28
|
+
|
29
|
+
ou adiciona essa linha no seu Gemfile
|
19
30
|
|
20
31
|
```ruby
|
21
|
-
gem 'pombo'
|
32
|
+
gem 'pombo', '~> 1.0.0.beta'
|
22
33
|
```
|
23
34
|
|
24
|
-
|
35
|
+
e
|
25
36
|
|
26
|
-
$ bundle
|
37
|
+
$ bundle install
|
27
38
|
|
28
|
-
Or install it yourself as:
|
29
39
|
|
30
|
-
|
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.min_package = true
|
53
|
+
config.request_timeout = 5
|
54
|
+
config.log_level = Pombo::Logger::INFO
|
55
|
+
config.logger = Pombo::Logger.new(STDOUT)
|
56
|
+
config.locale = 'pt-BR'
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
> Os pacotes enviados pelos Correios possuem limitações de tamanho, usando a opção `min_package` você pode informar se caso o pacote não
|
61
|
+
> atinga as dimensões mínimas, que seja realizada a cotação com os tamanhos mínimos permitidos.
|
62
|
+
|
63
|
+
Se você precisar modificar qualquer configuração em um determinado momento, use o `#set`
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Pombo.set request_timeout: 10, locale: 'en'
|
67
|
+
```
|
68
|
+
|
69
|
+
> O `#set` não modifica as configurações default
|
70
|
+
|
71
|
+
## Formatos
|
72
|
+
|
73
|
+
Os formatos são objetos pré-definidos com informações fornecidas pelos Correios
|
74
|
+
Os Correios trabalha com os seguintes formatos: caixa, envelope e rolo. Todo item deve possuir um formato.
|
75
|
+
|
76
|
+
O formato do pacote é informado conforme os itens adicionado. Para mais de dois itens prevalece o formato caixa.
|
77
|
+
|
78
|
+
Listar todos os formatos suportados pelos serviços de entrega
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Pombo::Package::Format.all
|
31
82
|
|
32
|
-
|
83
|
+
# => [
|
84
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
85
|
+
# => ....
|
86
|
+
# => ]
|
87
|
+
```
|
88
|
+
|
89
|
+
Encontrar um formato específico pelo código ou pelo nome
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Pombo::Package::Format.find '3'
|
93
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
94
|
+
|
95
|
+
# ou
|
33
96
|
|
34
|
-
|
97
|
+
Pombo::Package::Format.find 'envelope'
|
98
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
99
|
+
```
|
100
|
+
|
101
|
+
## Serviços
|
102
|
+
|
103
|
+
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)
|
104
|
+
|
105
|
+
Listar todos os serviços de entrega suportados pelos Correios.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Pombo::Services.all
|
109
|
+
|
110
|
+
# => [
|
111
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">,
|
112
|
+
# => ....
|
113
|
+
# => ]
|
114
|
+
```
|
115
|
+
|
116
|
+
Listar todos os serviços de um grupo.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
Pombo::Services.all :pac
|
120
|
+
# => [
|
121
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">,
|
122
|
+
# => ....
|
123
|
+
# => ]
|
124
|
+
```
|
125
|
+
|
126
|
+
Encontrar um serviço pelo seu código.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
Pombo::Services.find "41106"
|
130
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (sem contrato)">
|
131
|
+
```
|
35
132
|
|
36
|
-
##
|
133
|
+
## Pacotes
|
134
|
+
|
135
|
+
Os pacotes são os objetos enviados ao webservice para que seja realizada a consulta. Ele é composto por vários
|
136
|
+
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)
|
137
|
+
|
138
|
+
Criando um pacote:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
package = Pombo::Package.new ({
|
142
|
+
destination_zip_code: '29160565',
|
143
|
+
origin_zip_code: '29108046',
|
144
|
+
services: "40010",
|
145
|
+
in_hand: false,
|
146
|
+
delivery_notice: false
|
147
|
+
})
|
148
|
+
# => <Pombo::Package:0x007fcfd32080f0 @items=[], @length=0, @height=0, @width=0, @declared_value=0, @destination_zip_code="29160565", @origin_zip_code="29108046">
|
149
|
+
```
|
150
|
+
|
151
|
+
> Pode ser informador um array de serviços para realizar a consulta em vários serviços.
|
152
|
+
> `Pombo::Package.new services: ["40010", "41068", "40568"]`
|
153
|
+
|
154
|
+
Adicionando items:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
item = Pombo::Package::Item.new weight: 10, length: 17, height: 22, width: 22
|
158
|
+
package.add_item item
|
159
|
+
```
|
160
|
+
|
161
|
+
ou pode ser informado um hash
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
package.add_item weight: 10, length: 15, height: 5, width: 10
|
165
|
+
```
|
166
|
+
|
167
|
+
Agora podemos obter várias informações
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
package.in_hand? # => false
|
171
|
+
package.delivery_notice? # => false
|
172
|
+
package.weight # => 10
|
173
|
+
package.diameter # => 0
|
174
|
+
package.format # => 1
|
175
|
+
package.volume # => 8228.0
|
176
|
+
package.single_item? # => true
|
177
|
+
```
|
178
|
+
|
179
|
+
## Utilizando o Pombo
|
180
|
+
|
181
|
+
Para realizar uma consulta para saber o valor e o prazo de entrega
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
Pombo.shipping package
|
185
|
+
# => [
|
186
|
+
# => [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>
|
187
|
+
# => ]
|
188
|
+
```
|
189
|
+
|
190
|
+
Para realizar uma consulta para saber o prazo de entrega
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
Pombo.delivery_time package
|
194
|
+
# => [
|
195
|
+
# => [0] #<Pombo::Webservice::CPP::Service:0x007fae1da0b040 @code="40010", @delivery_time="1", @delivery_home=true, @delivery_sartuday=true>
|
196
|
+
# => ]
|
197
|
+
```
|
198
|
+
|
199
|
+
Para realizar uma consulta para saber o valor da entrega
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
Pombo.shipping_value package
|
203
|
+
# => [
|
204
|
+
# => [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>
|
205
|
+
# => ]
|
206
|
+
```
|
207
|
+
|
208
|
+
## Log
|
209
|
+
|
210
|
+
Pombo aceita qualquer sistema de logger compatível com a interface do [Log4r](http://log4r.rubyforge.org/index.html).
|
211
|
+
|
212
|
+
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.
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
Pombo.logger.info('event.namespace'){ 'Any error message' }
|
216
|
+
# => 2016-05-13 15:15:49 -0300 | POMBO | event.namespace | INFO: Any error message
|
217
|
+
```
|
218
|
+
|
219
|
+
Para gravar em arquivo, você pode fazer algo parecido com isso:
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
Pombo.setup do |config|
|
223
|
+
config.log_level = Pombo::Logger::INFO
|
224
|
+
config.logger = Pombo::Logger.new('caminho do arquivo')
|
225
|
+
end
|
226
|
+
```
|
37
227
|
|
38
|
-
|
228
|
+
## Como contribuir
|
39
229
|
|
40
|
-
|
230
|
+
Pombo é mantido pelo time de desenvolvimento da [Adena E-commerce Platform](http://www.adena.com.br/).
|
41
231
|
|
42
|
-
|
232
|
+
Relatórios de Bugs e pull requests são bem vindos no GitHub em https://github.com/adenaecommerce/pombo.
|
233
|
+
Você pode nos enviar a sua colaboração, mas deve aderir ao código de conduta [Contributor Covenant](http://contributor-covenant.org).
|
43
234
|
|
44
|
-
|
235
|
+
## Licença
|
45
236
|
|
237
|
+
MIT License. Veja o arquivo MIT-LICENSE.
|
data/lib/pombo.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
I18n.load_path += Dir[File.expand_path('../../locales/*.yml', __FILE__)]
|
3
|
+
|
1
4
|
require 'pombo/version'
|
5
|
+
require 'pombo/logger'
|
2
6
|
require 'pombo/configuration'
|
3
7
|
require 'pombo/exception'
|
4
8
|
require 'pombo/support'
|
@@ -8,39 +12,26 @@ require 'pombo/package/item'
|
|
8
12
|
require 'pombo/package/format'
|
9
13
|
require 'pombo/webservice/base'
|
10
14
|
require 'pombo/webservice/cpp'
|
11
|
-
require 'pombo/webservice/cpp/
|
15
|
+
require 'pombo/webservice/cpp/service_response'
|
12
16
|
require 'pombo/webservice/cpp/response'
|
13
17
|
require 'pombo/webservice/cpp/base_request'
|
14
18
|
require 'pombo/webservice/cpp/shipping_request'
|
15
19
|
require 'pombo/webservice/cpp/shipping_value_request'
|
16
20
|
require 'pombo/webservice/cpp/delivery_time_request'
|
17
21
|
|
22
|
+
# It allows you to configure and perform consulting delivery services
|
23
|
+
#
|
24
|
+
# For more information read the file {file:/readmes/README-EN.md}
|
18
25
|
module Pombo
|
19
26
|
# Inform settings for persisting with default
|
20
|
-
# @yield [config] with the configuration data
|
21
|
-
# @
|
22
|
-
# @option config [String] :password Password to access the service, associated with its contract code
|
23
|
-
# @option config [Integer] :extends_delivery Days late on a package
|
24
|
-
# @option config [Integer] :request_timeout Second delay when accessing the webservice
|
25
|
-
# @option config [Symbol] :log_level Log Level, `:info`, `:debug` or `warn`
|
26
|
-
# @option config [Symbol] :logger object to trigger messages (defaults to `:logger`)
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# Pombo.setup do |config|
|
30
|
-
# config.contract_code = 'AA99BB'
|
31
|
-
# config.password = '999999'
|
32
|
-
# config.extends_delivery = 0
|
33
|
-
# config.request_timeout = 5
|
34
|
-
# config.log_level = :info
|
35
|
-
# config.logger = :logger
|
36
|
-
# end
|
27
|
+
# @yield [config] with the configuration data.
|
28
|
+
# @return [Pombo::Configuration] with default settings
|
37
29
|
def self.setup(&block)
|
38
30
|
Configuration.setup(&block)
|
39
31
|
end
|
40
32
|
|
41
33
|
# Tells the settings that will be used at this time
|
42
34
|
# @note Does not modify the default settings
|
43
|
-
# @options (see .setup)
|
44
35
|
# @return [Pombo::Configuration] current settings
|
45
36
|
def self.set(**args)
|
46
37
|
@@configurations = Configuration.new args
|
@@ -51,15 +42,37 @@ module Pombo
|
|
51
42
|
@@configurations ||= Configuration.new
|
52
43
|
end
|
53
44
|
|
45
|
+
# Perform the quotation of delivery of consulting services value and delivery time
|
46
|
+
# @param package [Pombo::Package] the package to be consulted
|
47
|
+
# @return [Array<Pombo::Webservice::CPP::ServiceResponse>]
|
54
48
|
def self.shipping(package)
|
55
49
|
Webservice::CPP.shipping(package)
|
56
50
|
end
|
57
51
|
|
52
|
+
# Perform the quotation of delivery of consulting delivery time
|
53
|
+
# @param package [Pombo::Package] the package to be consulted
|
54
|
+
# @return [Array<Pombo::Webservice::CPP::ServiceResponse>]
|
58
55
|
def self.delivery_time(package)
|
59
56
|
Webservice::CPP.delivery_time(package)
|
60
57
|
end
|
61
58
|
|
59
|
+
# Perform the quotation of delivery of consulting services value
|
60
|
+
# @param package [Pombo::Package] the package to be consulted
|
61
|
+
# @return [Array<Pombo::Webservice::CPP::ServiceResponse>]
|
62
62
|
def self.shipping_value(package)
|
63
63
|
Webservice::CPP.shipping_value(package)
|
64
64
|
end
|
65
|
+
|
66
|
+
# Performs internationalization for informed locale in settings
|
67
|
+
# @return [String] internationalized text
|
68
|
+
def self.t(*args)
|
69
|
+
I18n.with_locale configurations.locale do
|
70
|
+
I18n.translate args
|
71
|
+
end.first
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Pombo::Logger] the default log object Pombo
|
75
|
+
def self.logger
|
76
|
+
configurations.logger
|
77
|
+
end
|
65
78
|
end
|
data/lib/pombo/configuration.rb
CHANGED
@@ -1,39 +1,67 @@
|
|
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] min_package
|
12
|
+
# Force Pombo send at least a package of minimum dimensions of Correios
|
13
|
+
# @!attribute [rw] log_level
|
14
|
+
# Level compatible with Ruby Logger
|
15
|
+
# @!attribute [rw] logger
|
16
|
+
# Object to trigger messages (defaults to +Pombo::Logger+)
|
17
|
+
# @!attribute [rw] locale
|
18
|
+
# Tells you what language will be used (defaults to `pt-BR`)
|
2
19
|
class Configuration
|
3
20
|
@@default = {
|
4
21
|
contract_code: nil,
|
5
22
|
password: nil,
|
6
23
|
extends_delivery: 0,
|
7
|
-
|
8
|
-
|
9
|
-
|
24
|
+
min_package: true,
|
25
|
+
log_level: Pombo::Logger::INFO,
|
26
|
+
logger: Pombo::Logger.new(STDOUT),
|
27
|
+
request_timeout: 5,
|
28
|
+
locale: 'pt-BR'
|
10
29
|
}
|
11
30
|
|
12
|
-
attr_accessor :contract_code, :password, :extends_delivery, :log_level, :logger, :request_timeout
|
31
|
+
attr_accessor :contract_code, :password, :extends_delivery, :log_level, :logger, :request_timeout, :locale, :min_package
|
13
32
|
|
14
33
|
def initialize(**args)
|
15
34
|
args = @@default.merge(args)
|
16
35
|
args.each { |key, value| __send__("#{ key }=", value) }
|
36
|
+
|
37
|
+
logger.level = log_level
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean] tells you if a package with minimum size will be sent
|
41
|
+
def min_package?
|
42
|
+
Pombo::Support::TRUE_VALUES.include? @min_package
|
17
43
|
end
|
18
44
|
|
19
45
|
# Saves the current state of the standard as an object
|
20
|
-
# @return [
|
46
|
+
# @return [Pombo::Configuration] with default settings
|
21
47
|
def set_default
|
22
48
|
attributes = {}
|
23
49
|
instance_variables.each{ |v| attributes[v.to_s.delete('@').to_sym] = instance_variable_get(v) }
|
24
50
|
@@default.merge!(attributes)
|
51
|
+
Pombo.logger.info('update.configuration'){ 'Update the default settings' }
|
52
|
+
self
|
25
53
|
end
|
26
54
|
|
27
55
|
# Inform settings for persisting with default
|
28
|
-
# @
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
56
|
+
# @param [Proc] with the configuration data.
|
57
|
+
# @return [Pombo::Configuration] the updated settings
|
58
|
+
# @raise [Pombo::ConfigurationError] if not passed a block
|
59
|
+
def self.setup
|
60
|
+
raise(Pombo::ConfigurationError, 'expected block the .setup') unless block_given?
|
61
|
+
config = new
|
62
|
+
yield config
|
63
|
+
config.set_default
|
64
|
+
self
|
37
65
|
end
|
38
66
|
|
39
67
|
# @return [Hash] The settings that are set as default
|