cadun 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
1
  source "http://rubygems.org"
2
- gemspec
2
+ gemspec
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'benchmark'
3
+ require 'curb'
4
+ require 'restclient'
5
+
6
+ n = 100
7
+ url = "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/fab1@spam.la"
8
+
9
+ Benchmark.bm do |x|
10
+ x.report("restclient") { n.times { RestClient.get(url) } }
11
+ x.report("curb") { n.times { Curl::Easy.perform(url) } }
12
+ end
data/cadun.gemspec CHANGED
@@ -15,13 +15,12 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
16
16
  s.require_paths = %w(lib)
17
17
 
18
+ s.add_dependency 'i18n'
18
19
  s.add_dependency 'activesupport', '>= 3.0.0'
19
20
  s.add_dependency 'builder', '>= 2.1.2'
20
- s.add_dependency 'rest-client'
21
- s.add_dependency 'json'
22
- s.add_dependency 'i18n'
21
+ s.add_dependency 'curb'
23
22
  s.add_development_dependency 'rake'
24
23
  s.add_development_dependency 'rspec'
25
24
  s.add_development_dependency 'rr'
26
- s.add_development_dependency 'fakeweb'
25
+ s.add_development_dependency 'webmock'
27
26
  end
data/lib/cadun/gateway.rb CHANGED
@@ -3,7 +3,11 @@ module Cadun
3
3
  attr_reader :opts
4
4
 
5
5
  def self.provision(user_id, service_id)
6
- RestClient.put("#{Config.restclient_url}/service/provisionamento", "{\"usuarioId\": \"#{user_id}\", \"servicoId\": \"#{service_id}\"}", :content_type => "text/javascript").code == 200
6
+ request = Curl::Easy.perform("#{Config.restclient_url}/service/provisionamento") do |curl|
7
+ curl.headers['Content-Type'] = 'application/json'
8
+ curl.http_put("{\"usuarioId\":\"#{user_id}\",\"servicoId\":\"#{service_id}\"}")
9
+ end
10
+ request.response_code == 200
7
11
  end
8
12
 
9
13
  def initialize(opts = {})
@@ -22,7 +26,8 @@ module Cadun
22
26
  authorization["usuarioID"]
23
27
  end
24
28
 
25
- RestClient.get("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}", :content_type => "text/xml")
29
+ request = Curl::Easy.perform("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}")
30
+ request.body_str
26
31
  end
27
32
 
28
33
  def authorization
@@ -33,7 +38,11 @@ module Cadun
33
38
  %w(glb_id ip service_id).each { |i| raise ArgumentError.new("#{i} is missing") unless opts[i.to_sym] }
34
39
  authorization_data = { "glbId" => opts[:glb_id], "ip" => opts[:ip], "servicoID" => opts[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0)
35
40
 
36
- RestClient.put("#{Config.auth_url}/ws/rest/autorizacao", authorization_data, :content_type => "text/xml")
41
+ request = Curl::Easy.perform("#{Config.auth_url}/ws/rest/autorizacao") do |curl|
42
+ curl.headers['Content-Type'] = 'application/xml'
43
+ curl.http_put(authorization_data)
44
+ end
45
+ request.body_str
37
46
  end
38
47
  end
39
48
  end
data/lib/cadun/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Cadun
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 5
5
- PATCH = 9
4
+ MINOR = 6
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH] * '.'
8
8
  end
data/lib/cadun.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'date'
2
2
  require 'yaml'
3
- require 'rest_client'
4
- require 'json'
3
+ require 'curb'
5
4
  require 'active_support/core_ext/hash'
6
5
  require 'active_support/core_ext/object'
7
6
  require "#{File.dirname(__FILE__)}/cadun/gateway"
@@ -5,31 +5,31 @@ describe Cadun::Gateway do
5
5
 
6
6
  describe "#provision" do
7
7
  context "when the service is provisioned to the user" do
8
- before { FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 200) }
8
+ before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [200]) }
9
9
 
10
10
  subject { Cadun::Gateway.provision(123456, 2515) }
11
11
  specify { should be_true }
12
12
  end
13
13
 
14
14
  context "when the service is provisioned to the user" do
15
- before { FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 304) }
15
+ before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [304]) }
16
16
 
17
17
  subject { Cadun::Gateway.provision(123456, 2515) }
18
- it { proc { subject }.should raise_error(RestClient::NotModified) }
18
+ it { subject.should be_false }
19
19
  end
20
20
 
21
21
  context "when the service is not found" do
22
- before { FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 404) }
22
+ before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [404]) }
23
23
 
