correios_sigep 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/correios_sigep.rb +1 -0
- data/lib/correios_sigep/builders/xml/authentication.rb +6 -5
- data/lib/correios_sigep/builders/xml/request.rb +5 -2
- data/lib/correios_sigep/configuration.rb +8 -0
- data/lib/correios_sigep/models/administrative_fields.rb +14 -0
- data/lib/correios_sigep/version.rb +1 -1
- data/spec/correios_sigep/builders/xml/request_spec.rb +46 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2FhYzFlYjAxZmJiOWRjNjI2MDVmMDk4ODk5ZjFkMDZhYWNkOTZlMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDFhMGYyMzU0NzBhMzI2MDRjYjQ5ODQ2NTQ5ZDhmYWE4NmQ4MjI2OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjRlYzY1YWI1MGZhNDBlODIwNzVjZjFmMDhmNWVjMmE4NWNiNThhNzRlNjE0
|
10
|
+
YTI2YWMzZjQ3N2JlMjk2MDg0ZmU5MTc4NjMyYjUzODc5NGQ2NmIxNjU4MzY2
|
11
|
+
ODkzNjFiYjZhY2M2MzUwMjU3NzM4OWQyZDkyZTY4M2UzNTE4OWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDVmMWIzZDBkMWNiZjViNzkzOWVmMmMxYThlZTMwOGI0NTFkYzM0ZTNmMDNl
|
14
|
+
MTAxOTBjMGRjNzMxN2Q0ZWEyNWY4ZGY5OGIyZmMwNWQyOGM1NWI0NGY5ZmQy
|
15
|
+
ZjJhMTFkMDI2NDM1Y2FkZDJkNTFlOWE0ZDc3MmU5NGQyNDZjZTU=
|
data/lib/correios_sigep.rb
CHANGED
@@ -2,18 +2,19 @@ module CorreiosSigep
|
|
2
2
|
module Builders
|
3
3
|
module XML
|
4
4
|
class Authentication
|
5
|
-
def initialize(builder)
|
5
|
+
def initialize(builder, administrative_fields)
|
6
6
|
@builder = builder
|
7
7
|
@config = CorreiosSigep.configuration
|
8
|
+
@administrative_fields = administrative_fields
|
8
9
|
end
|
9
10
|
|
10
11
|
def build_xml!
|
11
12
|
add_node "usuario", @config.user
|
12
13
|
add_node "senha", @config.password
|
13
|
-
add_node "codAdministrativo", @
|
14
|
-
add_node "contrato", @
|
15
|
-
add_node "codigo_servico", @
|
16
|
-
add_node "cartao", @
|
14
|
+
add_node "codAdministrativo", @administrative_fields.administrative_code
|
15
|
+
add_node "contrato", @administrative_fields.contract
|
16
|
+
add_node "codigo_servico", @administrative_fields.service_code
|
17
|
+
add_node "cartao", @administrative_fields.card
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
@@ -3,9 +3,12 @@ module CorreiosSigep
|
|
3
3
|
module XML
|
4
4
|
class Request
|
5
5
|
|
6
|
-
def self.build_xml(request)
|
6
|
+
def self.build_xml(request, overrides={})
|
7
|
+
config = CorreiosSigep.configuration
|
7
8
|
document = Nokogiri::XML(request.to_xml)
|
8
|
-
|
9
|
+
administrative_fields =
|
10
|
+
overrides[:administrative] || config.administrative_fields
|
11
|
+
XML::Authentication.new(document, administrative_fields).build_xml!
|
9
12
|
|
10
13
|
document
|
11
14
|
.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
@@ -2,5 +2,13 @@ module CorreiosSigep
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :administrative_code, :card, :contract, :password,
|
4
4
|
:service_code, :user, :wsdl_base_url, :proxy
|
5
|
+
|
6
|
+
def administrative_fields
|
7
|
+
@administrative_fields ||=
|
8
|
+
Models::AdministrativeFields.new(administrative_code: administrative_code,
|
9
|
+
card: card, contract: contract,
|
10
|
+
service_code: service_code)
|
11
|
+
|
12
|
+
end
|
5
13
|
end
|
6
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CorreiosSigep
|
2
|
+
module Models
|
3
|
+
class AdministrativeFields
|
4
|
+
attr_accessor :administrative_code, :card, :contract, :service_code
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
self.administrative_code = options[:administrative_code]
|
8
|
+
self.card = options[:card]
|
9
|
+
self.contract = options[:contract]
|
10
|
+
self.service_code = options[:service_code]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
module CorreiosSigep
|
5
|
+
module Builders
|
6
|
+
module XML
|
7
|
+
describe Request do
|
8
|
+
describe '.build_xml' do
|
9
|
+
let(:request) { double(:request, to_xml: '<root><test></root>') }
|
10
|
+
context 'when do not override anything' do
|
11
|
+
it 'builds a Authentication XML with Configuration parameters' do
|
12
|
+
expected_response = [
|
13
|
+
'<cartao>0057018901</cartao>',
|
14
|
+
'<codigo_servico>41076</codigo_servico>',
|
15
|
+
'<contrato>9912208555</contrato>',
|
16
|
+
'<codAdministrativo>08082650</codAdministrativo>',
|
17
|
+
'<senha>8o8otn</senha>',
|
18
|
+
'<usuario>60618043</usuario><test/>'
|
19
|
+
].join + "\n"
|
20
|
+
expect(described_class.build_xml request).to eq expected_response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when override the administrative fields' do
|
25
|
+
it 'builds a Authentication XML with the override parameter' do
|
26
|
+
administrative_fields = Models::AdministrativeFields.new(administrative_code: 'adm123',
|
27
|
+
card: 'card123',
|
28
|
+
contract: 'cont123',
|
29
|
+
service_code: 'ser123')
|
30
|
+
expected_response = [
|
31
|
+
'<cartao>card123</cartao>',
|
32
|
+
'<codigo_servico>ser123</codigo_servico>',
|
33
|
+
'<contrato>cont123</contrato>',
|
34
|
+
'<codAdministrativo>adm123</codAdministrativo>',
|
35
|
+
'<senha>8o8otn</senha>',
|
36
|
+
'<usuario>60618043</usuario><test/>'
|
37
|
+
].join + "\n"
|
38
|
+
expect(described_class.build_xml request, administrative: administrative_fields).to eq expected_response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios_sigep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Ribeiro
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/correios_sigep/logistic_reverse/base_client.rb
|
132
132
|
- lib/correios_sigep/logistic_reverse/request_collect_number.rb
|
133
133
|
- lib/correios_sigep/logistic_reverse/request_sro.rb
|
134
|
+
- lib/correios_sigep/models/administrative_fields.rb
|
134
135
|
- lib/correios_sigep/models/collect.rb
|
135
136
|
- lib/correios_sigep/models/correios_response_codes.rb
|
136
137
|
- lib/correios_sigep/models/errors/collect_not_answered_for_the_zipcode.rb
|
@@ -149,6 +150,7 @@ files:
|
|
149
150
|
- lib/correios_sigep/models/sro.rb
|
150
151
|
- lib/correios_sigep/version.rb
|
151
152
|
- spec/correios_sigep/builders/xml/request_collect_number_spec.rb
|
153
|
+
- spec/correios_sigep/builders/xml/request_spec.rb
|
152
154
|
- spec/correios_sigep/builders/xml/request_sro_spec.rb
|
153
155
|
- spec/correios_sigep/configuration_spec.rb
|
154
156
|
- spec/correios_sigep/logistic_reverse/base_client_spec.rb
|
@@ -202,6 +204,7 @@ specification_version: 4
|
|
202
204
|
summary: A gem that integrates with Correios SIGEP WEB.
|
203
205
|
test_files:
|
204
206
|
- spec/correios_sigep/builders/xml/request_collect_number_spec.rb
|
207
|
+
- spec/correios_sigep/builders/xml/request_spec.rb
|
205
208
|
- spec/correios_sigep/builders/xml/request_sro_spec.rb
|
206
209
|
- spec/correios_sigep/configuration_spec.rb
|
207
210
|
- spec/correios_sigep/logistic_reverse/base_client_spec.rb
|