cadun 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Rakefile +8 -0
- data/cadun.gemspec +27 -0
- data/lib/cadun/gateway.rb +32 -0
- data/lib/cadun/user.rb +40 -0
- data/lib/cadun.rb +13 -0
- data/spec/cadun/gateway_spec.rb +67 -0
- data/spec/cadun/user_spec.rb +69 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/fixtures/autorizacao.xml +13 -0
- data/spec/support/fixtures/pessoa.xml +77 -0
- metadata +127 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/cadun.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require "cadun"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cadun"
|
7
|
+
s.version = Cadun::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Bruno Azisaka Maciel"]
|
10
|
+
s.email = ["bruno@azisaka.com.br"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = ""
|
13
|
+
s.description = ""
|
14
|
+
|
15
|
+
s.rubyforge_project = "cadun"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'nokogiri'
|
23
|
+
s.add_development_dependency 'rack'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'rr'
|
26
|
+
s.add_development_dependency 'fakeweb'
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Cadun
|
2
|
+
class Gateway
|
3
|
+
def initialize(glb_id, ip, service_id)
|
4
|
+
@glb_id, @ip, @service_id = glb_id, ip, service_id
|
5
|
+
end
|
6
|
+
|
7
|
+
def content
|
8
|
+
@content ||= Nokogiri::XML(resource).children
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorization
|
12
|
+
@authorization ||= Nokogiri::XML(connection.put("/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@glb_id}</glbId><ip>#{@ip}</ip><servicoID>#{@service_id}</servicoID></usuarioAutorizado>", {'Content-Type' => 'text/xml'}).body).children
|
13
|
+
end
|
14
|
+
|
15
|
+
def resource
|
16
|
+
@resource ||= connection.get("/cadunii/ws/resources/pessoa/#{authorization.xpath("usuarioID").text}", {'Content-Type' => 'text/xml'}).body
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection
|
20
|
+
@connection ||= Net::HTTP.new(*(development? ? ["isp-authenticator.dev.globoi.com", 8280] : ["autenticacao.globo.com", 8080] ))
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def development?
|
25
|
+
if defined?(Rails)
|
26
|
+
Rails.env.development?
|
27
|
+
else
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cadun/user.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Cadun
|
2
|
+
class User
|
3
|
+
attr_reader :gateway
|
4
|
+
|
5
|
+
{ "id" => "id",
|
6
|
+
"nome" => "name",
|
7
|
+
"emailPrincipal" => "email",
|
8
|
+
"sexo" => "gender",
|
9
|
+
"bairro" => "suburb",
|
10
|
+
"cidade/nome" => "city",
|
11
|
+
"estado/sigla" => "state",
|
12
|
+
"pais/nome" => "country" }.each do |path, method|
|
13
|
+
define_method(method) { gateway.content.xpath(path).text }
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(glb_id, ip, service_id)
|
17
|
+
@gateway = Gateway.new(@glb_id, @ip, @service_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def address
|
21
|
+
"#{endereco}, #{numero}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def birthday
|
25
|
+
Date.parse(dataNascimento)
|
26
|
+
end
|
27
|
+
|
28
|
+
def phone
|
29
|
+
"#{telefoneResidencialDdd} #{telefoneResidencial}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def mobile
|
33
|
+
"#{telefoneCelularDdd} #{telefoneCelular}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method)
|
37
|
+
gateway.content.xpath(method.to_s).text
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/cadun.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cadun::Gateway do
|
4
|
+
subject { Cadun::Gateway.new("GLB_ID", "127.0.0.1", 2626) }
|
5
|
+
|
6
|
+
describe "#content" do
|
7
|
+
it "should parse the resource" do
|
8
|
+
connection = mock
|
9
|
+
response = mock
|
10
|
+
body = "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>"
|
11
|
+
mock(response).body { body }
|
12
|
+
|
13
|
+
mock(subject).authorization { Nokogiri::XML("<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</usuarioID></pessoa>").children }
|
14
|
+
mock(connection).get("/cadunii/ws/resources/pessoa/1", {'Content-Type' => 'text/xml'}) { response }
|
15
|
+
mock(subject).connection { connection }
|
16
|
+
|
17
|
+
subject.content.xpath('nome').text.should == 'Barack Obama'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#connection" do
|
22
|
+
context "when the environment is development" do
|
23
|
+
before { mock(subject).development? { true } }
|
24
|
+
|
25
|
+
it "should request from the development server" do
|
26
|
+
mock(Net::HTTP).new("isp-authenticator.dev.globoi.com", 8280)
|
27
|
+
subject.connection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the environment is not development" do
|
32
|
+
before { mock(subject).development? { false } }
|
33
|
+
|
34
|
+
it "should request from the production server" do
|
35
|
+
mock(Net::HTTP).new("autenticacao.globo.com", 8080)
|
36
|
+
subject.connection
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#authorization" do
|
42
|
+
it "should parse the authorization request" do
|
43
|
+
connection = mock
|
44
|
+
response = mock
|
45
|
+
mock(response).body { "<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</id></usuarioID>" }
|
46
|
+
mock(connection).put("/ws/rest/autorizacao", "<usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID>2626</servicoID></usuarioAutorizado>", {'Content-Type' => 'text/xml'}) { response }
|
47
|
+
mock(subject).connection { connection }
|
48
|
+
|
49
|
+
subject.authorization.xpath('usuarioID').text.should == '1'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#resource" do
|
54
|
+
it "should parse the resource request" do
|
55
|
+
connection = mock
|
56
|
+
response = mock
|
57
|
+
body = "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>"
|
58
|
+
mock(response).body { body }
|
59
|
+
|
60
|
+
mock(subject).authorization { Nokogiri::XML("<?xml version='1.0' encoding='utf-8'?><pessoa><usuarioID>1</usuarioID></pessoa>").children }
|
61
|
+
mock(connection).get("/cadunii/ws/resources/pessoa/1", {'Content-Type' => 'text/xml'}) { response }
|
62
|
+
mock(subject).connection { connection }
|
63
|
+
|
64
|
+
subject.resource.should == body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Cadun::User do
|
5
|
+
|
6
|
+
before { stub_requests }
|
7
|
+
|
8
|
+
subject { Cadun::User.new("GLB_ID", "127.0.0.1", 2626) }
|
9
|
+
|
10
|
+
describe "#id" do
|
11
|
+
it { subject.id.should == "21737810" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#name" do
|
15
|
+
it { subject.name.should == "Fabricio Rodrigo Lopes" }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#birthday" do
|
19
|
+
it { subject.birthday.should == Date.new(1983, 02, 22) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#phone" do
|
23
|
+
it { subject.phone.should == "21 22881060" }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#mobile" do
|
27
|
+
it { subject.mobile.should == "21 99999999" }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#email" do
|
31
|
+
it { subject.email.should == "fab1@spam.la"}
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#gender" do
|
35
|
+
it { subject.gender.should == "MASCULINO" }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#city" do
|
39
|
+
it { subject.city.should == "Rio de Janeiro"}
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#state" do
|
43
|
+
it { subject.state.should == "RJ" }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#status" do
|
47
|
+
it { subject.status.should == "ATIVO" }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#address" do
|
51
|
+
it { subject.address.should == "Rua Uruguai, 59"}
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#suburb" do
|
55
|
+
it { subject.suburb.should == "Andaraí" }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#cpf" do
|
59
|
+
it { subject.cpf.should == "09532034765" }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#login" do
|
63
|
+
it { subject.login.should == "fabricio_fab1" }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#country" do
|
67
|
+
it { subject.country.should == "Brasil" }
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../lib/cadun"
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before :suite do
|
8
|
+
FakeWeb.allow_net_connect = false
|
9
|
+
end
|
10
|
+
|
11
|
+
config.before :each do
|
12
|
+
FakeWeb.clean_registry
|
13
|
+
end
|
14
|
+
|
15
|
+
config.mock_with :rr
|
16
|
+
config.filter_run :focus => true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def stub_requests
|
21
|
+
FakeWeb.register_uri :put, "http://isp-authenticator.dev.globoi.com:8280/ws/rest/autorizacao",
|
22
|
+
:body => File.join(File.dirname(__FILE__), "support", "fixtures", "autorizacao.xml")
|
23
|
+
|
24
|
+
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
|
25
|
+
:body => File.join(File.dirname(__FILE__), "support", "fixtures", "pessoa.xml")
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<usuarioAutorizado>
|
3
|
+
<emailPrincipal>fab1@spam.la</emailPrincipal>
|
4
|
+
<glbId>1484e00106ea401d57902541631200e8a6d44556132366c754c4261655666625537614531655252536e6262626c63676676436c6c316744544d5636617651707a6d417a49756b6e3830415a4a394f36773a303a66616231407370616d2e6c61</glbId>
|
5
|
+
<ip>10.2.25.160</ip>
|
6
|
+
<login>fab1@spam.la</login>
|
7
|
+
<servicoID>2626</servicoID>
|
8
|
+
<status>AUTORIZADO</status>
|
9
|
+
<statusUsuario>ATIVO</statusUsuario>
|
10
|
+
<tipoUsuario>NAO_ASSINANTE</tipoUsuario>
|
11
|
+
<username>fabricio_fab1</username>
|
12
|
+
<usuarioID>21737810</usuarioID>
|
13
|
+
</usuarioAutorizado>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<pessoa>
|
3
|
+
<id>21737810</id>
|
4
|
+
<alteracao>2011-04-25T00:00:00-03:00</alteracao>
|
5
|
+
<bairro>Andaraí</bairro>
|
6
|
+
<cep>20510060</cep>
|
7
|
+
<cidade>
|
8
|
+
<estadoId>19</estadoId>
|
9
|
+
<id>7043</id>
|
10
|
+
<nome>Rio de Janeiro</nome>
|
11
|
+
</cidade>
|
12
|
+
<cidadeId>7043</cidadeId>
|
13
|
+
<complemento>807</complemento>
|
14
|
+
<cookie>0000097QgXvo9pYpqTFi1p21BBPvV0Al</cookie>
|
15
|
+
<cpf>09532034765</cpf>
|
16
|
+
<criacao>2009-05-08T00:00:00-03:00</criacao>
|
17
|
+
<dataNascimento>1983-02-22T00:00:00-03:00</dataNascimento>
|
18
|
+
<emailPrincipal>fab1@spam.la</emailPrincipal>
|
19
|
+
<endereco>Rua Uruguai</endereco>
|
20
|
+
<estado>
|
21
|
+
<id>19</id>
|
22
|
+
<nome>Rio de Janeiro</nome>
|
23
|
+
<paisId>1</paisId>
|
24
|
+
<sigla>RJ</sigla>
|
25
|
+
</estado>
|
26
|
+
<estadoId>19</estadoId>
|
27
|
+
<ipCadastro>127.0.0.1</ipCadastro>
|
28
|
+
<login>fabricio_fab1</login>
|
29
|
+
<modulos>
|
30
|
+
<criacao>2009-05-08T10:04:35-03:00</criacao>
|
31
|
+
<moduloID>2</moduloID>
|
32
|
+
<pessoaID>21737810</pessoaID>
|
33
|
+
</modulos>
|
34
|
+
<modulos>
|
35
|
+
<alteracao>2011-04-14T18:04:15-03:00</alteracao>
|
36
|
+
<criacao>2009-05-08T10:04:35-03:00</criacao>
|
37
|
+
<moduloID>1</moduloID>
|
38
|
+
<pessoaID>21737810</pessoaID>
|
39
|
+
</modulos>
|
40
|
+
<modulos>
|
41
|
+
<criacao>2009-05-08T10:04:35-03:00</criacao>
|
42
|
+
<moduloID>3</moduloID>
|
43
|
+
<pessoaID>21737810</pessoaID>
|
44
|
+
</modulos>
|
45
|
+
<modulos>
|
46
|
+
<criacao>2009-05-08T10:04:35-03:00</criacao>
|
47
|
+
<moduloID>4</moduloID>
|
48
|
+
<pessoaID>21737810</pessoaID>
|
49
|
+
</modulos>
|
50
|
+
<modulos>
|
51
|
+
<criacao>2009-05-08T10:04:35-03:00</criacao>
|
52
|
+
<moduloID>7</moduloID>
|
53
|
+
<pessoaID>21737810</pessoaID>
|
54
|
+
</modulos>
|
55
|
+
<nome>Fabricio Rodrigo Lopes</nome>
|
56
|
+
<numero>59</numero>
|
57
|
+
<optinCelular>false</optinCelular>
|
58
|
+
<optinGlobo>true</optinGlobo>
|
59
|
+
<optinParceiros>true</optinParceiros>
|
60
|
+
<origemId>181</origemId>
|
61
|
+
<pais>
|
62
|
+
<id>1</id>
|
63
|
+
<nome>Brasil</nome>
|
64
|
+
<sigla>BR</sigla>
|
65
|
+
</pais>
|
66
|
+
<paisId>1</paisId>
|
67
|
+
<perguntaId>3</perguntaId>
|
68
|
+
<resposta>preto</resposta>
|
69
|
+
<servicoOrigemId>807</servicoOrigemId>
|
70
|
+
<sexo>MASCULINO</sexo>
|
71
|
+
<status>ATIVO</status>
|
72
|
+
<telefoneCelular>99999999</telefoneCelular>
|
73
|
+
<telefoneCelularDdd>21</telefoneCelularDdd>
|
74
|
+
<telefoneResidencial>22881060</telefoneResidencial>
|
75
|
+
<telefoneResidencialDdd>21</telefoneResidencialDdd>
|
76
|
+
<tipoUsuario>NAO_ASSINANTE</tipoUsuario>
|
77
|
+
</pessoa>
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cadun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bruno Azisaka Maciel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-17 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: nokogiri
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rr
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: fakeweb
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
description: ""
|
72
|
+
email:
|
73
|
+
- bruno@azisaka.com.br
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- .rspec
|
83
|
+
- Gemfile
|
84
|
+
- Rakefile
|
85
|
+
- cadun.gemspec
|
86
|
+
- lib/cadun.rb
|
87
|
+
- lib/cadun/gateway.rb
|
88
|
+
- lib/cadun/user.rb
|
89
|
+
- spec/cadun/gateway_spec.rb
|
90
|
+
- spec/cadun/user_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/support/fixtures/autorizacao.xml
|
93
|
+
- spec/support/fixtures/pessoa.xml
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: ""
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project: cadun
|
118
|
+
rubygems_version: 1.6.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: ""
|
122
|
+
test_files:
|
123
|
+
- spec/cadun/gateway_spec.rb
|
124
|
+
- spec/cadun/user_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spec/support/fixtures/autorizacao.xml
|
127
|
+
- spec/support/fixtures/pessoa.xml
|