24
24
  subject { Cadun::Gateway.provision(123456, 2515) }
25
- it { proc { subject }.should raise_error(RestClient::ResourceNotFound) }
25
+ it { subject.should be_false }
26
26
  end
27
27
 
28
28
  context "when the service is not found" do
29
- before { FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento", :status => 503) }
29
+ before { stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:status => [503]) }
30
30
 
31
31
  subject { Cadun::Gateway.provision(123456, 2515) }
32
- it { proc { subject }.should raise_error(RestClient::ServiceUnavailable) }
32
+ it { subject.should be_false }
33
33
  end
34
34
 
35
35
  end
@@ -39,7 +39,7 @@ describe Cadun::Gateway do
39
39
 
40
40
  context "when status not AUTORIZADO" do
41
41
  before do
42
- FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>NAO_AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
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
43
  end
44
44
 
45
45
  it { proc { gateway.content }.should raise_error(Exception) }
@@ -47,8 +47,8 @@ describe Cadun::Gateway do
47
47
 
48
48
  context "when status AUTORIZADO" do
49
49
  before do
50
- FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :body => "<?xml version='1.0' encoding='utf-8'?><usuarioAutorizado><status>AUTORIZADO</status><usuarioID>1</usuarioID></usuarioAutorizado>")
51
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/1", :body => "<?xml version='1.0' encoding='utf-8'?><pessoa><nome>Barack Obama</nome></pessoa>")
50
+ 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
+ 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
52
  end
53
53
 
54
54
  it { proc { gateway.content }.should_not raise_error(Exception) }
@@ -64,7 +64,7 @@ describe Cadun::Gateway do
64
64
  let(:gateway) { Cadun::Gateway.new(:glb_id => "GLB_ID", :ip => "127.0.0.1", :service_id => 2626) }
65
65
 
66
66
  before do
67
- FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao", :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>")
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
68
  end
69
69
 
70
70
  it "should parse the authorization request" do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "#{File.dirname(__FILE__)}/../lib/cadun"
2
- require 'fakeweb'
2
+ require 'webmock/rspec'
3
3
 
4
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
5
5
 
@@ -9,25 +9,18 @@ RSpec.configure do |config|
9
9
  config.run_all_when_everything_filtered = true
10
10
 
11
11
  config.before(:suite) do
12
- FakeWeb.allow_net_connect = false
12
+ WebMock.disable_net_connect!(:allow_localhost => true)
13
13
  end
14
14
  end
15
15
 
16
16
  def stub_requests
17
- FakeWeb.register_uri(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao",
18
- :body => "#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml")
19
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/21737810",
20
- :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml")
21
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/10001000",
22
- :body => "#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml")
23
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com",
24
- :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml")
25
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com",
26
- :body => "#{File.dirname(__FILE__)}/support/fixtures/email.xml")
27
- FakeWeb.register_uri(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/fulano_adm_campanha@globomail.com",
28
- :body => "#{File.dirname(__FILE__)}/support/fixtures/email2.xml")
29
- FakeWeb.register_uri(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento",
30
- :body => "#{File.dirname(__FILE__)}/support/fixtures/provisionamento.json", :status => 200)
17
+ stub_request(:put, "http://isp-authenticator.qa01.globoi.com:8280/ws/rest/autorizacao").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/autorizacao.xml"))
18
+ stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/21737810").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/pessoa.xml"))
19
+ stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/10001000").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/pessoa_2.xml"))
20
+ stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@globo.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email.xml"))
21
+ stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/silvano@corp.globo.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email.xml"))
22
+ stub_request(:get, "http://isp-authenticator.qa01.globoi.com:8280/cadunii/ws/resources/pessoa/email/fulano_adm_campanha@globomail.com").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/email2.xml"))
23
+ stub_request(:put, "http://cadun-rest.qa01.globoi.com/service/provisionamento").to_return(:body => File.new("#{File.dirname(__FILE__)}/support/fixtures/provisionamento.json"))
31
24
  end
32
25
 
33
26
  def load_config
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.5.9
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,55 +11,44 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-05 00:00:00.000000000Z
14
+ date: 2011-09-05 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: activesupport
18
- requirement: &2152502120 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ! '>='
22
- - !ruby/object:Gem::Version
23
- version: 3.0.0
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: *2152502120
27
- - !ruby/object:Gem::Dependency
28
- name: builder
29
- requirement: &2152501620 !ruby/object:Gem::Requirement
17
+ name: i18n
18
+ requirement: &2152951100 !ruby/object:Gem::Requirement
30
19
  none: false
31
20
  requirements:
