cadun 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,15 +19,20 @@ module Cadun
19
19
  end
20
20
 
21
21
  def content_resource
22
- subject = if opts[:email]; "email/#{opts[:email]}"
23
- elsif opts[:cadun_id]; opts[:cadun_id]
24
- else
25
- raise Exception.new(authorization["status"]) unless authorization["status"] == "AUTORIZADO"
26
- authorization["usuarioID"]
27
- end
22
+ Curl::Easy.perform("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}").body_str
23
+ end
28
24
 
29
- request = Curl::Easy.perform("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}")
30
- request.body_str
25
+ def subject
26
+ if opts[:email]; "email/#{opts[:email]}"
27
+ elsif opts[:cadun_id]; opts[:cadun_id]
28
+ else
29
+ raise Exception.new(authorization["status"]) unless authorized?
30
+ authorization["usuarioID"]
31
+ end
32
+ end
33
+
34
+ def authorized?
35
+ authorization["status"] == "AUTORIZADO"
31
36
  end
32
37
 
33
38
  def authorization
@@ -36,6 +41,7 @@ module Cadun
36
41
 
37
42
  def authorization_resource
38
43
  %w(glb_id ip service_id).each { |i| raise ArgumentError.new("#{i} is missing") unless opts[i.to_sym] }
44
+
39
45
  authorization_data = { "glbId" => opts[:glb_id], "ip" => opts[:ip], "servicoID" => opts[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0)
40
46
 
41
47
  request = Curl::Easy.http_put("#{Config.auth_url}/ws/rest/autorizacao", authorization_data) do |curl|
@@ -12,7 +12,7 @@ module Cadun
12
12
  alias :id :cadun_id
13
13
 
14
14
  def self.find_by_email(email)
15
- email = "#{email}@globo.com" unless email =~ /^.*@.*$/
15
+ email = "#{email}@globomail.com" unless email =~ /^.*@.*$/
16
16
  new(:email => email)
17
17
  end
18
18
 
@@ -2,7 +2,7 @@ module Cadun
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 6
5
- PATCH = 1
5
+ PATCH = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH] * '.'
8
8
  end
@@ -1,29 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cadun::Config do
4
- def self.verify_method(method, value)
5
- describe "##{method}" do
6
- subject { Cadun::Config.send(method) }
7
- specify { should == value }
8
- end
9
- end
10
-
11
4
  before { load_config }
5
+ subject { Cadun::Config }
12
6
 
13
- verify_method "login_url", "https://login.qa01.globoi.com/login"
14
-
15
- verify_method "logout_url", "https://login.qa01.globoi.com/Servlet/do/logout"
16
-
17
- verify_method "auth_url", "http://isp-authenticator.qa01.globoi.com:8280"
7
+ its(:login_url) { should == "https://login.qa01.globoi.com/login" }
8
+ its(:logout_url) { should == "https://login.qa01.globoi.com/Servlet/do/logout" }
9
+ its(:auth_url) { should == "http://isp-authenticator.qa01.globoi.com:8280" }
18
10
 
19
11
  context "when the file changes" do
20
-
21
12
  before { load_another_config }
22
-
23
- verify_method "login_url", "https://login.globo.com/login"
24
-
25
- verify_method "logout_url", "https://login.globo.com/Servlet/do/logout"
26
-
27
- verify_method "auth_url", "http://autenticacao.globo.com:8080"
13
+
14
+ its(:login_url) { should == "https://login.globo.com/login" }
15
+ its(:logout_url) { should == "https://login.globo.com/Servlet/do/logout" }
16
+ its(:auth_url) { should == "http://autenticacao.globo.com:8080" }
28
17
  end
29
18
  end
@@ -3,46 +3,32 @@ require 'spec_helper'
3
3
  describe Cadun::Gateway do
4
4
  before { load_config }
5
5
 
6
- describe "#provision" do
6
+ describe "#provision" do
7
+ subject { Cadun::Gateway.provision(123456, 2515) }
8
+
7
9
  context "when the service is provisioned to the user" do
8
10
  before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [200]) }
9
-
10
- subject { Cadun::Gateway.provision(123456, 2515) }
11
- specify { should be_true }
11
+ it { should be_true }
12
12
  end
13
13
 
