bsm-openx 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/VERSION +1 -1
- data/bsm-openx.gemspec +7 -3
- data/lib/openx/services/session.rb +2 -2
- data/lib/openx/services/targeting_rule.rb +4 -4
- data/lib/openx/xmlrpc_client.rb +20 -17
- data/test/test_xmlrpc_client.rb +37 -0
- data/test/test_xmlrpc_session_client.rb +36 -0
- metadata +8 -4
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.3
|
data/bsm-openx.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bsm-openx}
|
8
|
-
s.version = "1.9.
|
8
|
+
s.version = "1.9.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Patterson", "Andy Smith", "TouchLocal P/L", "Dimitrij Denissenko"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-13}
|
13
13
|
s.description = %q{A Ruby interface to the OpenX XML-RPC API}
|
14
14
|
s.email = %q{dimitrij@blacksquaremedia.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -55,6 +55,8 @@ Gem::Specification.new do |s|
|
|
55
55
|
"test/test_session.rb",
|
56
56
|
"test/test_targeting_rule.rb",
|
57
57
|
"test/test_targeting_rules.rb",
|
58
|
+
"test/test_xmlrpc_client.rb",
|
59
|
+
"test/test_xmlrpc_session_client.rb",
|
58
60
|
"test/test_zone.rb"
|
59
61
|
]
|
60
62
|
s.homepage = %q{http://github.com/bsm/openx}
|
@@ -63,7 +65,8 @@ Gem::Specification.new do |s|
|
|
63
65
|
s.rubygems_version = %q{1.3.7}
|
64
66
|
s.summary = %q{A Ruby interface to the OpenX XML-RPC API}
|
65
67
|
s.test_files = [
|
66
|
-
"test/
|
68
|
+
"test/test_xmlrpc_session_client.rb",
|
69
|
+
"test/test_openx.rb",
|
67
70
|
"test/test_channel.rb",
|
68
71
|
"test/test_targeting_rule.rb",
|
69
72
|
"test/test_zone.rb",
|
@@ -76,6 +79,7 @@ Gem::Specification.new do |s|
|
|
76
79
|
"test/test_services.rb",
|
77
80
|
"test/test_banner.rb",
|
78
81
|
"test/test_targeting_rules.rb",
|
82
|
+
"test/test_xmlrpc_client.rb",
|
79
83
|
"test/test_publisher.rb"
|
80
84
|
]
|
81
85
|
|
@@ -24,8 +24,7 @@ module OpenX
|
|
24
24
|
def create(user, password)
|
25
25
|
self.user = user
|
26
26
|
self.password = password
|
27
|
-
|
28
|
-
self
|
27
|
+
recreate!
|
29
28
|
end
|
30
29
|
|
31
30
|
def recreate!
|
@@ -39,6 +38,7 @@ module OpenX
|
|
39
38
|
self.id = nil
|
40
39
|
self
|
41
40
|
end
|
41
|
+
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -74,13 +74,13 @@ module OpenX
|
|
74
74
|
update 'comparison' => '!x', 'data' => convert(value)
|
75
75
|
end
|
76
76
|
|
77
|
-
def include?(*
|
78
|
-
update 'comparison' => '=~', 'data' => convert(
|
77
|
+
def include?(*values)
|
78
|
+
update 'comparison' => '=~', 'data' => convert(values)
|
79
79
|
end
|
80
80
|
alias_method :contains?, :include?
|
81
81
|
|
82
|
-
def exclude?(*
|
83
|
-
update 'comparison' => '!~', 'data' => convert(
|
82
|
+
def exclude?(*values)
|
83
|
+
update 'comparison' => '!~', 'data' => convert(values)
|
84
84
|
end
|
85
85
|
alias_method :does_not_contain?, :exclude?
|
86
86
|
|
data/lib/openx/xmlrpc_client.rb
CHANGED
@@ -2,29 +2,31 @@ require 'xmlrpc/client'
|
|
2
2
|
|
3
3
|
module OpenX
|
4
4
|
|
5
|
-
unless defined? HTTPBroken
|
6
|
-
# A module that captures all the possible Net::HTTP exceptions
|
7
|
-
# from http://pastie.org/pastes/145154
|
8
|
-
module HTTPBroken; end
|
9
|
-
[
|
10
|
-
Timeout::Error, Errno::EINVAL, Errno::EPIPE,
|
11
|
-
Errno::ECONNRESET, EOFError, Net::HTTPBadResponse,
|
12
|
-
Net::HTTPHeaderSyntaxError, Net::ProtocolError
|
13
|
-
].each {|m| m.send(:include, HTTPBroken) }
|
14
|
-
end
|
15
|
-
|
16
5
|
class XmlrpcClient
|
6
|
+
EXCEPTION_CLASSES = [
|
7
|
+
::Timeout::Error,
|
8
|
+
::Errno::EINVAL,
|
9
|
+
::Errno::EPIPE,
|
10
|
+
::Errno::ECONNRESET,
|
11
|
+
::EOFError,
|
12
|
+
::Net::HTTPBadResponse,
|
13
|
+
::Net::HTTPHeaderSyntaxError,
|
14
|
+
::Net::ProtocolError
|
15
|
+
].freeze
|
16
|
+
|
17
17
|
attr_reader :client, :url
|
18
18
|
|
19
19
|
def initialize(url)
|
20
|
-
@url
|
20
|
+
@url = url
|
21
|
+
@retries = 0
|
21
22
|
init_client!
|
22
23
|
end
|
23
24
|
|
24
25
|
def call(method, *args)
|
25
|
-
@client.call(method, *convert(args))
|
26
|
-
rescue
|
27
|
-
|
26
|
+
@client.call(method, *(convert(args)))
|
27
|
+
rescue *EXCEPTION_CLASSES => e
|
28
|
+
cycle = (cycle || 0) + 1
|
29
|
+
raise(e) if cycle > 10 || OpenX.configuration['retry'] == false
|
28
30
|
init_client!
|
29
31
|
retry
|
30
32
|
end
|
@@ -56,8 +58,9 @@ module OpenX
|
|
56
58
|
|
57
59
|
def call(method, *args)
|
58
60
|
super
|
59
|
-
rescue XMLRPC::FaultException =>
|
60
|
-
|
61
|
+
rescue XMLRPC::FaultException => e
|
62
|
+
cycle = (cycle || 0) + 1
|
63
|
+
raise(e) if cycle > 10 || e.message !~ /Session ID.*invalid/i
|
61
64
|
session.recreate!
|
62
65
|
retry
|
63
66
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'xmlrpc/client'
|
3
|
+
|
4
|
+
class XmlrpcClientTest < OpenX::TestCase
|
5
|
+
|
6
|
+
def client
|
7
|
+
@client ||= OpenX::XmlrpcClient.new("http://example.com/random/path")
|
8
|
+
end
|
9
|
+
|
10
|
+
def stub_xrc
|
11
|
+
stub(:call => nil, :timeout= => 10)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "initialize" do
|
15
|
+
assert_equal "http://example.com/random/path", client.url
|
16
|
+
assert_instance_of XMLRPC::Client, client.client
|
17
|
+
end
|
18
|
+
|
19
|
+
test "call forwarding" do
|
20
|
+
client.client.expects(:call).with('ox.getAgency', 1)
|
21
|
+
client.call('ox.getAgency', 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "call rescueing" do
|
25
|
+
a, b, c = stub_xrc, stub_xrc, stub_xrc
|
26
|
+
::XMLRPC::Client.stubs(:new2).returns(a, b, c)
|
27
|
+
|
28
|
+
a.expects(:call).with('ox.getAgency', 1).once.raises(Net::HTTPBadResponse, 'Bad response')
|
29
|
+
b.expects(:call).with('ox.getAgency', 1).once.raises(Errno::EPIPE, 'Other problem')
|
30
|
+
client.call('ox.getAgency', 1)
|
31
|
+
|
32
|
+
assert_not_equal client.client, a
|
33
|
+
assert_not_equal client.client, b
|
34
|
+
assert_equal client.client, c
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'xmlrpc/client'
|
3
|
+
|
4
|
+
class XmlrpcSessionClientTest < OpenX::TestCase
|
5
|
+
|
6
|
+
def client
|
7
|
+
@client ||= OpenX::XmlrpcSessionClient.new(stub_session)
|
8
|
+
end
|
9
|
+
|
10
|
+
def stub_session
|
11
|
+
stub(:url => "http://example.com/random/path", :id => 33)
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_xrc
|
15
|
+
stub(:call => nil, :timeout= => 10)
|
16
|
+
end
|
17
|
+
|
18
|
+
test "call forwarding" do
|
19
|
+
client.client.expects(:call).with('ox.getAgency', 33, 1)
|
20
|
+
client.call('ox.getAgency', 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "call rescueing" do
|
24
|
+
a, b = stub_xrc, stub_xrc
|
25
|
+
::XMLRPC::Client.stubs(:new2).returns(a, b)
|
26
|
+
|
27
|
+
a.expects(:call).once.raises(Net::HTTPBadResponse, 'Bad response')
|
28
|
+
b.expects(:call).once.raises(XMLRPC::FaultException.new(0, 'session id is invalid'))
|
29
|
+
client.session.expects(:recreate!).once
|
30
|
+
|
31
|
+
client.call('ox.getAgency', 1)
|
32
|
+
assert_not_equal client.client, a
|
33
|
+
assert_equal client.client, b
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsm-openx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 1.9.
|
9
|
+
- 3
|
10
|
+
version: 1.9.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aaron Patterson
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-09-
|
21
|
+
date: 2010-09-13 00:00:00 +01:00
|
22
22
|
default_executable:
|
23
23
|
dependencies: []
|
24
24
|
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- test/test_session.rb
|
71
71
|
- test/test_targeting_rule.rb
|
72
72
|
- test/test_targeting_rules.rb
|
73
|
+
- test/test_xmlrpc_client.rb
|
74
|
+
- test/test_xmlrpc_session_client.rb
|
73
75
|
- test/test_zone.rb
|
74
76
|
has_rdoc: true
|
75
77
|
homepage: http://github.com/bsm/openx
|
@@ -106,6 +108,7 @@ signing_key:
|
|
106
108
|
specification_version: 3
|
107
109
|
summary: A Ruby interface to the OpenX XML-RPC API
|
108
110
|
test_files:
|
111
|
+
- test/test_xmlrpc_session_client.rb
|
109
112
|
- test/test_openx.rb
|
110
113
|
- test/test_channel.rb
|
111
114
|
- test/test_targeting_rule.rb
|
@@ -119,4 +122,5 @@ test_files:
|
|
119
122
|
- test/test_services.rb
|
120
123
|
- test/test_banner.rb
|
121
124
|
- test/test_targeting_rules.rb
|
125
|
+
- test/test_xmlrpc_client.rb
|
122
126
|
- test/test_publisher.rb
|