krakatoa-openx 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +8 -0
- data/Gemfile.lock +25 -0
- data/README.txt +85 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/krakatoa-openx.gemspec +75 -0
- data/lib/openx.rb +44 -0
- data/lib/openx/image.rb +22 -0
- data/lib/openx/invocation.rb +62 -0
- data/lib/openx/persistance.rb +63 -0
- data/lib/openx/services.rb +29 -0
- data/lib/openx/services/advertiser.rb +31 -0
- data/lib/openx/services/agency.rb +38 -0
- data/lib/openx/services/banner.rb +96 -0
- data/lib/openx/services/base.rb +97 -0
- data/lib/openx/services/campaign.rb +56 -0
- data/lib/openx/services/channel.rb +42 -0
- data/lib/openx/services/publisher.rb +36 -0
- data/lib/openx/services/session.rb +44 -0
- data/lib/openx/services/zone.rb +82 -0
- data/lib/openx/targeting_rule.rb +121 -0
- data/lib/openx/targeting_rules.rb +24 -0
- data/lib/openx/xmlrpc_client.rb +75 -0
- data/test/assets/300x250.jpg +0 -0
- data/test/assets/cat.swf +0 -0
- data/test/helper.rb +131 -0
- data/test/test_advertiser.rb +82 -0
- data/test/test_agency.rb +94 -0
- data/test/test_banner.rb +85 -0
- data/test/test_base.rb +40 -0
- data/test/test_campaign.rb +64 -0
- data/test/test_channel.rb +65 -0
- data/test/test_openx.rb +17 -0
- data/test/test_publisher.rb +69 -0
- data/test/test_services.rb +16 -0
- data/test/test_session.rb +42 -0
- data/test/test_targeting_rule.rb +85 -0
- data/test/test_targeting_rules.rb +13 -0
- data/test/test_xmlrpc_client.rb +37 -0
- data/test/test_xmlrpc_session_client.rb +36 -0
- data/test/test_zone.rb +101 -0
- metadata +89 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class SessionTest < OpenX::TestCase
|
4
|
+
|
5
|
+
test "has a URI" do
|
6
|
+
assert_instance_of URI::HTTP, new_session.uri
|
7
|
+
end
|
8
|
+
|
9
|
+
test "has a URL" do
|
10
|
+
assert_equal 'http://test.host/path/to/api', new_session('http://test.host/path/to/api').url
|
11
|
+
end
|
12
|
+
|
13
|
+
test "has a host" do
|
14
|
+
assert_equal 'http://test.host', new_session('http://test.host/path/to/api').host
|
15
|
+
end
|
16
|
+
|
17
|
+
test "offers session-based API client (remote reference)" do
|
18
|
+
assert_instance_of OpenX::XmlrpcSessionClient, new_session.remote
|
19
|
+
end
|
20
|
+
|
21
|
+
test "login working" do
|
22
|
+
assert_nothing_raised { new_session.create(config['username'], config['password']) }
|
23
|
+
end
|
24
|
+
|
25
|
+
test "logout working" do
|
26
|
+
assert_nothing_raised { new_session.create(config['username'], config['password']) }
|
27
|
+
assert_not_nil new_session.id
|
28
|
+
assert_nothing_raised { new_session.destroy }
|
29
|
+
assert_nil new_session.id
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def config
|
35
|
+
OpenX.configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_session(url = config['url'])
|
39
|
+
@session ||= Session.new(url)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TargetingRuleTest < OpenX::TestCase
|
4
|
+
|
5
|
+
test "is a Hash" do
|
6
|
+
assert_kind_of Hash, rule
|
7
|
+
end
|
8
|
+
|
9
|
+
test "has a type" do
|
10
|
+
assert_equal 'Geo:Region', rule['type']
|
11
|
+
end
|
12
|
+
|
13
|
+
test "raises exception on invalid type" do
|
14
|
+
assert_raise(RuntimeError) { new_rule('Wrong') }
|
15
|
+
assert_raise(RuntimeError) { new_rule('Geo:Wrong') }
|
16
|
+
assert_nothing_raised { new_rule('deliveryLimitations:Geo:Country') }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "accepts updates" do
|
20
|
+
rule = new_rule.update('comparison' => '==')
|
21
|
+
assert_instance_of TargetingRule, rule
|
22
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=="}, rule)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "accessors" do
|
26
|
+
rule = new_rule.logical('or').compare('==').with('GB|H9')
|
27
|
+
assert_equal({"logical"=>"or", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, rule)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "completeness" do
|
31
|
+
assert !new_rule.complete?
|
32
|
+
assert new_rule.logical('or').compare('==').with('GB|H9').complete?
|
33
|
+
end
|
34
|
+
|
35
|
+
test "instantiation" do
|
36
|
+
assert_equal({
|
37
|
+
"logical"=>"and", "data"=>"test", "type"=>"Site:Pageurl", "comparison"=>"=~"
|
38
|
+
}, TargetingRule.instantiate(
|
39
|
+
"logical"=>"and", "data"=>"test", "type"=>"deliveryLimitations:Site:Pageurl", "comparison"=>"=~"
|
40
|
+
))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "comparisons" do
|
44
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.eq?('GB|H9'))
|
45
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.equal?('GB|H9'))
|
46
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.is?('GB|H9'))
|
47
|
+
|
48
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.ne?('GB|H9'))
|
49
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.not_equal?('GB|H9'))
|
50
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!=", "data" => "GB|H9"}, new_rule.not?('GB|H9'))
|
51
|
+
|
52
|
+
assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>">", "data" => "3"}, new_rule('Time:Day') > '3')
|
53
|
+
assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>"<", "data" => "3"}, new_rule('Time:Day') < '3')
|
54
|
+
assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>">=", "data" => "3"}, new_rule('Time:Day') >= '3')
|
55
|
+
assert_equal({"logical"=>"and", "type"=>"Time:Day", "comparison"=>"<=", "data" => "3"}, new_rule('Time:Day') <= '3')
|
56
|
+
|
57
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}, new_rule('Geo:Country').include?('GB', 'US'))
|
58
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}, new_rule('Geo:Country').contains?('GB', 'US'))
|
59
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Country", "comparison"=>"!~", "data" => "GB,US"}, new_rule('Geo:Country').exclude?('GB', 'US'))
|
60
|
+
|
61
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=x", "data" => "GB.H\\d"}, new_rule.match?(/GB.H\d/))
|
62
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"=x", "data" => "GB.H\\d"}, new_rule =~ /GB.H\d/)
|
63
|
+
assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"!x", "data" => "GB.H\\d"}, new_rule.no_match?(/GB.H\d/))
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'combining' do
|
67
|
+
rule = new_rule('Time:Day').gt?(3)
|
68
|
+
assert_equal rule['logical'], 'and'
|
69
|
+
rule = new_rule & rule
|
70
|
+
assert_equal rule['logical'], 'and'
|
71
|
+
rule = new_rule | rule
|
72
|
+
assert_equal rule['logical'], 'or'
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def rule
|
78
|
+
@rule ||= new_rule
|
79
|
+
end
|
80
|
+
|
81
|
+
def new_rule(type = 'Geo:Region')
|
82
|
+
TargetingRule.new(type)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TargetingRulesTest < OpenX::TestCase
|
4
|
+
|
5
|
+
test "creating rules" do
|
6
|
+
assert_equal [
|
7
|
+
{"logical"=>"and", "type"=>"Site:Pageurl", "comparison"=>"=~", "data" => "test"},
|
8
|
+
{"logical"=>"and", "type"=>"Client:Ip", "comparison"=>"=x", "data" => "^127\\."},
|
9
|
+
{"logical"=>"or", "type"=>"Geo:Country", "comparison"=>"=~", "data" => "GB,US"}
|
10
|
+
], targeting_rules
|
11
|
+
end
|
12
|
+
|
13
|
+
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
|
data/test/test_zone.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class ZoneTest < OpenX::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
params = init_params
|
7
|
+
zone = Zone.create!(params)
|
8
|
+
assert_not_nil zone
|
9
|
+
params.each do |k,v|
|
10
|
+
assert_equal(v, zone.send(:"#{k}"))
|
11
|
+
end
|
12
|
+
zone.destroy
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_find
|
16
|
+
params = init_params
|
17
|
+
zone = Zone.create!(params)
|
18
|
+
assert_not_nil zone
|
19
|
+
found_zone = Zone.find(zone.id)
|
20
|
+
assert_not_nil found_zone
|
21
|
+
assert_equal(zone, found_zone)
|
22
|
+
zone.destroy
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find_all
|
26
|
+
params = init_params
|
27
|
+
zone = Zone.create!(params)
|
28
|
+
assert_not_nil zone
|
29
|
+
|
30
|
+
zones = Zone.find(:all, publisher.id)
|
31
|
+
assert_equal(zones.sort, publisher.zones.sort)
|
32
|
+
found_zone = zones.find { |z| z.id == zone.id }
|
33
|
+
assert found_zone
|
34
|
+
assert_equal(zone, found_zone)
|
35
|
+
zone.destroy
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_destroy
|
39
|
+
params = init_params
|
40
|
+
zone = Zone.create!(params)
|
41
|
+
assert_not_nil zone
|
42
|
+
id = zone.id
|
43
|
+
assert_nothing_raised {
|
44
|
+
zone.destroy
|
45
|
+
}
|
46
|
+
assert_raises(XMLRPC::FaultException) {
|
47
|
+
Zone.find(id)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_update
|
52
|
+
params = init_params
|
53
|
+
zone = Zone.create!(params)
|
54
|
+
assert_not_nil zone
|
55
|
+
|
56
|
+
found_zone = Zone.find(zone.id)
|
57
|
+
found_zone.name = 'tenderlove'
|
58
|
+
found_zone.save!
|
59
|
+
|
60
|
+
found_zone = Zone.find(zone.id)
|
61
|
+
assert_equal('tenderlove', found_zone.name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_link_campaign
|
65
|
+
assert zone.link_campaign(campaign)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_unlink_campaign
|
69
|
+
assert_raises(XMLRPC::FaultException) {
|
70
|
+
zone.unlink_campaign(campaign)
|
71
|
+
}
|
72
|
+
assert zone.link_campaign(campaign)
|
73
|
+
assert zone.unlink_campaign(campaign)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_link_banner
|
77
|
+
assert zone.link_banner(banner)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_unlink_banner
|
81
|
+
assert_raises(XMLRPC::FaultException) {
|
82
|
+
zone.unlink_banner(banner)
|
83
|
+
}
|
84
|
+
assert zone.link_banner(banner)
|
85
|
+
assert zone.unlink_banner(banner)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_generate_tags
|
89
|
+
assert_match(/iframe/, zone.generate_tags)
|
90
|
+
end
|
91
|
+
|
92
|
+
def init_params
|
93
|
+
{
|
94
|
+
:publisher => publisher,
|
95
|
+
:name => "Zone - #{Time.now}",
|
96
|
+
:type => Zone::BANNER,
|
97
|
+
:width => 468,
|
98
|
+
:height => 60,
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: krakatoa-openx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Patterson
|
9
|
+
- Andy Smith
|
10
|
+
- TouchLocal P/L
|
11
|
+
- Dimitrij Denissenko
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2011-10-17 00:00:00.000000000Z
|
16
|
+
dependencies: []
|
17
|
+
description: A Ruby interface to the OpenX XML-RPC API
|
18
|
+
email: krakatoa1987@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files:
|
22
|
+
- README.txt
|
23
|
+
files:
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- README.txt
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- krakatoa-openx.gemspec
|
30
|
+
- lib/openx.rb
|
31
|
+
- lib/openx/image.rb
|
32
|
+
- lib/openx/invocation.rb
|
33
|
+
- lib/openx/persistance.rb
|
34
|
+
- lib/openx/services.rb
|
35
|
+
- lib/openx/services/advertiser.rb
|
36
|
+
- lib/openx/services/agency.rb
|
37
|
+
- lib/openx/services/banner.rb
|
38
|
+
- lib/openx/services/base.rb
|
39
|
+
- lib/openx/services/campaign.rb
|
40
|
+
- lib/openx/services/channel.rb
|
41
|
+
- lib/openx/services/publisher.rb
|
42
|
+
- lib/openx/services/session.rb
|
43
|
+
- lib/openx/services/zone.rb
|
44
|
+
- lib/openx/targeting_rule.rb
|
45
|
+
- lib/openx/targeting_rules.rb
|
46
|
+
- lib/openx/xmlrpc_client.rb
|
47
|
+
- test/assets/300x250.jpg
|
48
|
+
- test/assets/cat.swf
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_advertiser.rb
|
51
|
+
- test/test_agency.rb
|
52
|
+
- test/test_banner.rb
|
53
|
+
- test/test_base.rb
|
54
|
+
- test/test_campaign.rb
|
55
|
+
- test/test_channel.rb
|
56
|
+
- test/test_openx.rb
|
57
|
+
- test/test_publisher.rb
|
58
|
+
- test/test_services.rb
|
59
|
+
- test/test_session.rb
|
60
|
+
- test/test_targeting_rule.rb
|
61
|
+
- test/test_targeting_rules.rb
|
62
|
+
- test/test_xmlrpc_client.rb
|
63
|
+
- test/test_xmlrpc_session_client.rb
|
64
|
+
- test/test_zone.rb
|
65
|
+
homepage: http://github.com/krakatoa/openx
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.10
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: A Ruby interface to the OpenX XML-RPC API
|
89
|
+
test_files: []
|