pombo 1.0.0.pre.alpha → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -3,12 +3,15 @@ require 'uri'
|
|
3
3
|
module Pombo
|
4
4
|
module Webservice
|
5
5
|
class CPP
|
6
|
+
# Class to create the requests for services
|
7
|
+
# @abstract
|
6
8
|
class BaseRequest
|
7
9
|
|
8
10
|
def initialize(package)
|
9
11
|
@package = package
|
10
12
|
end
|
11
13
|
|
14
|
+
# Encodes the request for http format
|
12
15
|
def to_param
|
13
16
|
URI.encode_www_form to_hash
|
14
17
|
end
|
@@ -3,8 +3,9 @@ require 'uri'
|
|
3
3
|
module Pombo
|
4
4
|
module Webservice
|
5
5
|
class CPP
|
6
|
+
# Request for delivery time service
|
6
7
|
class DeliveryTimeRequest < BaseRequest
|
7
|
-
|
8
|
+
# Convert the object to the format accepted in webservice Correios
|
8
9
|
def to_hash
|
9
10
|
{
|
10
11
|
nCdServico: @package.services.join(','),
|
@@ -2,18 +2,22 @@ require 'sax-machine'
|
|
2
2
|
|
3
3
|
module Pombo
|
4
4
|
module Webservice
|
5
|
+
# Class representing the webservice for consulting services
|
5
6
|
class CPP
|
7
|
+
# Performs the parse of the server response
|
6
8
|
class ParseService
|
7
9
|
include SAXMachine
|
8
|
-
elements :cServico, as: :services, class: Pombo::Webservice::CPP::
|
10
|
+
elements :cServico, as: :services, class: Pombo::Webservice::CPP::ServiceResponse
|
9
11
|
end
|
10
12
|
|
13
|
+
# Comes the response from the server
|
11
14
|
class Response
|
12
|
-
|
13
15
|
def initialize(http_response)
|
14
16
|
@http_response = http_response
|
15
17
|
end
|
16
18
|
|
19
|
+
# Contains services found
|
20
|
+
# @return [Array<Pombo::Webservice::CPP::ServiceResponse>] the services found
|
17
21
|
def body
|
18
22
|
response = Pombo::Webservice::CPP::ParseService.parse @http_response.body
|
19
23
|
response.services
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'sax-machine'
|
2
|
+
|
3
|
+
module Pombo
|
4
|
+
module Webservice
|
5
|
+
class CPP
|
6
|
+
# Response standard for service delivery
|
7
|
+
# @!method [rw] code
|
8
|
+
# @return [String]
|
9
|
+
# @!method [rw] value
|
10
|
+
# @return [Float]
|
11
|
+
# @!method [rw] delivery_time
|
12
|
+
# @return [Fixnum]
|
13
|
+
# @!method [rw] value_in_hand
|
14
|
+
# @return [Float]
|
15
|
+
# @!method [rw] value_delivery_notice
|
16
|
+
# @return [Float]
|
17
|
+
# @!method [rw] value_declared_value
|
18
|
+
# @return [Float]
|
19
|
+
# @!method [rw] value_without_additions
|
20
|
+
# @return [Float]
|
21
|
+
# @!method [rw] delivery_home
|
22
|
+
# @return [Boolean]
|
23
|
+
# @!method [rw] delivery_sartuday
|
24
|
+
# @return [Boolean]
|
25
|
+
# @!method [rw] error_code
|
26
|
+
# @return [String]
|
27
|
+
# @!method [rw] error_message
|
28
|
+
# @return [String]
|
29
|
+
# @!method [rw] comments
|
30
|
+
# @return [String]
|
31
|
+
class ServiceResponse
|
32
|
+
include SAXMachine
|
33
|
+
|
34
|
+
element :Codigo, as: :code
|
35
|
+
element :Valor, as: :value do |value|
|
36
|
+
Pombo::Support.str_real_to_float value
|
37
|
+
end
|
38
|
+
element :PrazoEntrega, as: :delivery_time do |value|
|
39
|
+
value.to_i
|
40
|
+
end
|
41
|
+
element :ValorMaoPropria, as: :value_in_hand do |value|
|
42
|
+
Pombo::Support.str_real_to_float value
|
43
|
+
end
|
44
|
+
element :ValorAvisoRecebimento, as: :value_delivery_notice do |value|
|
45
|
+
Pombo::Support.str_real_to_float value
|
46
|
+
end
|
47
|
+
element :ValorValorDeclarado, as: :value_declared_value do |value|
|
48
|
+
Pombo::Support.str_real_to_float value
|
49
|
+
end
|
50
|
+
element :ValorSemAdicionais, as: :value_without_additions do |value|
|
51
|
+
Pombo::Support.str_real_to_float value
|
52
|
+
end
|
53
|
+
element :EntregaDomiciliar, as: 'delivery_home' do |value|
|
54
|
+
value == 'S'
|
55
|
+
end
|
56
|
+
element :EntregaSabado, as: :delivery_sartuday do |value|
|
57
|
+
value == 'S'
|
58
|
+
end
|
59
|
+
element :Erro, as: :error_code, default: '0'
|
60
|
+
element :MsgErro, as: :error_message do
|
61
|
+
Pombo.t "webservices.cpp.errors.#{ error_code }"
|
62
|
+
end
|
63
|
+
element :obsFim, as: :comments
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -3,8 +3,10 @@ require 'uri'
|
|
3
3
|
module Pombo
|
4
4
|
module Webservice
|
5
5
|
class CPP
|
6
|
+
# Request for shipping service
|
6
7
|
class ShippingRequest < BaseRequest
|
7
8
|
|
9
|
+
# Convert the object to the format accepted in webservice Correios
|
8
10
|
def to_hash
|
9
11
|
{
|
10
12
|
nCdEmpresa: Pombo.configurations.contract_code.to_s,
|
@@ -1,29 +1,8 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
1
|
module Pombo
|
4
2
|
module Webservice
|
5
3
|
class CPP
|
6
|
-
|
7
|
-
|
8
|
-
def to_hash
|
9
|
-
{
|
10
|
-
nCdEmpresa: Pombo.configurations.contract_code.to_s,
|
11
|
-
sDsSenha: Pombo.configurations.password.to_s,
|
12
|
-
nCdServico: @package.services.join(','),
|
13
|
-
sCepOrigem: @package.origin_zip_code,
|
14
|
-
sCepDestino: @package.destination_zip_code,
|
15
|
-
nVlPeso: @package.weight,
|
16
|
-
nCdFormato: @package.format,
|
17
|
-
nVlComprimento: @package.length,
|
18
|
-
nVlAltura: @package.height,
|
19
|
-
nVlLargura: @package.width,
|
20
|
-
nVlDiametro: @package.diameter,
|
21
|
-
sCdMaoPropria: Pombo::Support.boolean_to_string(@package.in_hand?),
|
22
|
-
nVlValorDeclarado: @package.declared_value,
|
23
|
-
sCdAvisoRecebimento: Pombo::Support.boolean_to_string(@package.delivery_notice?)
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
4
|
+
# Request for shipping value service
|
5
|
+
class ShippingValueRequest < ShippingRequest
|
27
6
|
end
|
28
7
|
end
|
29
8
|
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
services:
|
4
|
+
pac:
|
5
|
+
'41106': PAC (without contract)
|
6
|
+
'41068': PAC (with contract)
|
7
|
+
'41300': PAC (large format)
|
8
|
+
sedex:
|
9
|
+
'40010': SEDEX (without contract)
|
10
|
+
'40045': SEDEX to charge (without contract)
|
11
|
+
'40126': SEDEX to charge (with contract)
|
12
|
+
'40215': SEDEX 10 (without contract)
|
13
|
+
'40290': SEDEX today (without contract)
|
14
|
+
'40096': SEDEX (with contract)
|
15
|
+
'40436': SEDEX (with contract)
|
16
|
+
'40444': SEDEX (with contract)
|
17
|
+
'40568': SEDEX (with contract)
|
18
|
+
'40606': SEDEX (with contract)
|
19
|
+
e_sedex:
|
20
|
+
'81019': E-SEDEX (with contract)
|
21
|
+
'81027': E-SEDEX Priority (with contract)
|
22
|
+
'81035': E-SEDEX Express (with contract)
|
23
|
+
'81868': E-SEDEX (with contract, group 1)
|
24
|
+
'81833': E-SEDEX (with contract, group 2)
|
25
|
+
'81850': E-SEDEX (with contract, group 3)
|
26
|
+
|
27
|
+
formats:
|
28
|
+
'1': Box/Package
|
29
|
+
'2': Roll/Prism
|
30
|
+
'3': Envelope
|
31
|
+
|
32
|
+
webservices:
|
33
|
+
cpp:
|
34
|
+
error:
|
35
|
+
'0': Successfully processing
|
36
|
+
'-1': Invalid service code
|
37
|
+
'-2': invalid origin zip code
|
38
|
+
'-3': Invalid destination zip code
|
39
|
+
'-4': Exceeded weight
|
40
|
+
'-5': The declared value must not exceed R$ 10,000.00
|
41
|
+
'-6': Service unavailable to the informed section
|
42
|
+
'-7': The declared Value is required for this service
|
43
|
+
'-8': This service does not accept hand own
|
44
|
+
'-9': This service does not accept return receipt requested
|
45
|
+
'-10': Pricing unavailable for informed stretch
|
46
|
+
'-11': For price setting should be informed also the length, width and height of the object in centimeters (cm)
|
47
|
+
'-12': Invalid length
|
48
|
+
'-13': Invalid width
|
49
|
+
'-14': Invalid height
|
50
|
+
'-15': The length may not exceed 105 cm
|
51
|
+
'-16': The width can not be larger than 105 cm
|
52
|
+
'-17': The height can not be greater than 105 cm
|
53
|
+
'-18': The height can not be less than 2 cm
|
54
|
+
'-20': The width can not be less than 11 cm
|
55
|
+
'-22': Length can not be less than 16 cm
|
56
|
+
'-23': The resulting sum of the length + width + height must not exceed 200 cm
|
57
|
+
'-24': Invalid length
|
58
|
+
'-25': Invalid diameter
|
59
|
+
'-26': Enter the length
|
60
|
+
'-27': Enter the diameter
|
61
|
+
'-28': The length may not exceed 105 cm
|
62
|
+
'-29': The diameter can not be greater than 91 cm
|
63
|
+
'-30': The length can not be less than 18 cm
|
64
|
+
'-31': The diameter can not be less than 5 cm
|
65
|
+
'-32': The resulting sum of the length + two times the diameter should not exceed 200 cm
|
66
|
+
'-33': System temporarily unavailable. Please try later
|
67
|
+
'-34': Administrative Code or invalid password
|
68
|
+
'-35': Incorrect password
|
69
|
+
'-36': Customer does not have current contract with the Post Office
|
70
|
+
'-37': Customer does not have active service in his contract
|
71
|
+
'-38': Service unavailable for this administrative code
|
72
|
+
'-39': Exceeded weight for the envelope format
|
73
|
+
'-40': For definition of price should be informed, as well, the length and the width and height of the object in centimeters (cm)
|
74
|
+
'-41': The length can not be more than 60 cm
|
75
|
+
'-42': Length can not be less than 16 cm
|
76
|
+
'-43': The resulting sum of the length + width must not exceed 120 cm
|
77
|
+
'-44': The width can not be less than 11 cm
|
78
|
+
'-45': The width may be not greater than 60 cm
|
79
|
+
'-888': Error when calculating the rate
|
80
|
+
'006': City of origin does not cover the given service
|
81
|
+
'007': Destination location does not cover the given service
|
82
|
+
'008': Service unavailable to the informed section
|
83
|
+
'009': Initial zip code belonging to risk area
|
84
|
+
'010': Area delivery temporarily subject to different term
|
85
|
+
'011': initial and final zip code belonging to risk area
|
86
|
+
'7': Service unavailable, try again later
|
87
|
+
'99': An error occurred while processing
|
data/locales/pt-br.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
---
|
2
|
+
pt-BR:
|
3
|
+
services:
|
4
|
+
pac:
|
5
|
+
'41106': PAC (sem contrato)
|
6
|
+
'41068': PAC (com contrato)
|
7
|
+
'41300': PAC (grandes formatos)
|
8
|
+
sedex:
|
9
|
+
'40010': SEDEX (sem contrato)
|
10
|
+
'40045': SEDEX a cobrar (sem contrato)
|
11
|
+
'40126': SEDEX a cobrar (com contrato)
|
12
|
+
'40215': SEDEX 10 (sem contrato)
|
13
|
+
'40290': SEDEX hoje (sem contrato)
|
14
|
+
'40096': SEDEX (com contrato)
|
15
|
+
'40436': SEDEX (com contrato)
|
16
|
+
'40444': SEDEX (com contrato)
|
17
|
+
'40568': SEDEX (com contrato)
|
18
|
+
'40606': SEDEX (com contrato)
|
19
|
+
e_sedex:
|
20
|
+
'81019': E-SEDEX (com contrato)
|
21
|
+
'81027': E-SEDEX Prioritário (com contrato)
|
22
|
+
'81035': E-SEDEX Express (com contrato)
|
23
|
+
'81868': E-SEDEX (com contrato, grupo 1)
|
24
|
+
'81833': E-SEDEX (com contrato, grupo 2)
|
25
|
+
'81850': E-SEDEX (com contrato, grupo 3)
|
26
|
+
|
27
|
+
formats:
|
28
|
+
'1': Caixa/Pacote
|
29
|
+
'2': Rolo/Prisma
|
30
|
+
'3': Envelope
|
31
|
+
|
32
|
+
webservices:
|
33
|
+
cpp:
|
34
|
+
errors:
|
35
|
+
'0': Processamento com sucesso
|
36
|
+
'-1': Código de serviço inválido
|
37
|
+
'-2': CEP de origem inválido
|
38
|
+
'-3': CEP de destino inválido
|
39
|
+
'-4': Peso excedido
|
40
|
+
'-5': O Valor Declarado não deve exceder R$ 10.000,00
|
41
|
+
'-6': Serviço indisponível para o trecho informado
|
42
|
+
'-7': O Valor Declarado é obrigatório para este serviço
|
43
|
+
'-8': Este serviço não aceita Mão Própria
|
44
|
+
'-9': Este serviço não aceita Aviso de Recebimento
|
45
|
+
'-10': Precificação indisponível para o trecho informado
|
46
|
+
'-11': Para definição do preço deverão ser informados, também, o comprimento, a largura e altura do objeto em centímetros (cm)
|
47
|
+
'-12': Comprimento inválido
|
48
|
+
'-13': Largura inválida
|
49
|
+
'-14': Altura inválida
|
50
|
+
'-15': O comprimento não pode ser maior que 105 cm
|
51
|
+
'-16': A largura não pode ser maior que 105 cm
|
52
|
+
'-17': A altura não pode ser maior que 105 cm
|
53
|
+
'-18': A altura não pode ser inferior a 2 cm
|
54
|
+
'-20': A largura não pode ser inferior a 11 cm
|
55
|
+
'-22': O comprimento não pode ser inferior a 16 cm
|
56
|
+
'-23': A soma resultante do comprimento + largura + altura não deve superar a 200 cm
|
57
|
+
'-24': Comprimento inválido
|
58
|
+
'-25': Diâmetro inválido
|
59
|
+
'-26': Informe o comprimento
|
60
|
+
'-27': Informe o diâmetro
|
61
|
+
'-28': O comprimento não pode ser maior que 105 cm
|
62
|
+
'-29': O diâmetro não pode ser maior que 91 cm
|
63
|
+
'-30': O comprimento não pode ser inferior a 18 cm
|
64
|
+
'-31': O diâmetro não pode ser inferior a 5 cm
|
65
|
+
'-32': A soma resultante do comprimento + o dobro do diâmetro não deve superar a 200 cm
|
66
|
+
'-33': Sistema temporariamente fora do ar. Favor tentar mais tarde
|
67
|
+
'-34': Código Administrativo ou Senha inválidos
|
68
|
+
'-35': Senha incorreta
|
69
|
+
'-36': Cliente não possui contrato vigente com os Correios
|
70
|
+
'-37': Cliente não possui serviço ativo em seu contrato
|
71
|
+
'-38': Serviço indisponível para este código administrativo
|
72
|
+
'-39': Peso excedido para o formato envelope
|
73
|
+
'-40': Para definicao do preco deverao ser informados, tambem, o comprimento e a largura e altura do objeto em centimetros (cm)
|
74
|
+
'-41': O comprimento nao pode ser maior que 60 cm
|
75
|
+
'-42': O comprimento nao pode ser inferior a 16 cm
|
76
|
+
'-43': A soma resultante do comprimento + largura nao deve superar a 120 cm
|
77
|
+
'-44': A largura nao pode ser inferior a 11 cm
|
78
|
+
'-45': A largura nao pode ser maior que 60 cm
|
79
|
+
'-888': Erro ao calcular a tarifa
|
80
|
+
'006': Localidade de origem não abrange o serviço informado
|
81
|
+
'007': Localidade de destino não abrange o serviço informado
|
82
|
+
'008': Serviço indisponível para o trecho informado
|
83
|
+
'009': CEP inicial pertencente a Área de Risco
|
84
|
+
'010': Área com entrega temporariamente sujeita a prazo diferenciado
|
85
|
+
'011': CEP inicial e final pertencentes a Área de Risco
|
86
|
+
'7': Serviço indisponível, tente mais tarde
|
87
|
+
'99': Ocorreu um error no processamento
|
data/pombo.gemspec
CHANGED
@@ -4,29 +4,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'pombo/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'pombo'
|
8
8
|
spec.version = Pombo::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Leandro Nunes']
|
10
|
+
spec.email = ['leandronunes.dev@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Gem to manage the shipping packages using the webservice of the Correios}
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
12
|
+
spec.summary = %q{ Gem to manage the shipping packages using the webservice of the Correios (Brazilian Post Service) }
|
13
|
+
spec.description = %q{ Pombo is a gem that allows the use of webservices the Correios (Brazilian Post Service) of sending packets to check price, delivery time and progress of service }
|
14
|
+
spec.homepage = 'https://github.com/adenaecommerce/pombo'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
spec.platform = Gem::Platform::RUBY
|
17
|
-
spec.required_ruby_version = '~> 2.
|
17
|
+
spec.required_ruby_version = '~> 2.1'
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_runtime_dependency
|
25
|
-
spec.add_runtime_dependency
|
24
|
+
spec.add_runtime_dependency 'i18n', '~> 0.7.0'
|
25
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
26
|
+
spec.add_runtime_dependency 'sax-machine', '~> 1.3'
|
26
27
|
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
29
|
+
spec.add_development_dependency 'rake', '~> 11.1'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10.3'
|
32
|
+
spec.add_development_dependency 'webmock', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'yard', '~> 0.8.7.6'
|
32
34
|
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
# Pombo
|
2
|
+
|
3
|
+
Pombo is a gem that allows the use of the [Correios](http://correios.com.br/para-voce)
|
4
|
+
webservice to information query shipping packages.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
* Lets put together a package with multiple items
|
9
|
+
* Lets see the shipping price of a package
|
10
|
+
* Lets see the period of sending a packet
|
11
|
+
* It allows you to check the time and shipping price of a package
|
12
|
+
* It supports internationalization
|
13
|
+
* Accepts a logger compatible with the interface [Log4r](http://log4r.rubyforge.org/index.html)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
$ gem install pombo
|
18
|
+
|
19
|
+
or add a line in your Gemfile
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'pombo', '~> 1.0.0.beta'
|
23
|
+
```
|
24
|
+
|
25
|
+
and
|
26
|
+
|
27
|
+
$ bundle install
|
28
|
+
|
29
|
+
|
30
|
+
## Configuration
|
31
|
+
|
32
|
+
> The data returned in sending queries are the same provided at a agency of Correios.
|
33
|
+
> Companies can hire a differentiated service and use the code of their contract in the use of Pombo.
|
34
|
+
|
35
|
+
To modify the default settings, use the `#setup`
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Pombo.setup do |config|
|
39
|
+
config.contract_code = 'AA99BB'
|
40
|
+
config.password = '999999'
|
41
|
+
config.extends_delivery = 0
|
42
|
+
config.min_package = true
|
43
|
+
config.request_timeout = 5
|
44
|
+
config.log_level = Pombo::Logger::INFO
|
45
|
+
config.logger = Pombo::Logger.new(STDOUT)
|
46
|
+
config.locale = 'pt-BR'
|
47
|
+
end
|
48
|
+
```
|
49
|
+
> The packages sent by mail have size limitations, using the `min_package` option you can tell if the package
|
50
|
+
> does not have the minimum dimensions, which is held to quote the permitted minimum sizes.
|
51
|
+
|
52
|
+
If you need to modify some settings at a certain time, use the `#set`
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Pombo.set request_timeout: 10, locale: 'en'
|
56
|
+
```
|
57
|
+
|
58
|
+
> The #set does not modify the default settings
|
59
|
+
|
60
|
+
## Formats
|
61
|
+
|
62
|
+
The formats are predefined objects to information provided by the Correios.
|
63
|
+
The Correios works with the following formats: box, envelope and roll. Every item must have a format.
|
64
|
+
|
65
|
+
The packet format is reported as items added. For more than two items prevails box format.
|
66
|
+
|
67
|
+
|
68
|
+
List all formats supported by delivery services
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Pombo::Package::Format.all
|
72
|
+
|
73
|
+
# => [
|
74
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
75
|
+
# => ....
|
76
|
+
# => ]
|
77
|
+
```
|
78
|
+
|
79
|
+
Find a specific format by code or by name
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Pombo::Package::Format.find '3'
|
83
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
84
|
+
|
85
|
+
# Or
|
86
|
+
|
87
|
+
Pombo::Package::Format.find 'envelope'
|
88
|
+
# => #<OpenStruct code=3, name="Envelope", max_length=60, min_length=16, max_width=60, min_width=11, max_weight=1>
|
89
|
+
```
|
90
|
+
|
91
|
+
## Services
|
92
|
+
Services are predefined objects to information provided by the Post Office. To learn more, [click here](http://www.correios.com.br/para-voce/envio/encomendas/encomendas)
|
93
|
+
|
94
|
+
List all formats supported by delivery services
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
Pombo::Services.all
|
98
|
+
|
99
|
+
# => [
|
100
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (without contract)">,
|
101
|
+
# => ....
|
102
|
+
# => ]
|
103
|
+
```
|
104
|
+
|
105
|
+
Listing all the services of a group
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Pombo::Services.all :pac
|
109
|
+
# => [
|
110
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (without contract)">,
|
111
|
+
# => ....
|
112
|
+
# => ]
|
113
|
+
```
|
114
|
+
|
115
|
+
Search for a service code
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Pombo::Services.find "41106"
|
119
|
+
# => #<OpenStruct code="41106", max_weight=30, name="PAC", description="PAC (without contract)">
|
120
|
+
```
|
121
|
+
|
122
|
+
## Packages
|
123
|
+
|
124
|
+
Packages are the objects sent to the webservice for the query to be performed.
|
125
|
+
It consists of several items, the zip code of origin and destination zip code and some optional services,
|
126
|
+
[see here](https://www.correios.com.br/para-voce/envio/encomendas/servicos-opcionais)
|
127
|
+
|
128
|
+
Creating a package:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
package = Pombo::Package.new ({
|
132
|
+
destination_zip_code: '29160565',
|
133
|
+
origin_zip_code: '29108046',
|
134
|
+
services: "40010",
|
135
|
+
in_hand: false,
|
136
|
+
delivery_notice: false
|
137
|
+
})
|
138
|
+
# => <Pombo::Package:0x007fcfd32080f0 @items=[], @length=0, @height=0, @width=0, @declared_value=0, @destination_zip_code="29160565", @origin_zip_code="29108046">
|
139
|
+
```
|
140
|
+
|
141
|
+
> It can be informer an array of services to carry out the consultation on various services.
|
142
|
+
> `Pombo::Package.new services: ["40010", "41068", "40568"]`
|
143
|
+
|
144
|
+
Adding items:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
item = Pombo::Package::Item.new weight: 10, length: 17, height: 22, width: 22
|
148
|
+
package.add_item item
|
149
|
+
```
|
150
|
+
|
151
|
+
or you can be informed a hash
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
package.add_item weight: 10, length: 15, height: 5, width: 10
|
155
|
+
```
|
156
|
+
|
157
|
+
Now we can get various information
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
package.in_hand? # => false
|
161
|
+
package.delivery_notice? # => false
|
162
|
+
package.weight # => 10
|
163
|
+
package.diameter # => 0
|
164
|
+
package.format # => 1
|
165
|
+
package.volume # => 8228.0
|
166
|
+
package.single_item? # => true
|
167
|
+
```
|
168
|
+
|
169
|
+
## Usage
|
170
|
+
|
171
|
+
To perform a query to know the value and the delivery
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
Pombo.shipping package
|
175
|
+
# => [
|
176
|
+
# => [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>
|
177
|
+
# => ]
|
178
|
+
```
|
179
|
+
|
180
|
+
To make an inquiry to find out the delivery time
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
Pombo.delivery_time package
|
184
|
+
# => [
|
185
|
+
# => [0] #<Pombo::Webservice::CPP::Service:0x007fae1da0b040 @code="40010", @delivery_time="1", @delivery_home=true, @delivery_sartuday=true>
|
186
|
+
# => ]
|
187
|
+
```
|
188
|
+
|
189
|
+
To perform a query to know the value of delivery
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
Pombo.shipping_value package
|
193
|
+
# => [
|
194
|
+
# => [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>
|
195
|
+
# => ]
|
196
|
+
```
|
197
|
+
|
198
|
+
## Log
|
199
|
+
|
200
|
+
Pombo accepts any logger system compatible with [Log4r](http://log4r.rubyforge.org/index.html) interface.
|
201
|
+
We have our own logger object, `Pombo::Logger`, which by default sends the messages to the system `STDOUT` and the level is INFO.
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
Pombo.logger.info('event.namespace'){ 'Any error message' }
|
205
|
+
# => 2016-05-13 15:15:49 -0300 | POMBO | event.namespace | INFO: Any error message
|
206
|
+
```
|
207
|
+
|
208
|
+
To save file, you can do something like this:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Pombo.setup do |config|
|
212
|
+
config.log_level = Pombo::Logger::INFO
|
213
|
+
config.logger = Pombo::Logger.new('caminho do arquivo')
|
214
|
+
end
|
215
|
+
```
|
216
|
+
|
217
|
+
## Contributing
|
218
|
+
|
219
|
+
Pombo is maintained by the development team of [Adena E-commerce Platform](http://www.adena.com.br/).
|
220
|
+
|
221
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adenaecommerce/pombo.
|
222
|
+
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.
|
223
|
+
|
224
|
+
## License
|
225
|
+
|
226
|
+
MIT License. See the included MIT-LICENSE file.
|