correios-ws 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -11
- data/correios-ws.gemspec +1 -0
- data/lib/correios-ws/version.rb +1 -1
- data/lib/correios-ws.rb +24 -0
- metadata +17 -1
data/README.md
CHANGED
@@ -5,19 +5,19 @@ correios-ws uses correios web-services SOAP to calculate shipping.
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
```shell
|
9
|
+
gem 'correios-ws'
|
10
|
+
```
|
11
11
|
And then execute:
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
```shell
|
13
|
+
bundle
|
14
|
+
```
|
15
15
|
Or install it yourself as:
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
```shell
|
17
|
+
gem install correios-ws
|
18
|
+
```
|
19
19
|
## Usage
|
20
|
-
|
20
|
+
```ruby
|
21
21
|
require 'correios-ws'
|
22
22
|
|
23
23
|
calculator = Correios::ShippingCalculator.new(codigo_empresa, senha)
|
@@ -29,7 +29,7 @@ package_data = Correios::PackageData.new do |p|
|
|
29
29
|
p.largura = '45'
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
calculator.calculate(cep_origem, cep_destino, package_date, array_with_services)
|
33
33
|
result = calculator.calculate('08061-430','08061-456', package_data, [
|
34
34
|
Correios::Servicos::PAC_SEM_CONTRATO,
|
35
35
|
Correios::Servicos::PAC_COM_CONTRATO,
|
@@ -91,6 +91,16 @@ puts esedex_com_contrato.entrega_sabado
|
|
91
91
|
puts esedex_com_contrato.error
|
92
92
|
puts esedex_com_contrato.msg_error
|
93
93
|
|
94
|
+
# Searching by CEP
|
95
|
+
|
96
|
+
address = Correios::get_address(cep)
|
97
|
+
puts address.rua
|
98
|
+
puts address.bairro
|
99
|
+
puts address.cidade
|
100
|
+
puts address.estado
|
101
|
+
puts address.cep
|
102
|
+
```
|
103
|
+
|
94
104
|
## Contributing
|
95
105
|
|
96
106
|
1. Fork it
|
data/correios-ws.gemspec
CHANGED
data/lib/correios-ws/version.rb
CHANGED
data/lib/correios-ws.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Correios
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class Address
|
6
|
+
attr_accessor :rua, :bairro, :cidade, :estado, :cep
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
yield self if block_given?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_address cep
|
14
|
+
url = "http://www.buscacep.correios.com.br/servicos/dnec/consultaEnderecoAction.do?relaxation=#{cep}&TipoCep=ALL&semelhante=N&cfm=1&Metodo=listaLogradouro&TipoConsulta=relaxation&StartRow=1&EndRow=10"
|
15
|
+
doc = doc = Nokogiri::HTML(open(url))
|
16
|
+
line = '//div[@id="lamina"]/div[@class="column2"]/div[@class="content"]/div[@class="ctrlcontent"]/div/table[1]/tr[1]/'
|
17
|
+
|
18
|
+
Address.new do |a|
|
19
|
+
a.rua = doc.xpath("#{line}td[1]").text.encode("UTF-8", undef: :replace, invalid: :replace)
|
20
|
+
a.bairro = doc.xpath("#{line}td[2]").text.encode("UTF-8", undef: :replace, invalid: :replace)
|
21
|
+
a.cidade = doc.xpath("#{line}td[3]").text.encode("UTF-8", undef: :replace, invalid: :replace)
|
22
|
+
a.estado = doc.xpath("#{line}td[4]").text.encode("UTF-8", undef: :replace, invalid: :replace)
|
23
|
+
a.cep = cep
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
3
27
|
class CalcPrecoPrazo
|
4
28
|
attr_accessor(:nCdEmpresa,
|
5
29
|
:sDsSenha,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios-ws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: correios-ws uses correios web-services SOAP to calculate shipping
|
31
47
|
email:
|
32
48
|
- andrewaguiar6@gmail.com
|