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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5304bbd81d83f760e5828196f54a4e7bbb5e2fd5
4
- data.tar.gz: 0492be9b896f68b266b72c979b80ed6dff68d238
3
+ metadata.gz: 33ba03e4d4da8858a2d3ba57add938e5257dd87d
4
+ data.tar.gz: b213f940b135bbf21283c4564decbd0ef0ad9b4e
5
5
  SHA512:
6
- metadata.gz: 23cc2288024f0dd02ef64425c55b0cfcf5f0902f3befdc1b5662cb1c90e903b2c29b2d6391dfe62659d46d239db9b37138e5d90497f106f05b0ac11991712ac4
7
- data.tar.gz: 1ffc569c2d430c092d616534a070584a71b7beb0256f049cd8a31288374286612f2524472706a32e95729c13ff91419d5d68f2600013dd7b18e87132efa839e8
6
+ metadata.gz: e093e621eb02f17f8e491d4471e2e28d272f91b19302316c8579d0048ecd1e594c62f925e71a00ecef5b17ac56af666eefa14902ab1491121e9aaabf9460f9bb
7
+ data.tar.gz: ff206b65aaef71d71825f66612d2230bfa9e5a56bd5ea48d81ff8587376ee93ff179d3ad824020861ee4ef83fb11bb3357cac4bf88de990b0eff9eb0325875fe
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: bundle exec rspec
@@ -1,3 +1,6 @@
1
+ == Version 0.2.1
2
+ - New: User and password can be set on configuration.
3
+
1
4
  == Version 0.2.0
2
5
  - Warning: Minimal required Ruby version from now is 1.9.3.
3
6
  - Improvement: Update LogMe gem to version 0.0.6 with support to log request and response messages.
@@ -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
- To disable the log and configure other log output, use <b>Correios::SRO</b> module:
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
@@ -1,3 +1,4 @@
1
+ require 'correios/sro/access_data'
1
2
  require 'correios/sro/timeout'
2
3
  require 'correios/sro'
3
4
  require 'correios/sro/destination'
@@ -3,6 +3,7 @@ require 'log-me'
3
3
  module Correios
4
4
  module SRO
5
5
  extend LogMe
6
+ extend Correios::SRO::AccessData
6
7
  extend Correios::SRO::Timeout
7
8
  end
8
9
  end
@@ -0,0 +1,7 @@
1
+ module Correios
2
+ module SRO
3
+ module AccessData
4
+ attr_accessor :user, :password
5
+ end
6
+ end
7
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Correios
2
2
  module SRO
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -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,
@@ -1,20 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Correios::SRO do
4
- describe "#request_timeout" do
5
- it "default is 5" do
6
- Correios::SRO.request_timeout.should eql 5
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
- context "when set timeout" do
10
- it "returns timeout" do
11
- Correios::SRO.configure { |config| config.request_timeout = 3 }
12
- Correios::SRO.request_timeout.should eql 3
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
- it "returns timeout in seconds (integer)" do
16
- Correios::SRO.configure { |config| config.request_timeout = 2.123 }
17
- Correios::SRO.request_timeout.should eql 2
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.0
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-25 00:00:00.000000000 Z
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