cadun 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cadun/gateway.rb +9 -1
- data/lib/cadun/user.rb +12 -3
- data/lib/cadun/version.rb +2 -2
- data/spec/cadun/user_spec.rb +23 -16
- data/spec/spec_helper.rb +6 -0
- data/spec/support/fixtures/email.xml +57 -0
- metadata +4 -5
data/lib/cadun/gateway.rb
CHANGED
@@ -18,7 +18,15 @@ module Cadun
|
|
18
18
|
|
19
19
|
protected
|
20
20
|
def content_resource
|
21
|
-
|
21
|
+
subject = if @options[:email]
|
22
|
+
"email/#{@options[:email]}"
|
23
|
+
elsif @options[:cadun_id]
|
24
|
+
@options[:cadun_id]
|
25
|
+
else
|
26
|
+
authorization.xpath("usuarioID").text
|
27
|
+
end
|
28
|
+
|
29
|
+
get "/cadunii/ws/resources/pessoa/#{subject}"
|
22
30
|
end
|
23
31
|
|
24
32
|
def get(path)
|
data/lib/cadun/user.rb
CHANGED
@@ -2,7 +2,7 @@ module Cadun
|
|
2
2
|
class User
|
3
3
|
attr_reader :gateway
|
4
4
|
|
5
|
-
{ "id" => "
|
5
|
+
{ "id" => "cadun_id",
|
6
6
|
"nome" => "name",
|
7
7
|
"emailPrincipal" => "email",
|
8
8
|
"tipoUsuario" => "user_type",
|
@@ -16,7 +16,16 @@ module Cadun
|
|
16
16
|
define_method(method) { gateway.content.xpath(path).text }
|
17
17
|
end
|
18
18
|
|
19
|
-
alias :id :
|
19
|
+
alias :id :cadun_id
|
20
|
+
|
21
|
+
def self.find_by_email(email)
|
22
|
+
email = "#{email}@globo.com" unless email =~ /^.*@.*$/
|
23
|
+
new(:email => email)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find_by_id(cadun_id)
|
27
|
+
new(:cadun_id => cadun_id)
|
28
|
+
end
|
20
29
|
|
21
30
|
def initialize(options = {})
|
22
31
|
@gateway = Gateway.new(options)
|
@@ -39,7 +48,7 @@ module Cadun
|
|
39
48
|
end
|
40
49
|
|
41
50
|
def to_hash
|
42
|
-
%w(
|
51
|
+
%w(cadun_id name email user_type gender neighborhood city state country address birthday phone mobile login cpf zipcode status complement).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = send(method); hash }
|
43
52
|
end
|
44
53
|
|
45
54
|
def method_missing(method)
|
data/lib/cadun/version.rb
CHANGED
data/spec/cadun/user_spec.rb
CHANGED
@@ -54,28 +54,15 @@ describe Cadun::User do
|
|
54
54
|
|
55
55
|
verify_method "user_type", "NAO_ASSINANTE"
|
56
56
|
|
57
|
-
verify_method "
|
57
|
+
verify_method "cadun_id", "21737810"
|
58
58
|
|
59
59
|
verify_method "complement", "807"
|
60
60
|
end
|
61
61
|
|
62
|
-
context "when the user id is given" do
|
63
|
-
subject { Cadun::User.new :user_id => "10001000" }
|
64
|
-
|
65
|
-
it "should load the gateway" do
|
66
|
-
mock(Cadun::Gateway).new(hash_including(:user_id => "10001000"))
|
67
|
-
subject
|
68
|
-
end
|
69
|
-
|
70
|
-
verify_method "id", "10001000"
|
71
|
-
|
72
|
-
verify_method "name", "Guilherme Chico"
|
73
|
-
end
|
74
|
-
|
75
62
|
describe "#to_hash" do
|
76
|
-
subject { Cadun::User.new(:
|
63
|
+
subject { Cadun::User.new(:cadun_id => "10001000").to_hash }
|
77
64
|
|
78
|
-
specify { should include(:
|
65
|
+
specify { should include(:cadun_id => "10001000") }
|
79
66
|
specify { should include(:name => "Guilherme Chico") }
|
80
67
|
specify { should include(:email => "fab1@spam.la") }
|
81
68
|
specify { should include(:user_type => "NAO_ASSINANTE") }
|
@@ -94,4 +81,24 @@ describe Cadun::User do
|
|
94
81
|
specify { should include(:status => "ATIVO") }
|
95
82
|
specify { should include(:complement => "807") }
|
96
83
|
end
|
84
|
+
|
85
|
+
describe ".find_by_email" do
|
86
|
+
context "given an email without domain" do
|
87
|
+
subject { Cadun::User.find_by_email("silvano") }
|
88
|
+
|
89
|
+
verify_method "id", "24510533"
|
90
|
+
end
|
91
|
+
|
92
|
+
context "given an email with domain" do
|
93
|
+
subject { Cadun::User.find_by_email("silvano@corp.globo.com") }
|
94
|
+
|
95
|
+
verify_method "id", "24510533"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe ".find_by_id" do
|
100
|
+
subject { Cadun::User.find_by_id("10001000") }
|
101
|
+
|
102
|
+
verify_method "id", "10001000"
|
103
|
+
end
|
97
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,6 +26,12 @@ def stub_requests
|
|
26
26
|
|
27
27
|
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/10001000",
|
28
28
|
:body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml"
|
29
|
+
|
30
|
+
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com",
|
31
|
+
:body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml"
|
32
|
+
|
33
|
+
FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com",
|
34
|
+
:body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml"
|
29
35
|
end
|
30
36
|
|
31
37
|
def load_config
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<pessoa>
|
3
|
+
<id>24510533</id>
|
4
|
+
<alteracao>2011-05-05T00:00:00-03:00</alteracao>
|
5
|
+
<bairro>Barra da Tijuca</bairro>
|
6
|
+
<cep>22793380</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>AP 1711</complemento>
|
14
|
+
<cookie>000009gUMBNm3lygWTdpVUbWm6Ha7yWK</cookie>
|
15
|
+
<cpf>05359742720</cpf>
|
16
|
+
<criacao>2008-08-07T00:00:00-03:00</criacao>
|
17
|
+
<dadosAdicionais>
|
18
|
+
<atualizacao>2009-09-29T05:30:01-03:00</atualizacao>
|
19
|
+
<componenteId>21</componenteId>
|
20
|
+
<criacao>2008-08-07T01:52:30-03:00</criacao>
|
21
|
+
<usuarioId>24510533</usuarioId>
|
22
|
+
<valor>1759250SSPES</valor>
|
23
|
+
</dadosAdicionais>
|
24
|
+
<dataNascimento>1981-12-23T00:00:00-03:00</dataNascimento>
|
25
|
+
<emailPrincipal>silvano@corp.globo.com</emailPrincipal>
|
26
|
+
<endereco>Avenida Adolpho de Vasconcelos</endereco>
|
27
|
+
<estado>
|
28
|
+
<id>19</id>
|
29
|
+
<nome>Rio de Janeiro</nome>
|
30
|
+
<paisId>1</paisId>
|
31
|
+
<sigla>RJ</sigla>
|
32
|
+
</estado>
|
33
|
+
<estadoId>19</estadoId>
|
34
|
+
<login>silvano.silvano.2008</login>
|
35
|
+
<nome>Silvano Nogueira Buback</nome>
|
36
|
+
<numero>401</numero>
|
37
|
+
<optinCelular>false</optinCelular>
|
38
|
+
<optinGlobo>true</optinGlobo>
|
39
|
+
<optinParceiros>true</optinParceiros>
|
40
|
+
<origemId>181</origemId>
|
41
|
+
<pais>
|
42
|
+
<id>1</id>
|
43
|
+
<nome>Brasil</nome>
|
44
|
+
<sigla>BR</sigla>
|
45
|
+
</pais>
|
46
|
+
<paisId>1</paisId>
|
47
|
+
<perguntaId>2</perguntaId>
|
48
|
+
<resposta>astor</resposta>
|
49
|
+
<servicoOrigemId>807</servicoOrigemId>
|
50
|
+
<sexo>MASCULINO</sexo>
|
51
|
+
<status>ATIVO</status>
|
52
|
+
<telefoneCelular>82503193</telefoneCelular>
|
53
|
+
<telefoneCelularDdd>21</telefoneCelularDdd>
|
54
|
+
<telefoneResidencial>32171000</telefoneResidencial>
|
55
|
+
<telefoneResidencialDdd>21</telefoneResidencialDdd>
|
56
|
+
<tipoUsuario>NAO_ASSINANTE</tipoUsuario>
|
57
|
+
</pessoa>
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cadun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bruno
|
@@ -12,8 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-05-
|
16
|
-
default_executable:
|
15
|
+
date: 2011-05-30 00:00:00 Z
|
17
16
|
dependencies:
|
18
17
|
- !ruby/object:Gem::Dependency
|
19
18
|
name: nokogiri
|
@@ -97,9 +96,9 @@ files:
|
|
97
96
|
- spec/support/fixtures/another_config.yml
|
98
97
|
- spec/support/fixtures/autorizacao.xml
|
99
98
|
- spec/support/fixtures/config.yml
|
99
|
+
- spec/support/fixtures/email.xml
|
100
100
|
- spec/support/fixtures/pessoa.xml
|
101
101
|
- spec/support/fixtures/pessoa_2.xml
|
102
|
-
has_rdoc: true
|
103
102
|
homepage: https://github.com/azisaka/Cadun
|
104
103
|
licenses: []
|
105
104
|
|
@@ -123,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
122
|
requirements: []
|
124
123
|
|
125
124
|
rubyforge_project: cadun
|
126
|
-
rubygems_version: 1.
|
125
|
+
rubygems_version: 1.8.4
|
127
126
|
signing_key:
|
128
127
|
specification_version: 3
|
129
128
|
summary: A wrapper for the CadUn authentication/authorization API
|