cadun 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cadun/gateway.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Cadun
2
2
  class Gateway
3
- def initialize(glb_id, ip, service_id)
4
- @glb_id, @ip, @service_id = glb_id, ip, service_id
3
+ def initialize(options = {})
4
+ @options = options
5
5
  end
6
6
 
7
7
  def content
@@ -18,7 +18,7 @@ module Cadun
18
18
 
19
19
  protected
20
20
  def content_resource
21
- get "/cadunii/ws/resources/pessoa/#{authorization.xpath("usuarioID").text}"
21
+ get "/cadunii/ws/resources/pessoa/#{@options[:user_id] || authorization.xpath("usuarioID").text}"
22
22
  end
23
23
 
24
24
  def get(path)
@@ -26,7 +26,7 @@ module Cadun
26
26
  end
27
27
 
28
28
  def authorization_resource
29
- put "/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@glb_id}</glbId><ip>#{@ip}</ip><servicoID>#{@service_id}</servicoID></usuarioAutorizado>"
29
+ put "/ws/rest/autorizacao", "<usuarioAutorizado><glbId>#{@options[:glb_id]}</glbId><ip>#{@options[:ip]}</ip><servicoID>#{@options[:service_id]}</servicoID></usuarioAutorizado>"
30
30
  end
31
31
 
32
32
  def put(path, data)
data/lib/cadun/user.rb CHANGED
@@ -4,7 +4,8 @@ module Cadun
4
4
 
5
5
  { "id" => "id",
6
6
  "nome" => "name",
7
- "emailPrincipal" => "email",
7
+ "emailPrincipal" => "email",
8
+ "tipoUsuario" => "user_type",
8
9
  "sexo" => "gender",
9
10
  "bairro" => "neighborhood",
10
11
  "cidade/nome" => "city",
@@ -13,8 +14,8 @@ module Cadun
13
14
  define_method(method) { gateway.content.xpath(path).text }
14
15
  end
15
16
 
16
- def initialize(glb_id, ip, service_id)
17
- @gateway = Gateway.new(glb_id, ip, service_id)
17
+ def initialize(options = {})
18
+ @gateway = Gateway.new(options)
18
19
  end
19
20
 
20
21
  def address
data/lib/cadun/version.rb CHANGED
@@ -2,7 +2,7 @@ module Cadun
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY] * '.'
8
8
  end
@@ -9,7 +9,7 @@ describe Cadun::Gateway do
9
9
  mock(subject).connection { connection }
10
10
  end
11
11
 
12
- subject { Cadun::Gateway.new("GLB_ID", "127.0.0.1", 2626) }
12
+ subject { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
13
13
 
14
14
  describe "#content" do
15
15
  before do
@@ -2,9 +2,6 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Cadun::User do
5
- include Cadun
6
-
7
- subject { User.new "GLB_ID", "127.0.0.1", 2626 }
8
5
 
9
6
  def self.verify_method(method, value)
10
7
  describe "##{method}" do
@@ -17,38 +14,57 @@ describe Cadun::User do
17
14
  stub_requests
18
15
  end
19
16
 
20
- it "should load the gateway" do
21
- mock(Gateway).new "GLB_ID", "127.0.0.1", 2626
22
- subject
17
+ context "when the user id is not given" do
18
+ subject { Cadun::User.new :ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID" }
19
+
20
+ it "should load the gateway" do
21
+ mock(Cadun::Gateway).new(hash_including(:ip => "127.0.0.1", :service_id => 2626, :glb_id => "GLB_ID"))
22
+ subject
23
+ end
24
+
25
+ verify_method "id", "21737810"
26
+
27
+ verify_method "name", "Fabricio Rodrigo Lopes"
28
+
29
+ verify_method "birthday", Date.new(1983, 02, 22)
30
+
31
+ verify_method "phone", "21 22881060"
32
+
33
+ verify_method "mobile", "21 99999999"
34
+
35
+ verify_method "email", "fab1@spam.la"
36
+
37
+ verify_method "gender", "MASCULINO"
38
+
39
+ verify_method "city", "Rio de Janeiro"
40
+
41
+ verify_method "state", "RJ"
42
+
43
+ verify_method "status", "ATIVO"
44
+
45
+ verify_method "address", "Rua Uruguai, 59"
46
+
47
+ verify_method "neighborhood", "Andaraí"
48
+
49
+ verify_method "cpf", "09532034765"
50
+
51
+ verify_method "login", "fabricio_fab1"
52
+
53
+ verify_method "country", "Brasil"
54
+
55
+ verify_method "user_type", "NAO_ASSINANTE"
56
+ end
57
+
58
+ context "when the user id is given" do
59
+ subject { Cadun::User.new :user_id => "10001000", :ip => "127.0.0.1" }
60
+
61
+ it "should load the gateway" do
62
+ mock(Cadun::Gateway).new(hash_including(:ip => "127.0.0.1", :user_id => "10001000"))
63
+ subject
64
+ end
65
+
66
+ verify_method "id", "10001000"
67
+
68
+ verify_method "name", "Guilherme Chico"
23
69
  end
24
-
25
- verify_method "id", "21737810"
26
-
27
- verify_method "name", "Fabricio Rodrigo Lopes"
28
-
29
- verify_method "birthday", Date.new(1983, 02, 22)
30
-
31
- verify_method "phone", "21 22881060"
32
-
33
- verify_method "mobile", "21 99999999"
34
-
35
- verify_method "email", "fab1@spam.la"
36
-
37
- verify_method "gender", "MASCULINO"
38
-
39
- verify_method "city", "Rio de Janeiro"
40
-
41
- verify_method "state", "RJ"
42
-
43
- verify_method "status", "ATIVO"
44
-
45
- verify_method "address", "Rua Uruguai, 59"
46
-
47
- verify_method "neighborhood", "Andaraí"
48
-
49
- verify_method "cpf", "09532034765"
50
-
51
- verify_method "login", "fabricio_fab1"
52
-
53
- verify_method "country", "Brasil"
54
70
  end
data/spec/spec_helper.rb CHANGED
@@ -23,6 +23,9 @@ def stub_requests
23
23
 
24
24
  FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
25
25
  :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml"
26
+
27
+ FakeWeb.register_uri :get, "http://isp-authenticator.dev.globoi.com:8280/cadunii/ws/resources/pessoa/10001000",
28
+ :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml"
26
29
  end
27
30
 
28
31
  def load_config
@@ -0,0 +1,77 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <pessoa>
3
+ <id>10001000</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>Guilherme Chico</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 CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cadun
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruno
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-05-24 00:00:00 -03:00
15
+ date: 2011-05-26 00:00:00 -03:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -98,6 +98,7 @@ files:
98
98
  - spec/support/fixtures/autorizacao.xml
99
99
  - spec/support/fixtures/config.yml
100
100
  - spec/support/fixtures/pessoa.xml
101
+ - spec/support/fixtures/pessoa_2.xml
101
102
  has_rdoc: true
102
103
  homepage: https://github.com/azisaka/Cadun
103
104
  licenses: []