cadun 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/cadun.gemspec CHANGED
@@ -4,7 +4,7 @@ require "cadun/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "cadun"
7
- s.version = Cadun::VERSION
7
+ s.version = Cadun::VERSION::STRING
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Bruno Azisaka Maciel"]
10
10
  s.email = ["bruno@azisaka.com.br"]
@@ -0,0 +1,19 @@
1
+ module Cadun
2
+ class Config
3
+ include Singleton
4
+
5
+ attr_accessor :config
6
+
7
+ def initialize
8
+ @config = {}
9
+ end
10
+
11
+ def self.load_file(path)
12
+ instance.config = YAML::load_file(path)
13
+ end
14
+
15
+ def self.method_missing(method, *args)
16
+ instance.config['cadun'][method.to_s]
17
+ end
18
+ end
19
+ end
data/lib/cadun/gateway.rb CHANGED
@@ -17,16 +17,7 @@ module Cadun
17
17
  end
18
18
 
19
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
20
+ @connection ||= Net::HTTP.new(*[Config.auth_url, Config.auth_port])
30
21
  end
31
22
  end
32
23
  end
data/lib/cadun/version.rb CHANGED
@@ -1,3 +1,9 @@
1
1
  module Cadun
2
- VERSION = "0.0.2"
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY] * '.'
8
+ end
3
9
  end
data/lib/cadun.rb CHANGED
@@ -5,5 +5,8 @@ require 'cgi'
5
5
  require 'net/http'
6
6
  require 'nokogiri'
7
7
  require 'date'
8
+ require 'yaml'
9
+ require 'singleton'
8
10
  require 'cadun/gateway'
9
11
  require 'cadun/user'
12
+ require 'cadun/config'
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cadun::Config do
4
+ before do
5
+ Cadun::Config.load_file File.join(File.dirname(__FILE__), "..", "support", "fixtures", "config.yml")
6
+ end
7
+
8
+ describe "#login_url" do
9
+ subject { Cadun::Config.login_url }
10
+
11
+ specify { should == "https://login.dev.globoi.com/login" }
12
+ end
13
+
14
+ describe "#logout_url" do
15
+ subject { Cadun::Config.logout_url }
16
+
17
+ specify { should == "https://login.dev.globoi.com/Servlet/do/logout" }
18
+ end
19
+
20
+ describe "#auth_url" do
21
+ subject { Cadun::Config.auth_url }
22
+
23
+ specify { should == "isp-authenticator.dev.globoi.com" }
24
+ end
25
+
26
+ describe "#auth_port" do
27
+ subject { Cadun::Config.auth_port }
28
+
29
+ specify { should == 8280 }
30
+ end
31
+
32
+ context "when the file changes" do
33
+ before do
34
+ Cadun::Config.load_file File.join(File.dirname(__FILE__), "..", "support", "fixtures", "another_config.yml")
35
+ end
36
+
37
+ describe "#login_url" do
38
+ subject { Cadun::Config.login_url }
39
+
40
+ specify { should == "https://login.globo.com/login" }
41
+ end
42
+
43
+ describe "#logout_url" do
44
+ subject { Cadun::Config.logout_url }
45
+
46
+ specify { should == "https://login.globo.com/Servlet/do/logout" }
47
+ end
48
+
49
+ describe "#auth_url" do
50
+ subject { Cadun::Config.auth_url }
51
+
52
+ specify { should == "autenticacao.globo.com" }
53
+ end
54
+
55
+ describe "#auth_port" do
56
+ subject { Cadun::Config.auth_port }
57
+
58
+ specify { should == 8080 }
59
+ end
60
+ end
61
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Cadun::Gateway do
3
+ describe Cadun::Gateway do
4
+ before { load_config }
5
+
4
6
  subject { Cadun::Gateway.new("GLB_ID", "127.0.0.1", 2626) }
5
7
 
6
8
  describe "#content" do
@@ -18,26 +20,6 @@ describe Cadun::Gateway do
18
20
  end
19
21
  end
20
22
 
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
23
  describe "#authorization" do
42
24
  it "should parse the authorization request" do
43
25
  connection = mock
@@ -3,7 +3,10 @@ require 'spec_helper'
3
3
 
4
4
  describe Cadun::User do
5
5
 
6
- before { stub_requests }
6
+ before do
7
+ load_config
8
+ stub_requests
9
+ end
7
10
 
8
11
  subject { Cadun::User.new("GLB_ID", "127.0.0.1", 2626) }
9
12
 
data/spec/spec_helper.rb CHANGED
@@ -23,4 +23,8 @@ 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.join(File.dirname(__FILE__), "support", "fixtures", "pessoa.xml")
26
+ end
27
+
28
+ def load_config
29
+ Cadun::Config.load_file File.join(File.dirname(__FILE__), "support", "fixtures", "config.yml")
26
30
  end
@@ -0,0 +1,5 @@
1
+ cadun:
2
+ logout_url: https://login.globo.com/Servlet/do/logout
3
+ login_url: https://login.globo.com/login
4
+ auth_url: autenticacao.globo.com
5
+ auth_port: 8080
@@ -0,0 +1,5 @@
1
+ cadun:
2
+ logout_url: https://login.dev.globoi.com/Servlet/do/logout
3
+ login_url: https://login.dev.globoi.com/login
4
+ auth_url: isp-authenticator.dev.globoi.com
5
+ auth_port: 8280
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cadun
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruno Azisaka Maciel
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-18 00:00:00 -03:00
13
+ date: 2011-05-23 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -85,13 +85,17 @@ files:
85
85
  - Rakefile
86
86
  - cadun.gemspec
87
87
  - lib/cadun.rb
88
+ - lib/cadun/config.rb
88
89
  - lib/cadun/gateway.rb
89
90
  - lib/cadun/user.rb
90
91
  - lib/cadun/version.rb
92
+ - spec/cadun/config_spec.rb
91
93
  - spec/cadun/gateway_spec.rb
92
94
  - spec/cadun/user_spec.rb
93
95
  - spec/spec_helper.rb
96
+ - spec/support/fixtures/another_config.yml
94
97
  - spec/support/fixtures/autorizacao.xml
98
+ - spec/support/fixtures/config.yml
95
99
  - spec/support/fixtures/pessoa.xml
96
100
  has_rdoc: true
97
101
  homepage: ""
@@ -122,8 +126,11 @@ signing_key:
122
126
  specification_version: 3
123
127
  summary: ""
124
128
  test_files:
129
+ - spec/cadun/config_spec.rb
125
130
  - spec/cadun/gateway_spec.rb
126
131
  - spec/cadun/user_spec.rb
127
132
  - spec/spec_helper.rb
133
+ - spec/support/fixtures/another_config.yml
128
134
  - spec/support/fixtures/autorizacao.xml
135
+ - spec/support/fixtures/config.yml
129
136
  - spec/support/fixtures/pessoa.xml