14
- context "when the service is provisioned to the user" do
14
+ context "when the service has been provisioned to the user" do
15
15
  before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [304]) }
16
-
17
- subject { Cadun::Gateway.provision(123456, 2515) }
18
- it { subject.should be_false }
16
+ it { should be_false }
19
17
  end
20
18
 
21
19
  context "when the service is not found" do
22
20
  before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [404]) }
23
-
24
- subject { Cadun::Gateway.provision(123456, 2515) }
25
- it { subject.should be_false }
21
+ it { should be_false }
26
22
  end
27
-
28
- context "when the service is not found" do
29
- before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [503]) }
30
-
31
- subject { Cadun::Gateway.provision(123456, 2515) }
32
- it { subject.should be_false }
33
- end
34
-
35
23
  end
36
24
 
37
25
  describe "#content" do
38
26
  let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
27
+ subject { gateway.content }
39
28
 
40
29
  context "when status not AUTORIZADO" do
41
- before do
42
- stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
43
- end
44
-
45
- it { proc { gateway.content }.should raise_error(Exception) }
30
+ before { stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>") }
31
+ it { expect { subject }.to raise_error(Exception) }
46
32
  end
47
33
 
48
34
  context "when status AUTORIZADO" do
@@ -50,42 +36,33 @@ describe Cadun::Gateway do
50
36
  stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
51
37
  stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/1").to_return(:body => "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>")
52
38
  end
53
-
54
- it { proc { gateway.content }.should_not raise_error(Exception) }
55
-
56
- it "should parse the resource" do
57
- gateway.content['nome'].should == 'Barack Obama'
58
- end
39
+
40
+ it { should include('nome' => 'Barack Obama') }
59
41
  end
60
42
  end
61
43
 
62
44
  describe "#authorization" do
45
+ subject { gateway.authorization }
46
+
63
47
  context "when all information is given" do
64
48
  let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
65
-
66
- before do
67
- stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID type=\"integer\">2626</servicoID></usuarioAutorizado>", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
68
- end
69
-
70
- it "should parse the authorization request" do
71
- gateway.authorization['usuarioID'].should == '1'
72
- end
73
-
49
+ before { stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><usuarioAutorizado><glbId>GLB_ID</glbId><ip>127.0.0.1</ip><servicoID type=\"integer\">2626</servicoID></usuarioAutorizado>", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>") }
50
+ it { subject.should include('usuarioID' => '1') }
74
51
  end
75
52
 
76
53
  context "when glb_id is not given" do
77
54
  let(:gateway) { Cadun::Gateway.new }
78
- it { proc { gateway.authorization }.should raise_error(ArgumentError, "glb_id is missing") }
55
+ it { expect { subject }.to raise_error(ArgumentError, "glb_id is missing") }
79
56
  end
80
57
 
81
58
  context "when ip is not given" do
82
59
  let(:gateway) { Cadun::Gateway.new(:glb_id => "1") }
83
- it { proc { gateway.authorization }.should raise_error(ArgumentError, "ip is missing") }
60
+ it { expect { subject }.to raise_error(ArgumentError, "ip is missing") }
84
61
  end
85
62
 
86
63
  context "when service_id is not given" do
87
64
  let(:gateway) { Cadun::Gateway.new(:glb_id => "1", :ip => "1") }
88
- it { proc { gateway.authorization }.should raise_error(ArgumentError, "service_id is missing") }
65
+ it { expect { subject }.to raise_error(ArgumentError, "service_id is missing") }
89
66
  end
90
67
  end
91
68
  end
@@ -2,13 +2,6 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Cadun::User do
5
-
6
- def self.verify_method(method, value)
7
- describe "##{method}" do
8
- specify { subject.send(method).should == value }
9
- end
10
- end
11
-
12
5
  before do
13
6
  load_config
14
7
  stub_requests
@@ -30,74 +23,75 @@ describe Cadun::User do
30
23
  subject
31
24
  end
32
25
 
33
- verify_method "id", "21737810"
34
- verify_method "name", "Fabricio Rodrigo Lopes"
35
- verify_method "birthday", Date.new(1983, 02, 22)
36
- verify_method "phone", "21 22881060"
37
- verify_method "mobile", "21 99999999"
38
- verify_method "email", "fab1@spam.la"
39
- verify_method "gender", "MASCULINO"
40
- verify_method "city", "Rio de Janeiro"
41
- verify_method "state", "RJ"
42
- verify_method "status", "ATIVO"
43
- verify_method "address", "Rua Uruguai, 59"
44
- verify_method "neighborhood", "Andaraí"
45
- verify_method "cpf", "09532034765"
46
- verify_method "login", "fabricio_fab1"
47
- verify_method "country", "Brasil"
48
- verify_method "user_type", "NAO_ASSINANTE"
49
- verify_method "cadun_id", "21737810"
50
- verify_method "complement", "807"
26
+ its(:id) { should == "21737810" }
27
+ its(:name) { should == "Fabricio Rodrigo Lopes" }
28
+ its(:birthday) { should == Date.new(1983, 02, 22) }
29
+ its(:phone) { should == "21 22881060" }
30
+ its(:mobile) { should == "21 99999999" }
31
+ its(:email) { should == "fab1@spam.la" }
32
+ its(:gender) { should == "MASCULINO" }
33
+ its(:city) { should == "Rio de Janeiro" }
34
+ its(:state) { should == "RJ" }
35
+ its(:status) { should == "ATIVO" }
36
+ its(:address) { should == "Rua Uruguai, 59" }
37
+ its(:neighborhood) { should == "Andaraí" }
38
+ its(:cpf) { should == "09532034765" }
39
+ its(:login) { should == "fabricio_fab1" }
40
+ its(:country) { should == "Brasil" }
41
+ its(:user_type) { should == "NAO_ASSINANTE" }
42
+ its(:cadun_id) { should == "21737810" }
43
+ its(:complement) { should == "807" }
51
44
  end
52
45
 
53
46
  describe "#to_hash" do
54
47
  context "when the user has all data" do
55
48
  subject { Cadun::User.new(:cadun_id => "10001000").to_hash }
56
-
57
- specify { should include(:cadun_id => "10001000") }
58
- specify { should include(:name => "Guilherme Chico") }
59
- specify { should include(:email => "fab1@spam.la") }
60
- specify { should include(:user_type => "NAO_ASSINANTE") }
61
- specify { should include(:gender => "MASCULINO") }
62
- specify { should include(:neighborhood => "Andaraí") }
63
- specify { should include(:city => "Rio de Janeiro") }
64
- specify { should include(:state => "RJ") }
65
- specify { should include(:country => "Brasil") }
66
- specify { should include(:address => "Rua Uruguai, 59") }
67
- specify { should include(:birthday => Date.new(1983, 02, 22)) }
68
- specify { should include(:phone => "21 22881060") }
69
- specify { should include(:mobile => "21 99999999") }
70
- specify { should include(:login => "fabricio_fab1") }
71
- specify { should include(:cpf => "09532034765") }
72
- specify { should include(:zipcode => "20510060") }
73
- specify { should include(:status => "ATIVO") }
74
- specify { should include(:complement => "807") }
49
+
50
+ it { should include :cadun_id => "10001000" }
51
+ it { should include :name => "Guilherme Chico" }
52
+ it { should include :email => "fab1@spam.la" }
53
+ it { should include :user_type => "NAO_ASSINANTE" }
54
+ it { should include :gender => "MASCULINO" }
55
+ it { should include :neighborhood => "Andaraí" }
56
+ it { should include :city => "Rio de Janeiro" }
57
+ it { should include :state => "RJ" }
58
+ it { should include :country => "Brasil" }
59
+ it { should include :address => "Rua Uruguai, 59" }
60
+ it { should include :birthday => Date.new(1983, 02, 22) }
61
+ it { should include :phone => "21 22881060" }
62
+ it { should include :mobile => "21 99999999" }
63
+ it { should include :login => "fabricio_fab1" }
64
+ it { should include :cpf => "09532034765" }
65
+ it { should include :zipcode => "20510060" }
66
+ it { should include :status => "ATIVO" }
67
+ it { should include :complement => "807" }
75
68
  end
76
69
 
77
70
  context "when the user has minimal data" do
78
71
  subject { Cadun::User.find_by_email("fulano_adm_campanha@globomail.com") }
79
- specify { subject.id.should == "23370159" }
80
- specify { subject.city.should == nil }
81
- specify { subject.state.should == nil }
82
- specify { subject.country.should == nil }
72
+
73
+ its(:id) { should == "23370159" }
74
+ its(:city) { should be_nil }
75
+ its(:state) { should be_nil }
76
+ its(:country) { should be_nil }
83
77
  end
84
78
  end
85
79
 
86
80
  describe ".find_by_email" do
87
81
  context "given an email without domain" do
88
82
  subject { Cadun::User.find_by_email("silvano") }
89
- verify_method "id", "24510533"
83
+ its(:id) { should == "24510533" }
90
84
  end
91
85
 
92
86
  context "given an email with domain" do
93
87
  subject { Cadun::User.find_by_email("silvano@corp.globo.com") }
94
- verify_method "id", "24510533"
88
+ its(:id) { should == "24510533" }
95
89
  end
96
90
  end
97
91
 
98
92
  describe ".find_by_id" do
99
93
  subject { Cadun::User.find_by_id("10001000") }
100
- verify_method "id", "10001000"
94
+ its(:id) { should == "10001000" }
101
95
  end
102
96
 
103
97
  describe "#provision_to_service" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cadun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-09-05 00:00:00.000000000Z
14
+ date: 2011-11-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n
18
- requirement: &2161593740 !ruby/object:Gem::Requirement
18
+ requirement: &70300104786900 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2161593740
26
+ version_requirements: *70300104786900
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
- requirement: &2161593240 !ruby/object:Gem::Requirement
29
+ requirement: &70300104779400 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2161593240
37
+ version_requirements: *70300104779400
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: builder
40
- requirement: &2161592740 !ruby/object:Gem::Requirement
40
+ requirement: &70300104778780 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 2.1.2
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *2161592740
48
+ version_requirements: *70300104778780
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: curb
51
- requirement: &2161592360 !ruby/object:Gem::Requirement
51
+ requirement: &70300104636920 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *2161592360
59
+ version_requirements: *70300104636920
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rake
62
- requirement: &2161591900 !ruby/object:Gem::Requirement
62
+ requirement: &70300104634980 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2161591900
70
+ version_requirements: *70300104634980
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
- requirement: &2161611940 !ruby/object:Gem::Requirement
73
+ requirement: &70300104633980 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2161611940
81
+ version_requirements: *70300104633980
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rr
84
- requirement: &2161611520 !ruby/object:Gem::Requirement
84
+ requirement: &70300104633280 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *2161611520
92
+ version_requirements: *70300104633280
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: webmock
95
- requirement: &2161611100 !ruby/object:Gem::Requirement
95
+ requirement: &70300104632720 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,7 +100,7 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *2161611100
103
+ version_requirements: *70300104632720
104
104
  description: A wrapper for the Globo.com's authentication/authorization API
105
105
  email:
106
106
  - bruno@azisaka.com.br
@@ -112,15 +112,13 @@ files:
112
112
  - .rspec
113
113
  - Gemfile
114
114
  - Rakefile
115
- - bench/curl_x_restclient.rb
115
+ - benchmark/curl_x_restclient.rb
116
116
  - cadun.gemspec
117
117
  - lib/cadun.rb
118
118
  - lib/cadun/config.rb
119
119
  - lib/cadun/gateway.rb
120
120
  - lib/cadun/user.rb
121
121
  - lib/cadun/version.rb
122
- - script/console
123
- - script/loader.rb
124
122
  - spec/cadun/config_spec.rb
125
123
  - spec/cadun/gateway_spec.rb
126
124
  - spec/cadun/user_spec.rb
@@ -153,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
151
  version: '0'
154
152
  requirements: []
155
153
  rubyforge_project:
156
- rubygems_version: 1.8.6
154
+ rubygems_version: 1.8.10
157
155
  signing_key:
158
156
  specification_version: 3
159
157
  summary: A wrapper for the Globo.com's authentication/authorization API
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- irb -r ./script/loader.rb
@@ -1,3 +0,0 @@
1
- require File.expand_path("../../lib/cadun.rb", __FILE__)
2
-
3
- Cadun::Config.load_file("#{File.dirname(__FILE__)}/../spec/support/fixtures/config.yml")