correios 0.2.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.
- data/CHANGELOG +0 -0
- data/Manifest +6 -0
- data/README.rdoc +47 -0
- data/Rakefile +14 -0
- data/correios.gemspec +33 -0
- data/init.rb +1 -0
- data/lib/correios.rb +67 -0
- metadata +94 -0
data/CHANGELOG
ADDED
File without changes
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= Correios
|
2
|
+
|
3
|
+
Gem para cálculo de frete usando o e rastreamento dos correios usando webservices. http://www.correios.com.br/webservices/
|
4
|
+
|
5
|
+
== Instalação
|
6
|
+
|
7
|
+
gem install correios
|
8
|
+
|
9
|
+
== Como Usar
|
10
|
+
|
11
|
+
require 'correios'
|
12
|
+
|
13
|
+
begin
|
14
|
+
correios = Correios.new(76410000, 74932180)
|
15
|
+
correios.calcula_frete(Correios::Servico::PAC, 0.4, 17, 16,16,16)
|
16
|
+
rescue Correios::InvalidCalcException => e
|
17
|
+
puts e.message
|
18
|
+
end
|
19
|
+
|
20
|
+
Em caso de algum dado inválido será levantada a exception:
|
21
|
+
|
22
|
+
Correios::InvalidCalcException
|
23
|
+
|
24
|
+
== Outras informações
|
25
|
+
|
26
|
+
Definição do método calcula frete:
|
27
|
+
|
28
|
+
calcula_frete(tipo, peso, comprimento,
|
29
|
+
altura, largura, diametro, mao_propria = NAO,
|
30
|
+
valor_declarado = 0, aviso_recebimento = NAO)
|
31
|
+
|
32
|
+
|
33
|
+
Serviços:
|
34
|
+
|
35
|
+
Correios::Servico::PAC
|
36
|
+
Correios::Servico::SEDEX
|
37
|
+
Correios::Servico::SEDEX10
|
38
|
+
Correios::Servico::SEDEX_HOJE
|
39
|
+
Correios::Servico::ESEDEX
|
40
|
+
Correios::Servico::MALOTE
|
41
|
+
|
42
|
+
== Contato
|
43
|
+
|
44
|
+
Caso tenha alguma dúvida ou sugestão entre em contato: bfscordeiro (em) gmail.com
|
45
|
+
|
46
|
+
|
47
|
+
Copyright (c) 2010 Bruno Cordeiro, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('correios', '0.2.0') do |p|
|
6
|
+
p.description = "Gem para calculo de valor e restreamento dos correios"
|
7
|
+
p.url = "https://github.com/brunofrank/correios"
|
8
|
+
p.author = "Bruno Frank"
|
9
|
+
p.email = "bfscordeiro@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = ['xml-simple']
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/correios.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{correios}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Bruno Frank"]
|
9
|
+
s.date = %q{2011-05-29}
|
10
|
+
s.description = %q{Gem para calculo de valor e restreamento dos correios}
|
11
|
+
s.email = %q{bfscordeiro@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/correios.rb"]
|
13
|
+
s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "init.rb", "lib/correios.rb", "Manifest", "correios.gemspec"]
|
14
|
+
s.homepage = %q{https://github.com/brunofrank/correios}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Correios", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{correios}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Gem para calculo de valor e restreamento dos correios}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<xml-simple>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'correios'
|
data/lib/correios.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'xmlsimple'
|
3
|
+
|
4
|
+
class Correios
|
5
|
+
|
6
|
+
class InvalidCalcException < Exception
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(message)
|
10
|
+
@message = message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Servico
|
15
|
+
PAC = 41106
|
16
|
+
SEDEX = 40010
|
17
|
+
SEDEX10 = 40215
|
18
|
+
SEDEX_HOJE = 40290
|
19
|
+
ESEDEX = 81019
|
20
|
+
MALOTE = 44105
|
21
|
+
end
|
22
|
+
|
23
|
+
SIM = 'S'
|
24
|
+
NAO = 'N'
|
25
|
+
|
26
|
+
def initialize(cep_origem, cep_destino)
|
27
|
+
@cep_origem = cep_origem
|
28
|
+
@cep_destino = cep_destino
|
29
|
+
end
|
30
|
+
|
31
|
+
def calcula_frete(tipo, peso, comprimento, altura, largura, diametro, mao_propria = NAO,
|
32
|
+
valor_declarado = 0, aviso_recebimento = NAO)
|
33
|
+
host = 'http://ws.correios.com.br'
|
34
|
+
path = '/calculador/CalcPrecoPrazo.aspx'
|
35
|
+
|
36
|
+
params = {
|
37
|
+
:nCdEmpresa => '',
|
38
|
+
:sDsSenha => '',
|
39
|
+
:StrRetorno => "xml",
|
40
|
+
:nCdServico => tipo,
|
41
|
+
:sCepOrigem => @cep_origem,
|
42
|
+
:sCepDestino => @cep_destino,
|
43
|
+
:nVlPeso => peso,
|
44
|
+
:nCdFormato => 1,
|
45
|
+
:nVlComprimento => comprimento,
|
46
|
+
:nVlAltura => altura,
|
47
|
+
:nVlLargura => largura,
|
48
|
+
:nVlDiametro => diametro,
|
49
|
+
:sCdMaoPropria => mao_propria,
|
50
|
+
:nVlValorDeclarado => valor_declarado,
|
51
|
+
:resposta => "Xml",
|
52
|
+
:sCdAvisoRecebimento => aviso_recebimento
|
53
|
+
}
|
54
|
+
|
55
|
+
params = params.to_a.map {|item| item.to_a.join('=')} .join('&')
|
56
|
+
|
57
|
+
xml = XmlSimple.xml_in(open("#{host}#{path}?#{params}").read)
|
58
|
+
if xml["cServico"].first["Erro"].first == '0'
|
59
|
+
{
|
60
|
+
:valor => xml['cServico'].first["Valor"].to_s.gsub(',', '.').to_f,
|
61
|
+
:prazo => xml['cServico'].first["PrazoEntrega"].to_s.to_i
|
62
|
+
}
|
63
|
+
else
|
64
|
+
raise InvalidCalcException, xml["cServico"].first["MsgErro"].first
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: correios
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Bruno Frank
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-29 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: xml-simple
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Gem para calculo de valor e restreamento dos correios
|
36
|
+
email: bfscordeiro@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- CHANGELOG
|
43
|
+
- README.rdoc
|
44
|
+
- lib/correios.rb
|
45
|
+
files:
|
46
|
+
- CHANGELOG
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- init.rb
|
50
|
+
- lib/correios.rb
|
51
|
+
- Manifest
|
52
|
+
- correios.gemspec
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: https://github.com/brunofrank/correios
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --line-numbers
|
60
|
+
- --inline-source
|
61
|
+
- --title
|
62
|
+
- Correios
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 11
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 2
|
85
|
+
version: "1.2"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: correios
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Gem para calculo de valor e restreamento dos correios
|
93
|
+
test_files: []
|
94
|
+
|