correios-sro-xml 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
+ == Versão 0.0.4
2
+ - Correção: Lugar de encode é no Parser e não no WebService.
3
+
1
4
  == Versão 0.0.3
2
- - Melhoria: {Issue #2: Problema de encoding}[https://github.com/prodis/correios-sro-xml/pull/2].
5
+ - Correção: {Issue #2: Problema de encoding}[https://github.com/prodis/correios-sro-xml/pull/2].
3
6
 
4
7
  == Versão 0.0.2
5
8
  - Melhoria: {Issue #1: Incluindo campo hora}[https://github.com/prodis/correios-sro-xml/pull/1].
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "correios-sro-xml"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Prodis a.k.a. Fernando Hamasaki"]
@@ -6,6 +6,7 @@ module Correios
6
6
  class Parser
7
7
  def objetos(xml)
8
8
  objetos = {}
9
+ xml = xml.backward_encode("UTF-8", "ISO-8859-1")
9
10
 
10
11
  doc = Nokogiri::XML(xml)
11
12
  doc.xpath("//objeto").each do |element|
@@ -4,7 +4,7 @@ module Correios
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- PATCH = 3
7
+ PATCH = 4
8
8
  VERSION = [MAJOR, MINOR, PATCH].join(".")
9
9
  end
10
10
  end
@@ -15,7 +15,7 @@ module Correios
15
15
 
16
16
  def request(sro)
17
17
  response = Net::HTTP.post_form(@uri, params_for(sro))
18
- response.body.backward_encode("UTF-8", "ISO-8859-1")
18
+ response.body
19
19
  end
20
20
 
21
21
  private
@@ -3,19 +3,24 @@ require 'spec_helper'
3
3
 
4
4
  describe Correios::SRO::Parser do
5
5
  describe "#objetos" do
6
- before :each do
7
- xml = body_for :success_response_many_objects
8
- parser = Correios::SRO::Parser.new
9
- @objetos = parser.objetos(xml)
6
+ let(:xml) { body_for :success_response_many_objects }
7
+ let(:parser) { Correios::SRO::Parser.new }
8
+
9
+ it "encodes from ISO-8859-1 to UTF-8" do
10
+ xml.should_receive(:backward_encode).with("UTF-8", "ISO-8859-1").and_return(xml)
11
+ parser.objetos(xml)
10
12
  end
11
13
 
12
14
  ["SI047624825BR", "SX104110463BR"].each do |number|
13
15
  it "returns object number" do
14
- @objetos[number].numero.should == number
16
+ objetos = parser.objetos(xml)
17
+ objetos[number].numero.should == number
15
18
  end
16
19
  end
17
20
 
18
21
  context "returns event" do
22
+ before(:each) { @objetos = parser.objetos(xml) }
23
+
19
24
  { "SI047624825BR" => {
20
25
  :tipo => "BDI",
21
26
  :status => "01",
@@ -57,6 +62,8 @@ describe Correios::SRO::Parser do
57
62
  end
58
63
 
59
64
  context "returns destination" do
65
+ before(:each) { @objetos = parser.objetos(xml) }
66
+
60
67
  { "SI047624825BR" => {
61
68
  :local => "CTE VILA MARIA",
62
69
  :codigo => "02170975",
@@ -6,13 +6,6 @@ describe Correios::SRO::WebService do
6
6
  let(:sro) { Correios::SRO::Rastreador.new }
7
7
  let(:web_service) { Correios::SRO::WebService.new }
8
8
 
9
- it "encodes from ISO-8859-1 to UTF-8" do
10
- response = double("response", :body => "<xml><fake></fake>")
11
- response.body.should_receive(:backward_encode).with("UTF-8", "ISO-8859-1")
12
- Net::HTTP.stub(:post_form).and_return(response)
13
- web_service.request(sro)
14
- end
15
-
16
9
  it "returns XML response" do
17
10
  fake_request_for("<xml><fake></fake>")
18
11
  web_service.request(sro).should == "<xml><fake></fake>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: correios-sro-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log-me
16
- requirement: &11300850 !ruby/object:Gem::Requirement
16
+ requirement: &11301360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11300850
24
+ version_requirements: *11301360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &11300240 !ruby/object:Gem::Requirement
27
+ requirement: &11300280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11300240
35
+ version_requirements: *11300280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sax-machine
38
- requirement: &11299850 !ruby/object:Gem::Requirement
38
+ requirement: &11299360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *11299850
46
+ version_requirements: *11299360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fakeweb
49
- requirement: &11299430 !ruby/object:Gem::Requirement
49
+ requirement: &11298680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.3'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11299430
57
+ version_requirements: *11298680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &11298700 !ruby/object:Gem::Requirement
60
+ requirement: &11297320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.8'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *11298700
68
+ version_requirements: *11297320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &11298340 !ruby/object:Gem::Requirement
71
+ requirement: &11296780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '2.9'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *11298340
79
+ version_requirements: *11296780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: ruby-debug
82
- requirement: &11298100 !ruby/object:Gem::Requirement
82
+ requirement: &11312530 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *11298100
90
+ version_requirements: *11312530
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: ruby-debug19
93
- requirement: &11297770 !ruby/object:Gem::Requirement
93
+ requirement: &11311710 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *11297770
101
+ version_requirements: *11311710
102
102
  description: Sistema de Rastreamento de Objetos dos Correios (SRO) utilizando o Web
103
103
  Service SRO XML, que permite a consulta de ate 50 encomendas simultaneamente.
104
104
  email: prodis@gmail.com