pombo 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e35c41bc810a96a4517c2a1bd0cf2dfaafb47ad5
4
+ data.tar.gz: 6b15a04c6ce1c138e5572bdc11d6a556d9eca58a
5
+ SHA512:
6
+ metadata.gz: 4e1bb9beb588c8bf1e31e8bcab2f4dfb124df2131f1f0d7ffcc7820260dae14badfaefb144db649c41ff9cea2908a545a6adebf7f40624d657871133497e6946
7
+ data.tar.gz: 6a2de9baa6b927b97180a6e6a8e8a3f9f5e70470681be718a3872e2d247f3e0e79e007eec0a388b97b58cb8c153dc7d931bb4b53747d3430b5b58f76b8db2627
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.1.2
5
+ before_install: gem install bundler -v 1.11.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
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
+ * Allows the service value of consultation
9
+ * Allows consultation of service delivery time
10
+ * It allows you to see the value and service delivery time
11
+ * It supports internationalization
12
+ * Accepts a logger compatible with the interface [Log4r](http://log4r.rubyforge.org/index.html)
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at leandronunes.dev@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pombo.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Adena E-commerce Platform
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,233 @@
1
+ > ***
2
+ > Attention! if you are looking for documentation in English, [click here!](readmes/README-EN.md)
3
+ > ***
4
+
5
+ # Pombo
6
+ [![Build Status](https://travis-ci.org/adenaecommerce/pombo.svg?branch=master)](https://travis-ci.org/adenaecommerce/pombo)
7
+ [![Dependency Status](https://gemnasium.com/adenaecommerce/pombo.svg)](https://gemnasium.com/adenaecommerce/pombo)
8
+ [![Inline docs](http://inch-ci.org/github/adenaecommerce/pombo.svg?branch=master)](http://inch-ci.org/github/adenaecommerce/pombo)
9
+ [![Hex.pm](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/adenaecommerce/pombo/master)
10
+ [![Gem Version](https://badge.fury.io/rb/pombo.svg)](https://badge.fury.io/rb/pombo)
11
+ [![Code Climate](https://codeclimate.com/github/adenaecommerce/pombo/badges/gpa.svg)](https://codeclimate.com/github/adenaecommerce/pombo)
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
15
+
16
+ ## Funcionalidades
17
+
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)
24
+
25
+ ## Instalação
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:
135
+
136
+ ```ruby
137
+ package = Pombo::Package.new ({
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">
145
+ ```
146
+
147
+ > Pode ser informador um array de serviços para realizar a consulta em vários serviços.
148
+ > `Pombo::Package.new services: ["40010", "41068", "40568"]`
149
+
150
+ Adicionando items:
151
+
152
+ ```ruby
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
+ ```
174
+
175
+ ## Utilizando o Pombo
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.
209
+
210
+ ```ruby
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
+ ```
214
+
215
+ Para gravar em arquivo, você pode fazer algo parecido com isso:
216
+
217
+ ```ruby
218
+ Pombo.setup do |config|
219
+ config.log_level = Pombo::Logger::INFO
220
+ config.logger = Pombo::Logger.new('caminho do arquivo')
221
+ end
222
+ ```
223
+
224
+ ## Como contribuir
225
+
226
+ Pombo é mantido pela time de desenvolvimento da [Adena E-commerce Platform](http://www.adena.com.br/).
227
+
228
+ Relatórios de Bugs e pull requests são bem vindos no GitHub em https://github.com/adenaecommerce/pombo.
229
+ Você pode nos enviar a sua colaboração, mas deve aderir ao código de conduta [Contributor Covenant](http://contributor-covenant.org).
230
+
231
+ ## Licença
232
+
233
+ MIT License. Veja o arquivo MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pombo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pombo.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'i18n'
2
+ I18n.load_path += Dir[File.expand_path('../../locales/*.yml', __FILE__)]
3
+
4
+ require 'pombo/version'
5
+ require 'pombo/logger'
6
+ require 'pombo/configuration'
7
+ require 'pombo/exception'
8
+ require 'pombo/support'
9
+ require 'pombo/services'
10
+ require 'pombo/package'
11
+ require 'pombo/package/item'
12
+ require 'pombo/package/format'
13
+ require 'pombo/webservice/base'
14
+ require 'pombo/webservice/cpp'
15
+ require 'pombo/webservice/cpp/service_response'
16
+ require 'pombo/webservice/cpp/response'
17
+ require 'pombo/webservice/cpp/base_request'
18
+ require 'pombo/webservice/cpp/shipping_request'
19
+ require 'pombo/webservice/cpp/shipping_value_request'
20
+ require 'pombo/webservice/cpp/delivery_time_request'
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}
25
+ module Pombo
26
+ # Inform settings for persisting with default
27
+ # @yield [config] with the configuration data.
28
+ # @return [Pombo::Configuration] with default settings
29
+ def self.setup(&block)
30
+ Configuration.setup(&block)
31
+ end
32
+
33
+ # Tells the settings that will be used at this time
34
+ # @note Does not modify the default settings
35
+ # @return [Pombo::Configuration] current settings
36
+ def self.set(**args)
37
+ @@configurations = Configuration.new args
38
+ end
39
+
40
+ # @return [Pombo::Configuration] current settings
41
+ def self.configurations
42
+ @@configurations ||= Configuration.new
43
+ end
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>]
48
+ def self.shipping(package)
49
+ Webservice::CPP.shipping(package)
50
+ end
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>]
55
+ def self.delivery_time(package)
56
+ Webservice::CPP.delivery_time(package)
57
+ end
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
+ def self.shipping_value(package)
63
+ Webservice::CPP.shipping_value(package)
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
78
+ end