correios-sro-xml 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == Versão 0.0.3
2
+ - Melhoria: {Issue #2: Problema de encoding}[https://github.com/prodis/correios-sro-xml/pull/2].
3
+
1
4
  == Versão 0.0.2
2
5
  - Melhoria: {Issue #1: Incluindo campo hora}[https://github.com/prodis/correios-sro-xml/pull/1].
3
6
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "correios-sro-xml"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
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"]
12
- s.date = "2012-04-04"
12
+ s.date = "2012-04-18"
13
13
  s.description = "Sistema de Rastreamento de Objetos dos Correios (SRO) utilizando o Web Service SRO XML, que permite a consulta de ate 50 encomendas simultaneamente."
14
14
  s.email = "prodis@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/correios/sro/objeto.rb",
31
31
  "lib/correios/sro/parser.rb",
32
32
  "lib/correios/sro/rastreador.rb",
33
+ "lib/correios/sro/string.rb",
33
34
  "lib/correios/sro/version.rb",
34
35
  "lib/correios/sro/web_service.rb",
35
36
  "spec/correios/sro/evento_spec.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "spec/correios/sro/web_service_spec.rb",
39
40
  "spec/spec_helper.rb",
40
41
  "spec/support/fake_request.rb",
42
+ "spec/support/responses/success-response-many-objects-international.xml",
41
43
  "spec/support/responses/success-response-many-objects.xml",
42
44
  "spec/support/responses/success-response-one-object.xml"
43
45
  ]
@@ -6,4 +6,5 @@ require 'correios/sro/evento'
6
6
  require 'correios/sro/objeto'
7
7
  require 'correios/sro/parser'
8
8
  require 'correios/sro/rastreador'
9
+ require 'correios/sro/string'
9
10
  require 'correios/sro/web_service'
@@ -0,0 +1,10 @@
1
+ class String
2
+ def backward_encode(to, from)
3
+ if self.respond_to?(:encode)
4
+ self.encode(to, from)
5
+ else
6
+ require 'iconv'
7
+ Iconv.conv(to, from, self)
8
+ end
9
+ end
10
+ end
@@ -4,7 +4,7 @@ module Correios
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- PATCH = 2
7
+ PATCH = 3
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
18
+ response.body.backward_encode("UTF-8", "ISO-8859-1")
19
19
  end
20
20
 
21
21
  private
@@ -51,4 +51,3 @@ describe Correios::SRO::Rastreador do
51
51
  end
52
52
  end
53
53
  end
54
-
@@ -6,6 +6,13 @@ 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
+
9
16
  it "returns XML response" do
10
17
  fake_request_for("<xml><fake></fake>")
11
18
  web_service.request(sro).should == "<xml><fake></fake>"
@@ -13,6 +13,8 @@ def body_for(response)
13
13
  File.open(File.dirname(__FILE__) + "/responses/success-response-one-object.xml").read
14
14
  when :success_response_many_objects
15
15
  File.open(File.dirname(__FILE__) + "/responses/success-response-many-objects.xml").read
16
+ when :success_response_many_objects_international
17
+ File.open(File.dirname(__FILE__) + "/responses/success-response-many-objects-international.xml").read
16
18
  else
17
19
  response
18
20
  end
@@ -0,0 +1,110 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?>
2
+ <sroxml>
3
+ <versao>1.0</versao>
4
+ <qtd>1</qtd>
5
+ <TipoPesquisa>Lista de Objetos</TipoPesquisa>
6
+ <TipoResultado>Todos os eventos</TipoResultado>
7
+ <objeto>
8
+ <numero>EC688801478US</numero>
9
+ <evento>
10
+ <tipo>RO</tipo>
11
+ <status>01</status>
12
+ <data>09/04/2012</data>
13
+ <hora>13:32</hora>
14
+ <descricao>Encaminhado</descricao>
15
+ <local>UNIDADE TRAT INTERNACIONAL SAO PAULO</local>
16
+ <codigo>05314980</codigo>
17
+ <cidade>SAO PAULO</cidade>
18
+ <uf>SP</uf>
19
+ <sto>99999999</sto>
20
+ <destino>
21
+ <local>RFB - FISCALIZAÇÃO/CUSTOMS</local>
22
+ <codigo>00002999</codigo>
23
+ <cidade></cidade>
24
+ <bairro></bairro>
25
+ <uf></uf>
26
+ </destino>
27
+ </evento>
28
+ <evento>
29
+ <tipo>RO</tipo>
30
+ <status>01</status>
31
+ <data>09/04/2012</data>
32
+ <hora>13:32</hora>
33
+ <descricao>Encaminhado</descricao>
34
+ <local>UNIDADE TRAT INTERNACIONAL SAO PAULO</local>
35
+ <codigo>05314980</codigo>
36
+ <cidade>SAO PAULO</cidade>
37
+ <uf>SP</uf>
38
+ <sto>99999999</sto>
39
+ <destino>
40
+ <local>RFB - FISCALIZAÇÃO/CUSTOMS</local>
41
+ <codigo>00002999</codigo>
42
+ <cidade></cidade>
43
+ <bairro></bairro>
44
+ <uf></uf>
45
+ </destino>
46
+ </evento>
47
+ <evento>
48
+ <tipo>PAR</tipo>
49
+ <status>16</status>
50
+ <data>09/04/2012</data>
51
+ <hora>13:30</hora>
52
+ <descricao>Conferido</descricao>
53
+ <local>UNIDADE TRAT INTERNACIONAL SAO PAULO</local>
54
+ <codigo>05314980</codigo>
55
+ <cidade>SAO PAULO</cidade>
56
+ <uf>SP</uf>
57
+ <sto>99999999</sto>
58
+ </evento>
59
+ <evento>
60
+ <tipo>RO</tipo>
61
+ <status>01</status>
62
+ <data>05/04/2012</data>
63
+ <hora>10:06</hora>
64
+ <descricao>Encaminhado</descricao>
65
+ <local>ESTADOS UNIDOS DA AMÉRICA</local>
66
+ <codigo>00840000</codigo>
67
+ <cidade></cidade>
68
+ <uf></uf>
69
+ <sto>99999999</sto>
70
+ <destino>
71
+ <local>UNIDADE DE TRATAMENTO INTERNACIONAL</local>
72
+ <codigo>00500001</codigo>
73
+ <cidade>BRASIL</cidade>
74
+ <bairro></bairro>
75
+ <uf></uf>
76
+ </destino>
77
+ </evento>
78
+ <evento>
79
+ <tipo>RO</tipo>
80
+ <status>01</status>
81
+ <data>04/04/2012</data>
82
+ <hora>14:23</hora>
83
+ <descricao>Encaminhado</descricao>
84
+ <local>ESTADOS UNIDOS DA AMÉRICA</local>
85
+ <codigo>00840000</codigo>
86
+ <cidade></cidade>
87
+ <uf></uf>
88
+ <sto>99999999</sto>
89
+ <destino>
90
+ <local>UNIDADE DE TRATAMENTO INTERNACIONAL</local>
91
+ <codigo>00500001</codigo>
92
+ <cidade>BRASIL</cidade>
93
+ <bairro></bairro>
94
+ <uf></uf>
95
+ </destino>
96
+ </evento>
97
+ <evento>
98
+ <tipo>PAR</tipo>
99
+ <status>18</status>
100
+ <data>04/04/2012</data>
101
+ <hora>14:22</hora>
102
+ <descricao>Conferido</descricao>
103
+ <local>ESTADOS UNIDOS DA AMÉRICA</local>
104
+ <codigo>00840000</codigo>
105
+ <cidade></cidade>
106
+ <uf></uf>
107
+ <sto>99999999</sto>
108
+ </evento>
109
+ </objeto>
110
+ </sroxml>
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ 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: &11748970 !ruby/object:Gem::Requirement
16
+ requirement: &11300850 !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: *11748970
24
+ version_requirements: *11300850
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &11748730 !ruby/object:Gem::Requirement
27
+ requirement: &11300240 !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: *11748730
35
+ version_requirements: *11300240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sax-machine
38
- requirement: &11748490 !ruby/object:Gem::Requirement
38
+ requirement: &11299850 !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: *11748490
46
+ version_requirements: *11299850
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fakeweb
49
- requirement: &11748250 !ruby/object:Gem::Requirement
49
+ requirement: &11299430 !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: *11748250
57
+ version_requirements: *11299430
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &11748010 !ruby/object:Gem::Requirement
60
+ requirement: &11298700 !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: *11748010
68
+ version_requirements: *11298700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &11747770 !ruby/object:Gem::Requirement
71
+ requirement: &11298340 !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: *11747770
79
+ version_requirements: *11298340
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: ruby-debug
82
- requirement: &11747530 !ruby/object:Gem::Requirement
82
+ requirement: &11298100 !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: *11747530
90
+ version_requirements: *11298100
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: ruby-debug19
93
- requirement: &11763670 !ruby/object:Gem::Requirement
93
+ requirement: &11297770 !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: *11763670
101
+ version_requirements: *11297770
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
@@ -121,6 +121,7 @@ files:
121
121
  - lib/correios/sro/objeto.rb
122
122
  - lib/correios/sro/parser.rb
123
123
  - lib/correios/sro/rastreador.rb
124
+ - lib/correios/sro/string.rb
124
125
  - lib/correios/sro/version.rb
125
126
  - lib/correios/sro/web_service.rb
126
127
  - spec/correios/sro/evento_spec.rb
@@ -129,6 +130,7 @@ files:
129
130
  - spec/correios/sro/web_service_spec.rb
130
131
  - spec/spec_helper.rb
131
132
  - spec/support/fake_request.rb
133
+ - spec/support/responses/success-response-many-objects-international.xml
132
134
  - spec/support/responses/success-response-many-objects.xml
133
135
  - spec/support/responses/success-response-one-object.xml
134
136
  homepage: http://github.com/prodis/correios-sro-xml