oa-cadun 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/oa-cadun.rb CHANGED
@@ -1,11 +1,14 @@
1
- $:.push File.expand_path("lib", __FILE__)
1
+ $:.push File.expand_path('lib', __FILE__)
2
2
 
3
3
  require 'uri'
4
4
  require 'cgi'
5
5
  require 'net/http'
6
- require 'oa-core'
7
6
  require 'nokogiri'
8
7
  require 'date'
9
- require 'oa-cadun/gateway'
10
- require 'oa-cadun/user'
11
- require 'omni_auth/strategies/cadun'
8
+ require 'oa-core'
9
+ require 'cadun'
10
+ require 'omni_auth/strategies/cadun'
11
+
12
+ module OACadun
13
+ VERSION = '0.2'
14
+ end
@@ -14,9 +14,9 @@ module OmniAuth
14
14
  end
15
15
 
16
16
  def auth_hash
17
- @params = CGI.parse(URI.parse(env["REQUEST_URI"]).query)
18
- @glb_id = params["GLBID"].first
19
- @url = params["url"].first
17
+ @params = CGI.parse(URI.parse(env['REQUEST_URI']).query)
18
+ @glb_id = params['GLBID'].first
19
+ @url = params['url'].first
20
20
 
21
21
  { :GLBID => glb_id,
22
22
  :url => url,
@@ -39,7 +39,7 @@ module OmniAuth
39
39
 
40
40
  protected
41
41
  def user
42
- @user ||= OACadun::User.new(glb_id, env["REMOTE_ADDR"], service_id)
42
+ @user ||= ::Cadun::User.new(glb_id, env['REMOTE_ADDR'], service_id)
43
43
  end
44
44
 
45
45
  def service_id
data/oa-cadun.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "version"
3
+ require "oa-cadun"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "oa-cadun"
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency 'oa-core'
21
+ s.add_dependency 'cadun'
21
22
  s.add_dependency 'nokogiri'
22
23
  s.add_development_dependency 'rack'
23
24
  s.add_development_dependency 'rspec'
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe OmniAuth::Strategies::Cadun do
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-cadun
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
4
+ prerelease:
5
+ version: "0.2"
11
6
  platform: ruby
12
7
  authors:
13
8
  - Bruno Azisaka Maciel
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-16 00:00:00 -03:00
13
+ date: 2011-05-17 00:00:00 -03:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,82 +21,75 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
- name: nokogiri
28
+ name: cadun
37
29
  prerelease: false
38
30
  requirement: &id002 !ruby/object:Gem::Requirement
39
31
  none: false
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
35
  version: "0"
47
36
  type: :runtime
48
37
  version_requirements: *id002
49
38
  - !ruby/object:Gem::Dependency
50
- name: rack
39
+ name: nokogiri
51
40
  prerelease: false
52
41
  requirement: &id003 !ruby/object:Gem::Requirement
53
42
  none: false
54
43
  requirements:
55
44
  - - ">="
56
45
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
46
  version: "0"
61
- type: :development
47
+ type: :runtime
62
48
  version_requirements: *id003
63
49
  - !ruby/object:Gem::Dependency
64
- name: rspec
50
+ name: rack
65
51
  prerelease: false
66
52
  requirement: &id004 !ruby/object:Gem::Requirement
67
53
  none: false
68
54
  requirements:
69
55
  - - ">="
70
56
  - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
57
  version: "0"
75
58
  type: :development
76
59
  version_requirements: *id004
77
60
  - !ruby/object:Gem::Dependency
78
- name: rr
61
+ name: rspec
79
62
  prerelease: false
80
63
  requirement: &id005 !ruby/object:Gem::Requirement
81
64
  none: false
82
65
  requirements:
83
66
  - - ">="
84
67
  - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
68
  version: "0"
89
69
  type: :development
90
70
  version_requirements: *id005
91
71
  - !ruby/object:Gem::Dependency
92
- name: fakeweb
72
+ name: rr
93
73
  prerelease: false
94
74
  requirement: &id006 !ruby/object:Gem::Requirement
95
75
  none: false
96
76
  requirements:
97
77
  - - ">="
98
78
  - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
79
  version: "0"
103
80
  type: :development
104
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: fakeweb
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
105
93
  description: The goal of this gem is to allow the developer to use CadUn (a login webservice made by Globo.com) in any web app using OmniAuth
106
94
  email:
107
95
  - bruno@azisaka.com.br
@@ -119,13 +107,8 @@ files:
119
107
  - README.md
120
108
  - Rakefile
121
109
  - lib/oa-cadun.rb
122
- - lib/oa-cadun/gateway.rb
123
- - lib/oa-cadun/user.rb
124
110
  - lib/omni_auth/strategies/cadun.rb
125
- - lib/version.rb
126
111
  - oa-cadun.gemspec
127
- - spec/oa-cadun/gateway_spec.rb
128
- - spec/oa-cadun/user_spec.rb
129
112
  - spec/omni_auth/strategies/cadun_spec.rb
130
113
  - spec/spec_helper.rb
131
114
  - spec/support/fixtures/autorizacao.xml
@@ -144,29 +127,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
127
  requirements:
145
128
  - - ">="
146
129
  - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 0
150
130
  version: "0"
151
131
  required_rubygems_version: !ruby/object:Gem::Requirement
152
132
  none: false
153
133
  requirements:
154
134
  - - ">="
155
135
  - !ruby/object:Gem::Version
156
- hash: 3
157
- segments:
158
- - 0
159
136
  version: "0"
160
137
  requirements: []
161
138
 
162
139
  rubyforge_project:
163
- rubygems_version: 1.3.7
140
+ rubygems_version: 1.6.2
164
141
  signing_key:
165
142
  specification_version: 3
166
143
  summary: OmniAuth strategy for CadUn
167
144
  test_files:
168
- - spec/oa-cadun/gateway_spec.rb
169
- - spec/oa-cadun/user_spec.rb
170
145
  - spec/omni_auth/strategies/cadun_spec.rb
171
146
  - spec/spec_helper.rb
172
147
  - spec/support/fixtures/autorizacao.xml
@@ -1,32 +0,0 @@
1
- module OACadun
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/oa-cadun/user.rb DELETED
@@ -1,40 +0,0 @@
1
- module OACadun
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/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module OACadun
2
- VERSION = "0.1.1"
3
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OACadun::Gateway do
4
- subject { OACadun::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
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OACadun::User do
4
-
5
- before { stub_requests }
6
-
7
- subject { OACadun::User.new("GLB_ID", "127.0.0.1", 2626) }
8
-
9
- describe "#id" do
10
- it { subject.id.should == "21737810" }
11
- end
12
-
13
- describe "#name" do
14
- it { subject.name.should == "Fabricio Rodrigo Lopes" }
15
- end
16
-
17
- describe "#birthday" do
18
- it { subject.birthday.should == Date.new(1983, 02, 22) }
19
- end
20
-
21
- describe "#phone" do
22
- it { subject.phone.should == "21 22881060" }
23
- end
24
-
25
- describe "#mobile" do
26
- it { subject.mobile.should == "21 99999999" }
27
- end
28
-
29
- describe "#email" do
30
- it { subject.email.should == "fab1@spam.la"}
31
- end
32
-
33
- describe "#gender" do
34
- it { subject.gender.should == "MASCULINO" }
35
- end
36
-
37
- describe "#city" do
38
- it { subject.city.should == "Rio de Janeiro"}
39
- end
40
-
41
- describe "#state" do
42
- it { subject.state.should == "RJ" }
43
- end
44
-
45
- describe "#status" do
46
- it { subject.status.should == "ATIVO" }
47
- end
48
-
49
- describe "#address" do
50
- it { subject.address.should == "Rua Uruguai, 59"}
51
- end
52
-
53
- describe "#suburb" do
54
- it { subject.suburb.should == "Andaraí" }
55
- end
56
-
57
- describe "#cpf" do
58
- it { subject.cpf.should == "09532034765" }
59
- end
60
-
61
- describe "#login" do
62
- it { subject.login.should == "fabricio_fab1" }
63
- end
64
-
65
- describe "#country" do
66
- it { subject.country.should == "Brasil" }
67
- end
68
- end