correios-sro-xml 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +20 -4
- data/lib/correios-sro-xml.rb +1 -0
- data/lib/correios/sro.rb +1 -0
- data/lib/correios/sro/access_data.rb +7 -0
- data/lib/correios/sro/tracker.rb +8 -0
- data/lib/correios/sro/version.rb +1 -1
- data/spec/correios/sro/tracker_spec.rb +21 -0
- data/spec/correios/sro_spec.rb +28 -10
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33ba03e4d4da8858a2d3ba57add938e5257dd87d
|
4
|
+
data.tar.gz: b213f940b135bbf21283c4564decbd0ef0ad9b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e093e621eb02f17f8e491d4471e2e28d272f91b19302316c8579d0048ecd1e594c62f925e71a00ecef5b17ac56af666eefa14902ab1491121e9aaabf9460f9bb
|
7
|
+
data.tar.gz: ff206b65aaef71d71825f66612d2230bfa9e5a56bd5ea48d81ff8587376ee93ff179d3ad824020861ee4ef83fb11bb3357cac4bf88de990b0eff9eb0325875fe
|
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -4,6 +4,12 @@ Tracking Objects System from Correios - SRO (Sistema de Rastreamento de Objetos
|
|
4
4
|
|
5
5
|
http://prodis.net.br/images/ruby/2011/correios_logo.png
|
6
6
|
|
7
|
+
{<img src="https://badge.fury.io/rb/correios-sro-xml.png" alt="Gem Version" />}[http://badge.fury.io/rb/correios-sro-xml]
|
8
|
+
{<img src="https://travis-ci.org/prodis/correios-sro-xml.png?branch=master" alt="Build Status" />}[https://travis-ci.org/prodis/correios-sro-xml]
|
9
|
+
{<img src="https://coveralls.io/repos/prodis/correios-sro-xml/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/prodis/correios-sro-xml]
|
10
|
+
{<img src="https://codeclimate.com/github/prodis/correios-sro-xml.png" alt="Code Climate" />}[https://codeclimate.com/github/prodis/correios-sro-xml]
|
11
|
+
{<img src="https://gemnasium.com/prodis/correios-sro-xml.png" alt="Dependency Status" />}[https://gemnasium.com/prodis/correios-sro-xml]
|
12
|
+
|
7
13
|
In order to use SRO XML in production environment, it is necessary to request to Correios access data (user and password) for your company, as described in {Correios' Blog}[http://blog.correios.com.br/comercioeletronico/?p=218].
|
8
14
|
|
9
15
|
For development environment you can use follow access data:
|
@@ -81,13 +87,22 @@ In which you supplie the first and last objects numbers of an interval.
|
|
81
87
|
objects = sro.get("PB996681660BR", "PB996681700BR")
|
82
88
|
objects.keys # => ["PB996681660BR", "PB996681673BR", "PB996681687BR", "PB996681695BR", "PB996681700BR"]
|
83
89
|
|
90
|
+
|
84
91
|
== Configurations
|
85
92
|
|
93
|
+
Use <b>Correios::SRO</b> module to set all available gem configuration.
|
94
|
+
|
95
|
+
=== Access data
|
96
|
+
|
97
|
+
You can supply SRO XML Web Service user and password in configuration instead of each instance of <b>Correios::SRO::Tracker</b> class.
|
98
|
+
Correios::SRO.configure do |config|
|
99
|
+
config.user = "ECT"
|
100
|
+
config.password = "SRO"
|
101
|
+
end
|
102
|
+
|
86
103
|
=== Timeout
|
87
104
|
|
88
105
|
For default, the timeout for a request to SRO XML Web Service is <b>5 seconds</b>. If SRO XML Web Service does not respond, a <b>Timeout::Error</b> exception will be raised.
|
89
|
-
You can configure this timeout using <b>Correios::SRO</b> module.
|
90
|
-
|
91
106
|
Correios::SRO.configure do |config|
|
92
107
|
config.request_timeout = 3 # It configures timeout to 3 seconds
|
93
108
|
end
|
@@ -129,8 +144,7 @@ Log example:
|
|
129
144
|
</objeto>
|
130
145
|
</sroxml>
|
131
146
|
|
132
|
-
|
133
|
-
|
147
|
+
You can disable the log and configure other log output.
|
134
148
|
Correios::SRO.configure do |config|
|
135
149
|
config.log_enabled = false # It disables the log
|
136
150
|
config.logger = Rails.logger # It uses Rails logger
|
@@ -139,6 +153,8 @@ To disable the log and configure other log output, use <b>Correios::SRO</b> modu
|
|
139
153
|
=== Configuration example
|
140
154
|
|
141
155
|
Correios::SRO.configure do |config|
|
156
|
+
config.user = "ECT"
|
157
|
+
config.password = "SRO"
|
142
158
|
config.logger = Rails.logger
|
143
159
|
config.request_timeout = 3
|
144
160
|
end
|
data/lib/correios-sro-xml.rb
CHANGED
data/lib/correios/sro.rb
CHANGED
data/lib/correios/sro/tracker.rb
CHANGED
@@ -14,6 +14,8 @@ module Correios
|
|
14
14
|
|
15
15
|
yield self if block_given?
|
16
16
|
@object_numbers = []
|
17
|
+
|
18
|
+
set_attributes_from_config!
|
17
19
|
end
|
18
20
|
|
19
21
|
def get(*object_numbers)
|
@@ -30,6 +32,12 @@ module Correios
|
|
30
32
|
|
31
33
|
private
|
32
34
|
|
35
|
+
def set_attributes_from_config!
|
36
|
+
[:user, :password].each do |attr|
|
37
|
+
self.send("#{attr}=", Correios::SRO.send(attr)) unless self.send(attr)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
33
41
|
def web_service
|
34
42
|
@web_service ||= Correios::SRO::WebService.new(self)
|
35
43
|
end
|
data/lib/correios/sro/version.rb
CHANGED
@@ -8,6 +8,27 @@ describe Correios::SRO::Tracker do
|
|
8
8
|
expect(subject.object_numbers).to eql []
|
9
9
|
end
|
10
10
|
|
11
|
+
context "when access data is supplied on configuration" do
|
12
|
+
around do |example|
|
13
|
+
Correios::SRO.configure do |config|
|
14
|
+
config.user = "SROUSER"
|
15
|
+
config.password = "1q2w3e"
|
16
|
+
end
|
17
|
+
|
18
|
+
example.run
|
19
|
+
|
20
|
+
Correios::SRO.configure do |config|
|
21
|
+
config.user = nil
|
22
|
+
config.password = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses access data from configuration" do
|
27
|
+
expect(subject.user).to eql "SROUSER"
|
28
|
+
expect(subject.password).to eql "1q2w3e"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
11
32
|
{ user: "PRODIS",
|
12
33
|
password: "pim321",
|
13
34
|
query_type: :range,
|
data/spec/correios/sro_spec.rb
CHANGED
@@ -1,20 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Correios::SRO do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "timeout" do
|
5
|
+
describe "#request_timeout" do
|
6
|
+
it "default is 5" do
|
7
|
+
expect(Correios::SRO.request_timeout).to eql 5
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when set timeout" do
|
11
|
+
it "returns timeout" do
|
12
|
+
Correios::SRO.configure { |config| config.request_timeout = 3 }
|
13
|
+
expect(Correios::SRO.request_timeout).to eql 3
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns timeout in seconds (integer)" do
|
17
|
+
Correios::SRO.configure { |config| config.request_timeout = 2.123 }
|
18
|
+
expect(Correios::SRO.request_timeout).to eql 2
|
19
|
+
end
|
20
|
+
end
|
7
21
|
end
|
22
|
+
end
|
8
23
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Correios::SRO.
|
24
|
+
context "access data" do
|
25
|
+
describe "#user" do
|
26
|
+
it "returns configured user" do
|
27
|
+
Correios::SRO.configure { |config| config.user = "PRODIS" }
|
28
|
+
expect(Correios::SRO.user).to eql "PRODIS"
|
13
29
|
end
|
30
|
+
end
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
Correios::SRO.
|
32
|
+
describe "#password" do
|
33
|
+
it "returns configured password" do
|
34
|
+
Correios::SRO.configure { |config| config.password = "pim321" }
|
35
|
+
expect(Correios::SRO.password).to eql "pim321"
|
18
36
|
end
|
19
37
|
end
|
20
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios-sro-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: log-me
|
@@ -147,6 +147,7 @@ extra_rdoc_files: []
|
|
147
147
|
files:
|
148
148
|
- ".gitignore"
|
149
149
|
- ".rspec"
|
150
|
+
- ".travis.yml"
|
150
151
|
- CHANGELOG.rdoc
|
151
152
|
- Gemfile
|
152
153
|
- README.rdoc
|
@@ -154,6 +155,7 @@ files:
|
|
154
155
|
- correios-sro-xml.gemspec
|
155
156
|
- lib/correios-sro-xml.rb
|
156
157
|
- lib/correios/sro.rb
|
158
|
+
- lib/correios/sro/access_data.rb
|
157
159
|
- lib/correios/sro/destination.rb
|
158
160
|
- lib/correios/sro/event.rb
|
159
161
|
- lib/correios/sro/object.rb
|