correios-sro-xml 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/CHANGELOG.rdoc +14 -8
- data/Gemfile +1 -12
- data/README.rdoc +181 -35
- data/Rakefile +13 -35
- data/correios-sro-xml.gemspec +24 -80
- data/lib/correios-sro-xml.rb +4 -4
- data/lib/correios/sro.rb +11 -0
- data/lib/correios/sro/destination.rb +16 -0
- data/lib/correios/sro/event.rb +31 -0
- data/lib/correios/sro/object.rb +13 -0
- data/lib/correios/sro/parser.rb +5 -5
- data/lib/correios/sro/tracker.rb +43 -0
- data/lib/correios/sro/version.rb +1 -6
- data/lib/correios/sro/web_service.rb +64 -11
- data/misc/correios_sro_xml_manual_v1.5.pdf +0 -0
- data/spec/correios/sro/event_spec.rb +15 -0
- data/spec/correios/sro/parser_spec.rb +44 -44
- data/spec/correios/sro/tracker_spec.rb +116 -0
- data/spec/correios/sro/web_service_spec.rb +10 -4
- data/spec/correios/sro_spec.rb +22 -0
- data/spec/spec_helper.rb +3 -5
- data/spec/support/mock_request.rb +22 -0
- data/spec/support/responses/failure_response_not_found.xml +6 -0
- data/spec/support/responses/{success-response-many-objects.xml → success_response_many_objects.xml} +0 -0
- data/spec/support/responses/{success-response-many-objects-international.xml → success_response_many_objects_international.xml} +0 -0
- data/spec/support/responses/{success-response-one-object.xml → success_response_one_object.xml} +0 -0
- metadata +54 -59
- data/Gemfile.lock +0 -62
- data/lib/correios/sro/destino.rb +0 -16
- data/lib/correios/sro/evento.rb +0 -31
- data/lib/correios/sro/objeto.rb +0 -13
- data/lib/correios/sro/rastreador.rb +0 -43
- data/spec/correios/sro/evento_spec.rb +0 -15
- data/spec/correios/sro/rastreador_spec.rb +0 -53
- data/spec/support/fake_request.rb +0 -21
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Correios::SRO::Evento do
|
5
|
-
let(:evento) { Correios::SRO::Evento.new }
|
6
|
-
|
7
|
-
[:recebedor, :documento, :comentario].each do |method|
|
8
|
-
describe "##{method}=" do
|
9
|
-
it "strips string" do
|
10
|
-
evento.send("#{method}=", " Texto. ")
|
11
|
-
evento.send(method).should == "Texto."
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Correios::SRO::Rastreador do
|
5
|
-
describe ".new" do
|
6
|
-
context "creates with default value of" do
|
7
|
-
before(:each) { @sro = Correios::SRO::Rastreador.new }
|
8
|
-
|
9
|
-
{ :tipo => :lista,
|
10
|
-
:resultado => :ultimo,
|
11
|
-
:objetos => []
|
12
|
-
}.each do |attr, value|
|
13
|
-
it attr do
|
14
|
-
@sro.send(attr).should == value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
{ :usuario => "USUARIO",
|
20
|
-
:senha => "SENHA",
|
21
|
-
:tipo => :intervalo,
|
22
|
-
:resultado => :todos
|
23
|
-
}.each do |attr, value|
|
24
|
-
context "when #{attr} is supplied" do
|
25
|
-
it "sets #{attr}" do
|
26
|
-
sro = Correios::SRO::Rastreador.new(attr => value)
|
27
|
-
sro.send(attr).should == value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when #{attr} is supplied in a block" do
|
32
|
-
it "sets #{attr}" do
|
33
|
-
sro = Correios::SRO::Rastreador.new { |f| f.send("#{attr}=", value) }
|
34
|
-
sro.send(attr).should == value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#consultar" do
|
41
|
-
before :each do
|
42
|
-
fake_request_for :success_response_many_objects
|
43
|
-
@sro = Correios::SRO::Rastreador.new :usuario => "USUARIO", :senha => "SENHA"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "sets objetos" do
|
47
|
-
@sro.consultar("SQ458226057B", "RA132678652BR")
|
48
|
-
@sro.objetos.size.should == 2
|
49
|
-
@sro.objetos.first.should == "SQ458226057B"
|
50
|
-
@sro.objetos.last.should == "RA132678652BR"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
def fake_request_for(response)
|
4
|
-
FakeWeb.register_uri(:post,
|
5
|
-
Regexp.new("http://websro.correios.com.br/sro_bin/sroii_xml.eventos"),
|
6
|
-
:status => 200,
|
7
|
-
:body => body_for(response))
|
8
|
-
end
|
9
|
-
|
10
|
-
def body_for(response)
|
11
|
-
case response
|
12
|
-
when :success_response_one_object
|
13
|
-
File.open(File.dirname(__FILE__) + "/responses/success-response-one-object.xml").read
|
14
|
-
when :success_response_many_objects
|
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
|
18
|
-
else
|
19
|
-
response
|
20
|
-
end
|
21
|
-
end
|