32
21
  - - ! '>='
33
22
  - !ruby/object:Gem::Version
34
- version: 2.1.2
23
+ version: '0'
35
24
  type: :runtime
36
25
  prerelease: false
37
- version_requirements: *2152501620
26
+ version_requirements: *2152951100
38
27
  - !ruby/object:Gem::Dependency
39
- name: rest-client
40
- requirement: &2152501240 !ruby/object:Gem::Requirement
28
+ name: activesupport
29
+ requirement: &2152950600 !ruby/object:Gem::Requirement
41
30
  none: false
42
31
  requirements:
43
32
  - - ! '>='
44
33
  - !ruby/object:Gem::Version
45
- version: '0'
34
+ version: 3.0.0
46
35
  type: :runtime
47
36
  prerelease: false
48
- version_requirements: *2152501240
37
+ version_requirements: *2152950600
49
38
  - !ruby/object:Gem::Dependency
50
- name: json
51
- requirement: &2152500780 !ruby/object:Gem::Requirement
39
+ name: builder
40
+ requirement: &2152950100 !ruby/object:Gem::Requirement
52
41
  none: false
53
42
  requirements:
54
43
  - - ! '>='
55
44
  - !ruby/object:Gem::Version
56
- version: '0'
45
+ version: 2.1.2
57
46
  type: :runtime
58
47
  prerelease: false
59
- version_requirements: *2152500780
48
+ version_requirements: *2152950100
60
49
  - !ruby/object:Gem::Dependency
61
- name: i18n
62
- requirement: &2152500360 !ruby/object:Gem::Requirement
50
+ name: curb
51
+ requirement: &2152980420 !ruby/object:Gem::Requirement
63
52
  none: false
64
53
  requirements:
65
54
  - - ! '>='
@@ -67,10 +56,10 @@ dependencies:
67
56
  version: '0'
68
57
  type: :runtime
69
58
  prerelease: false
70
- version_requirements: *2152500360
59
+ version_requirements: *2152980420
71
60
  - !ruby/object:Gem::Dependency
72
61
  name: rake
73
- requirement: &2152499940 !ruby/object:Gem::Requirement
62
+ requirement: &2152979960 !ruby/object:Gem::Requirement
74
63
  none: false
75
64
  requirements:
76
65
  - - ! '>='
@@ -78,10 +67,10 @@ dependencies:
78
67
  version: '0'
79
68
  type: :development
80
69
  prerelease: false
81
- version_requirements: *2152499940
70
+ version_requirements: *2152979960
82
71
  - !ruby/object:Gem::Dependency
83
72
  name: rspec
84
- requirement: &2152499520 !ruby/object:Gem::Requirement
73
+ requirement: &2152979540 !ruby/object:Gem::Requirement
85
74
  none: false
86
75
  requirements:
87
76
  - - ! '>='
@@ -89,10 +78,10 @@ dependencies:
89
78
  version: '0'
90
79
  type: :development
91
80
  prerelease: false
92
- version_requirements: *2152499520
81
+ version_requirements: *2152979540
93
82
  - !ruby/object:Gem::Dependency
94
83
  name: rr
95
- requirement: &2152499100 !ruby/object:Gem::Requirement
84
+ requirement: &2152979120 !ruby/object:Gem::Requirement
96
85
  none: false
97
86
  requirements:
98
87
  - - ! '>='
@@ -100,10 +89,10 @@ dependencies:
100
89
  version: '0'
101
90
  type: :development
102
91
  prerelease: false
103
- version_requirements: *2152499100
92
+ version_requirements: *2152979120
104
93
  - !ruby/object:Gem::Dependency
105
- name: fakeweb
106
- requirement: &2152498680 !ruby/object:Gem::Requirement
94
+ name: webmock
95
+ requirement: &2152978700 !ruby/object:Gem::Requirement
107
96
  none: false
108
97
  requirements:
109
98
  - - ! '>='
@@ -111,7 +100,7 @@ dependencies:
111
100
  version: '0'
112
101
  type: :development
113
102
  prerelease: false
114
- version_requirements: *2152498680
103
+ version_requirements: *2152978700
115
104
  description: A wrapper for the Globo.com's authentication/authorization API
116
105
  email:
117
106
  - bruno@azisaka.com.br
@@ -123,6 +112,7 @@ files:
123
112
  - .rspec
124
113
  - Gemfile
125
114
  - Rakefile
115
+ - bench/curl_x_restclient.rb
126
116
  - cadun.gemspec
127
117
  - lib/cadun.rb
128
118
  - lib/cadun/config.rb