rastreioz 0.1.3
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 +7 -0
- data/.gitignore +31 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rastreioz/cep.rb +12 -0
- data/lib/rastreioz/frete.rb +84 -0
- data/lib/rastreioz/http.rb +31 -0
- data/lib/rastreioz/log.rb +33 -0
- data/lib/rastreioz/rastreamento.rb +12 -0
- data/lib/rastreioz/servico.rb +106 -0
- data/lib/rastreioz/version.rb +3 -0
- data/lib/rastreioz.rb +39 -0
- data/rastreioz.gemspec +30 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 796879e6c97c04645bf89e9dd3b3d6e75214103c8d57dcbcb73cddc002467c5c
|
4
|
+
data.tar.gz: fbded9f7d85184500404fd2ceb75c8e2573e519901b31f5de0c9edab9e9b40f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7abeea7fcb8f48da138f0c04954c3c6098448ea25e3ddd582216b8f041472889c0eb67cd9f84ea3d36606bc14185b10a447fa8b9ab74238d0fa5772039127421
|
7
|
+
data.tar.gz: 566a5ae76e4253cb11f6ca4c1b7c4e8d3b4feb4d1310dcef2f107fedeaecd8efee9200ac721fe67cc3a6c879a464ee050b85f864f6919c79f0d59064a074c4ff
|
data/.gitignore
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# rspec failure tracking
|
20
|
+
.rspec_status
|
21
|
+
|
22
|
+
# For MacOS:
|
23
|
+
.DS_Store
|
24
|
+
|
25
|
+
# For vim:
|
26
|
+
*.swp
|
27
|
+
*.swo
|
28
|
+
|
29
|
+
# RVM
|
30
|
+
.ruby-gemset
|
31
|
+
.ruby-version
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at augusto@base16.com.br. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Augusto Cesar S. Martins
|
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,43 @@
|
|
1
|
+
# Rastreioz
|
2
|
+
|
3
|
+
VERSÃO ALFA DE TESTE!
|
4
|
+
|
5
|
+
Rastreioz::Prazo.calcular([:e_sedex, :sedex_10, :pac_com_contrato, :sedex_com_contrato_1], {cep_origem: 22041030, cep_destino: 22041030, peso: 1, formato: :caixa_pacote, comprimento: 20, altura: 4, largura: 11, diametro: 20, valor_declarado: 25.00})
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rastreioz'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rastreioz
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/base16soft/rastreioz. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Rastreioz project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rastreioz/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rastreioz"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Rastreioz
|
2
|
+
class Frete
|
3
|
+
|
4
|
+
attr_accessor :codigo_empresa, :senha, :cep_origem, :cep_destino
|
5
|
+
attr_accessor :diametro, :mao_propria, :aviso_recebimento, :valor_declarado
|
6
|
+
attr_accessor :peso, :comprimento, :largura, :altura, :formato
|
7
|
+
|
8
|
+
DEFAULT_OPTIONS = {
|
9
|
+
:peso => 0.0,
|
10
|
+
:comprimento => 0.0,
|
11
|
+
:largura => 0.0,
|
12
|
+
:altura => 0.0,
|
13
|
+
:diametro => 0.0,
|
14
|
+
:formato => :caixa_pacote,
|
15
|
+
:mao_propria => false,
|
16
|
+
:aviso_recebimento => false,
|
17
|
+
:valor_declarado => 0.0
|
18
|
+
}
|
19
|
+
|
20
|
+
URL = "https://api.rastreioz.com/frete/prazo"
|
21
|
+
FORMATS = { :caixa_pacote => 1, :rolo_prisma => 2, :envelope => 3 }
|
22
|
+
CONDITIONS = { true => "S", false => "N" }
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
DEFAULT_OPTIONS.merge(options).each do |attr, value|
|
26
|
+
self.send("#{attr}=", value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def calcular(service_types)
|
31
|
+
servicos = {}
|
32
|
+
begin
|
33
|
+
url = "#{URL}?#{params_for(service_types)}"
|
34
|
+
response = Rastreioz::Log.new.with_log {Rastreioz::Http.new.http_request(url)}
|
35
|
+
response_body = JSON.parse(response.body)
|
36
|
+
response_body.each do |element|
|
37
|
+
servico = Rastreioz::Servico.new.parse(element)
|
38
|
+
servicos[servico.tipo] = servico
|
39
|
+
end
|
40
|
+
rescue
|
41
|
+
raise "Falha na Consulta ao Correio"
|
42
|
+
end
|
43
|
+
servicos
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.calcular(service_types, options = {})
|
47
|
+
self.new(options).calcular(service_types)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def params_for(service_types)
|
53
|
+
res = "sCepOrigem=#{self.cep_origem}&" +
|
54
|
+
"sCepDestino=#{self.cep_destino}&" +
|
55
|
+
"nVlPeso=#{self.peso}&" +
|
56
|
+
"nVlComprimento=#{format_decimal(self.comprimento)}&" +
|
57
|
+
"nVlLargura=#{format_decimal(self.largura)}&" +
|
58
|
+
"nVlAltura=#{format_decimal(self.altura)}&" +
|
59
|
+
"nVlDiametro=#{format_decimal(self.diametro)}&" +
|
60
|
+
"nCdFormato=#{FORMATS[self.formato]}&" +
|
61
|
+
"sCdMaoPropria=#{CONDITIONS[self.mao_propria]}&" +
|
62
|
+
"sCdAvisoRecebimento=#{CONDITIONS[self.aviso_recebimento]}&" +
|
63
|
+
"nVlValorDeclarado=#{format_decimal(format("%.2f" % self.valor_declarado))}&" +
|
64
|
+
"nCdServico=#{service_codes_for(service_types)}"
|
65
|
+
|
66
|
+
res = "#{res}&nCdEmpresa=#{self.codigo_empresa}&sDsSenha=#{self.senha}" if self.codigo_empresa && self.senha
|
67
|
+
res
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_decimal(value)
|
71
|
+
value.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
def service_codes_for(service_types)
|
75
|
+
service_codes = service_types.is_a?(Array) ?
|
76
|
+
service_types.map { |type| Rastreioz::Servico.code_from_type(type) }.join(",") :
|
77
|
+
Rastreioz::Servico.code_from_type(service_types)
|
78
|
+
|
79
|
+
puts service_codes
|
80
|
+
service_codes
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rastreioz
|
2
|
+
class Http
|
3
|
+
|
4
|
+
def http_request(request_url)
|
5
|
+
@uri = URI.parse(request_url)
|
6
|
+
@http = build_http
|
7
|
+
|
8
|
+
request = Net::HTTP::Get.new(@uri)
|
9
|
+
http.open_timeout = Rastreioz.request_timeout
|
10
|
+
http.request(request)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def build_http
|
16
|
+
Net::HTTP.start(
|
17
|
+
uri.host,
|
18
|
+
uri.port,
|
19
|
+
nil,
|
20
|
+
nil,
|
21
|
+
nil,
|
22
|
+
nil,
|
23
|
+
use_ssl: true,
|
24
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :uri, :url, :http
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rastreioz
|
2
|
+
class Log
|
3
|
+
|
4
|
+
def with_log
|
5
|
+
response = yield
|
6
|
+
Rastreioz.log(format_request_message(response))
|
7
|
+
Rastreioz.log(format_response_message(response))
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_request_message(response)
|
12
|
+
message = with_line_break { "RastreioZ Request:" }
|
13
|
+
message << with_line_break { "GET #{response.uri}" }
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_response_message(response)
|
17
|
+
message = with_line_break { "RastreioZ Response:" }
|
18
|
+
message << with_line_break { "HTTP/#{response.http_version} #{response.code} #{response.message}" }
|
19
|
+
message << with_line_break { format_headers_for(response) } if Rastreioz.log_level == :debug
|
20
|
+
message << with_line_break { response.body }
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_headers_for(http)
|
24
|
+
# I'm using an empty block in each_header method for Ruby 1.8.7 compatibility.
|
25
|
+
http.each_header{}.map { |name, values| "#{name}: #{values.first}" }.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_line_break
|
29
|
+
"#{yield}\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rastreioz
|
4
|
+
class Servico
|
5
|
+
|
6
|
+
AVAILABLE_SERVICES = {
|
7
|
+
"4510" => { :type => :pac, :name => "PAC", :description => "PAC sem contrato" },
|
8
|
+
"41068" => { :type => :pac_com_contrato, :name => "PAC", :description => "PAC com contrato" },
|
9
|
+
"4669" => { :type => :pac_com_contrato_2, :name => "PAC", :description => "PAC com contrato" },
|
10
|
+
"41300" => { :type => :pac_gf, :name => "PAC GF", :description => "PAC para grandes formatos" },
|
11
|
+
"4014" => { :type => :sedex, :name => "SEDEX", :description => "SEDEX sem contrato" },
|
12
|
+
"40045" => { :type => :sedex_a_cobrar, :name => "SEDEX a Cobrar", :description => "SEDEX a Cobrar, sem contrato" },
|
13
|
+
"40126" => { :type => :sedex_a_cobrar_com_contrato, :name => "SEDEX a Cobrar", :description => "SEDEX a Cobrar, com contrato" },
|
14
|
+
"40215" => { :type => :sedex_10, :name => "SEDEX 10", :description => "SEDEX 10, sem contrato" },
|
15
|
+
"40290" => { :type => :sedex_hoje, :name => "SEDEX Hoje", :description => "SEDEX Hoje, sem contrato" },
|
16
|
+
"40096" => { :type => :sedex_com_contrato_1, :name => "SEDEX", :description => "SEDEX com contrato" },
|
17
|
+
"40436" => { :type => :sedex_com_contrato_2, :name => "SEDEX", :description => "SEDEX com contrato" },
|
18
|
+
"40444" => { :type => :sedex_com_contrato_3, :name => "SEDEX", :description => "SEDEX com contrato" },
|
19
|
+
"40568" => { :type => :sedex_com_contrato_4, :name => "SEDEX", :description => "SEDEX com contrato" },
|
20
|
+
"40606" => { :type => :sedex_com_contrato_5, :name => "SEDEX", :description => "SEDEX com contrato" },
|
21
|
+
"4162" => { :type => :sedex_com_contrato_6, :name => "SEDEX", :description => "SEDEX com contrato" },
|
22
|
+
"81019" => { :type => :e_sedex, :name => "e-SEDEX", :description => "e-SEDEX, com contrato" },
|
23
|
+
"81027" => { :type => :e_sedex_prioritario, :name => "e-SEDEX", :description => "e-SEDEX Prioritário, com contrato" },
|
24
|
+
"81035" => { :type => :e_sedex_express, :name => "e-SEDEX", :description => "e-SEDEX Express, com contrato" },
|
25
|
+
"81868" => { :type => :e_sedex_grupo_1, :name => "e-SEDEX", :description => "(Grupo 1) e-SEDEX, com contrato" },
|
26
|
+
"81833" => { :type => :e_sedex_grupo_2, :name => "e-SEDEX", :description => "(Grupo 2) e-SEDEX, com contrato" },
|
27
|
+
"81850" => { :type => :e_sedex_grupo_3, :name => "e-SEDEX", :description => "(Grupo 3) e-SEDEX, com contrato" }
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
AVAILABLE_METHODS = {
|
31
|
+
"Codigo" => "codigo",
|
32
|
+
"Valor" => "valor",
|
33
|
+
"PrazoEntrega" => "prazo_entrega",
|
34
|
+
"ValorMaoPropria" => "valor_mao_propria",
|
35
|
+
"ValorAvisoRecebimento" => "valor_aviso_recebimento",
|
36
|
+
"ValorValorDeclarado" => "valor_valor_declarado",
|
37
|
+
"EntregaDomiciliar" => "entrega_domiciliar",
|
38
|
+
"EntregaSabado" => "entrega_sabado",
|
39
|
+
"Erro" => "erro",
|
40
|
+
"MsgErro" => "msg_erro",
|
41
|
+
"obsFim" => "obs_fim"
|
42
|
+
}.freeze
|
43
|
+
|
44
|
+
attr_reader :codigo, :valor, :prazo_entrega
|
45
|
+
attr_reader :valor_mao_propria, :valor_aviso_recebimento, :valor_valor_declarado, :valor_sem_adicionais
|
46
|
+
attr_reader :entrega_domiciliar, :entrega_sabado, :erro, :msg_erro, :obs_fim
|
47
|
+
|
48
|
+
attr_reader :tipo, :nome, :descricao
|
49
|
+
|
50
|
+
def parse(element)
|
51
|
+
|
52
|
+
element.each do |attr, value|
|
53
|
+
instance_variable_set("@#{AVAILABLE_METHODS[attr]}", value.to_s) unless AVAILABLE_METHODS[attr].nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
if AVAILABLE_SERVICES[codigo]
|
57
|
+
@tipo = AVAILABLE_SERVICES[codigo][:type]
|
58
|
+
@nome = AVAILABLE_SERVICES[codigo][:name]
|
59
|
+
@descricao = AVAILABLE_SERVICES[codigo][:description]
|
60
|
+
end
|
61
|
+
|
62
|
+
cast_to_float! :valor, :valor_mao_propria, :valor_aviso_recebimento, :valor_valor_declarado
|
63
|
+
cast_to_int! :prazo_entrega
|
64
|
+
cast_to_boolean! :entrega_domiciliar, :entrega_sabado
|
65
|
+
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def success?
|
70
|
+
valor > 0.0
|
71
|
+
end
|
72
|
+
alias sucesso? success?
|
73
|
+
|
74
|
+
def error?
|
75
|
+
!success?
|
76
|
+
end
|
77
|
+
alias erro? error?
|
78
|
+
|
79
|
+
def self.code_from_type(type)
|
80
|
+
# I don't use select method for Ruby 1.8.7 compatibility.
|
81
|
+
AVAILABLE_SERVICES.map { |key, value| key if value[:type] == type }.compact.first
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def cast_to_float!(*attributes)
|
87
|
+
attributes.each do |attr|
|
88
|
+
value = send(attr).to_s.gsub(".", "").gsub("," ,".")
|
89
|
+
instance_variable_set("@#{attr}", value.to_f)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def cast_to_int!(*attributes)
|
94
|
+
attributes.each do |attr|
|
95
|
+
instance_variable_set("@#{attr}", send(attr).to_i)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def cast_to_boolean!(*attributes)
|
100
|
+
attributes.each do |attr|
|
101
|
+
instance_variable_set("@#{attr}", send(attr) == "S")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
data/lib/rastreioz.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'log-me'
|
4
|
+
require 'net/https'
|
5
|
+
require 'json'
|
6
|
+
require 'uri'
|
7
|
+
require "rastreioz/version"
|
8
|
+
require "rastreioz/log"
|
9
|
+
require "rastreioz/http"
|
10
|
+
require "rastreioz/servico"
|
11
|
+
require "rastreioz/rastreamento"
|
12
|
+
require "rastreioz/frete"
|
13
|
+
require "rastreioz/cep"
|
14
|
+
|
15
|
+
module Rastreioz
|
16
|
+
extend LogMe
|
17
|
+
|
18
|
+
module Timeout
|
19
|
+
DEFAULT_REQUEST_TIMEOUT = 10 #seconds
|
20
|
+
attr_writer :request_timeout
|
21
|
+
|
22
|
+
def request_timeout
|
23
|
+
(@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
extend Timeout
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def auth=(credentials)
|
31
|
+
@credentials = credentials
|
32
|
+
end
|
33
|
+
|
34
|
+
def auth
|
35
|
+
@credentials
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/rastreioz.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rastreioz/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rastreioz"
|
8
|
+
spec.version = Rastreioz::VERSION
|
9
|
+
spec.authors = ["Augusto Cesar S. Martins"]
|
10
|
+
spec.email = ["augusto@base16.com.br"]
|
11
|
+
|
12
|
+
spec.summary = "Calculo de frete dos Correios utilizando a Rastreioz Api."
|
13
|
+
spec.description = "[Alfa Version] Calculo de frete utilizando o Web Service Rastreioz.\nOs servicos de frete suportados sao PAC, SEDEX, SEDEX a Cobrar, SEDEX 10, SEDEX Hoje e e-SEDEX."
|
14
|
+
spec.homepage = "https://github.com/base16soft/rastreioz"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "log-me", "~> 0.0.10"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rastreioz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Augusto Cesar S. Martins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: log-me
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: |-
|
70
|
+
[Alfa Version] Calculo de frete utilizando o Web Service Rastreioz.
|
71
|
+
Os servicos de frete suportados sao PAC, SEDEX, SEDEX a Cobrar, SEDEX 10, SEDEX Hoje e e-SEDEX.
|
72
|
+
email:
|
73
|
+
- augusto@base16.com.br
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- lib/rastreioz.rb
|
89
|
+
- lib/rastreioz/cep.rb
|
90
|
+
- lib/rastreioz/frete.rb
|
91
|
+
- lib/rastreioz/http.rb
|
92
|
+
- lib/rastreioz/log.rb
|
93
|
+
- lib/rastreioz/rastreamento.rb
|
94
|
+
- lib/rastreioz/servico.rb
|
95
|
+
- lib/rastreioz/version.rb
|
96
|
+
- rastreioz.gemspec
|
97
|
+
homepage: https://github.com/base16soft/rastreioz
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.7.7
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Calculo de frete dos Correios utilizando a Rastreioz Api.
|
121
|
+
test_files: []
|