openx 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +26 -0
- data/README.txt +80 -0
- data/Rakefile +40 -0
- data/lib/openx.rb +7 -0
- data/lib/openx/image.rb +22 -0
- data/lib/openx/services.rb +8 -0
- data/lib/openx/services/advertiser.rb +32 -0
- data/lib/openx/services/agency.rb +35 -0
- data/lib/openx/services/banner.rb +80 -0
- data/lib/openx/services/base.rb +125 -0
- data/lib/openx/services/campaign.rb +46 -0
- data/lib/openx/services/publisher.rb +32 -0
- data/lib/openx/services/session.rb +25 -0
- data/lib/openx/services/zone.rb +99 -0
- data/test/assets/300x250.jpg +0 -0
- data/test/assets/cat.swf +0 -0
- data/test/helper.rb +99 -0
- data/test/test_advertiser.rb +82 -0
- data/test/test_agency.rb +94 -0
- data/test/test_banner.rb +82 -0
- data/test/test_base.rb +37 -0
- data/test/test_campaign.rb +64 -0
- data/test/test_publisher.rb +69 -0
- data/test/test_session.rb +24 -0
- data/test/test_zone.rb +100 -0
- metadata +98 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module OpenX
|
2
|
+
module Services
|
3
|
+
class Campaign < Base
|
4
|
+
# Translate our property names to OpenX property names
|
5
|
+
openx_accessor :name => :campaignName,
|
6
|
+
:advertiser_id => :advertiserId,
|
7
|
+
:id => :campaignId,
|
8
|
+
:start_date => :startDate,
|
9
|
+
:end_date => :endDate,
|
10
|
+
:impressions => :impressions,
|
11
|
+
:target_impressions => :target_impressions,
|
12
|
+
:target_clicks => :target_clicks,
|
13
|
+
:revenue => :revenue,
|
14
|
+
:revenue_type => :revenue_type,
|
15
|
+
:impressions => :impressions,
|
16
|
+
:clicks => :clicks,
|
17
|
+
:priority => :priority,
|
18
|
+
:weight => :weight
|
19
|
+
|
20
|
+
has_one :advertiser
|
21
|
+
|
22
|
+
self.endpoint = '/CampaignXmlRpcService.php'
|
23
|
+
self.create = 'addCampaign'
|
24
|
+
self.update = 'modifyCampaign'
|
25
|
+
self.delete = 'deleteCampaign'
|
26
|
+
self.find_one = 'getCampaign'
|
27
|
+
self.find_all = 'getCampaignListByAdvertiserId'
|
28
|
+
|
29
|
+
# Revenue types
|
30
|
+
CPM = 1
|
31
|
+
CPC = 2
|
32
|
+
CPA = 3
|
33
|
+
MONTHLY_TENANCY = 4
|
34
|
+
|
35
|
+
def initialize(params = {})
|
36
|
+
raise ArgumentError unless params[:advertiser_id] || params[:advertiser]
|
37
|
+
params[:advertiser_id] ||= params[:advertiser].id
|
38
|
+
super(params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def banners
|
42
|
+
Banner.find(:all, self.id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module OpenX
|
2
|
+
module Services
|
3
|
+
class Publisher < Base
|
4
|
+
openx_accessor :name => :publisherName,
|
5
|
+
:contact_name => :contactName,
|
6
|
+
:email => :emailAddress,
|
7
|
+
:username => :username,
|
8
|
+
:password => :password,
|
9
|
+
:id => :publisherId,
|
10
|
+
:agency_id => :agencyId
|
11
|
+
|
12
|
+
has_one :agency
|
13
|
+
|
14
|
+
self.endpoint = '/PublisherXmlRpcService.php'
|
15
|
+
self.create = 'addPublisher'
|
16
|
+
self.update = 'modifyPublisher'
|
17
|
+
self.delete = 'deletePublisher'
|
18
|
+
self.find_one = 'getPublisher'
|
19
|
+
self.find_all = 'getPublisherListByAgencyId'
|
20
|
+
|
21
|
+
def initialize(params = {})
|
22
|
+
raise "need agency" unless params[:agency_id] || params[:agency]
|
23
|
+
params[:agency_id] ||= params[:agency].id
|
24
|
+
super(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def zones
|
28
|
+
Zone.find(:all, self.id)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenX
|
2
|
+
module Services
|
3
|
+
class Session
|
4
|
+
attr_accessor :url, :id
|
5
|
+
|
6
|
+
@@endpoint = '/LogonXmlRpcService.php'
|
7
|
+
def initialize(url)
|
8
|
+
@url = url
|
9
|
+
@server = XMLRPC::Client.new2("#{@url}#{@@endpoint}")
|
10
|
+
@id = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(user, password)
|
14
|
+
@id = @server.call('logon', user, password)
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
@server.call('logoff', @id)
|
20
|
+
@id = nil
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module OpenX
|
2
|
+
module Services
|
3
|
+
class Zone < Base
|
4
|
+
# Delivery types
|
5
|
+
BANNER = 'delivery-b'
|
6
|
+
INTERSTITIAL = 'delivery-i'
|
7
|
+
TEXT = 'delivery-t'
|
8
|
+
EMAIL = 'delivery-e'
|
9
|
+
|
10
|
+
# Tag Types
|
11
|
+
JAVASCRIPT = 'adjs'
|
12
|
+
LOCAL = 'local'
|
13
|
+
IFRAME = 'adframe'
|
14
|
+
XMLRPC_TAG = 'xmlrpc'
|
15
|
+
|
16
|
+
openx_accessor :name => :zoneName,
|
17
|
+
:id => :zoneId,
|
18
|
+
:width => :width,
|
19
|
+
:height => :height,
|
20
|
+
:type => :type,
|
21
|
+
:publisher_id => :publisherId
|
22
|
+
|
23
|
+
has_one :publisher
|
24
|
+
|
25
|
+
self.endpoint = '/ZoneXmlRpcService.php'
|
26
|
+
self.create = 'addZone'
|
27
|
+
self.update = 'modifyZone'
|
28
|
+
self.delete = 'deleteZone'
|
29
|
+
self.find_one = 'getZone'
|
30
|
+
self.find_all = 'getZoneListByPublisherId'
|
31
|
+
|
32
|
+
class << self
|
33
|
+
###
|
34
|
+
# Deliver +zone_id+ to +ip_address+ with +cookies+,
|
35
|
+
def deliver zone_id, ip_address = '192.168.1.1', cookies = []
|
36
|
+
url = "#{self.configuration['root']}/delivery/axmlrpc.php"
|
37
|
+
server = XMLRPC::Client.new2(url)
|
38
|
+
server.call('openads.view', {
|
39
|
+
'cookies' => cookies,
|
40
|
+
'remote_addr' => ip_address,
|
41
|
+
}, "zone:#{zone_id}", 0, '', '', true, [])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(params = {})
|
46
|
+
raise "need publisher" unless params[:publisher_id] || params[:publisher]
|
47
|
+
params[:publisher_id] ||= params[:publisher].id
|
48
|
+
super(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Link this zone to +campaign+
|
52
|
+
def link_campaign(campaign)
|
53
|
+
raise "Zone must be saved" if new_record?
|
54
|
+
raise ArgumentError.new("Campaign must be saved")if campaign.new_record?
|
55
|
+
|
56
|
+
session = self.class.connection
|
57
|
+
server = XMLRPC::Client.new2("#{session.url}#{self.class.endpoint}")
|
58
|
+
server.call("linkCampaign", session.id, self.id, campaign.id)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Unlink this zone from +campaign+
|
62
|
+
def unlink_campaign(campaign)
|
63
|
+
raise "Zone must be saved" if new_record?
|
64
|
+
raise ArgumentError.new("Campaign must be saved")if campaign.new_record?
|
65
|
+
|
66
|
+
session = self.class.connection
|
67
|
+
server = XMLRPC::Client.new2("#{session.url}#{self.class.endpoint}")
|
68
|
+
server.call("unlinkCampaign", session.id, self.id, campaign.id)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Link this zone to +banner+
|
72
|
+
def link_banner(banner)
|
73
|
+
raise "Zone must be saved" if new_record?
|
74
|
+
raise ArgumentError.new("Banner must be saved")if banner.new_record?
|
75
|
+
|
76
|
+
session = self.class.connection
|
77
|
+
server = XMLRPC::Client.new2("#{session.url}#{self.class.endpoint}")
|
78
|
+
server.call("linkBanner", session.id, self.id, banner.id)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Unlink this zone from +banner+
|
82
|
+
def unlink_banner(banner)
|
83
|
+
raise "Zone must be saved" if new_record?
|
84
|
+
raise ArgumentError.new("Banner must be saved")if banner.new_record?
|
85
|
+
|
86
|
+
session = self.class.connection
|
87
|
+
server = XMLRPC::Client.new2("#{session.url}#{self.class.endpoint}")
|
88
|
+
server.call("unlinkBanner", session.id, self.id, banner.id)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Generate tags for displaying this zone using +tag_type+
|
92
|
+
def generate_tags(tag_type = IFRAME)
|
93
|
+
session = self.class.connection
|
94
|
+
server = XMLRPC::Client.new2("#{session.url}#{self.class.endpoint}")
|
95
|
+
server.call("generateTags", session.id, self.id, tag_type, [])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
Binary file
|
data/test/assets/cat.swf
ADDED
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../lib')))
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'openx'
|
5
|
+
|
6
|
+
ENV['OPENX_ENV'] = 'test'
|
7
|
+
|
8
|
+
module OpenX
|
9
|
+
class TestCase < Test::Unit::TestCase
|
10
|
+
TEST_SWF = File.expand_path(File.join(File.dirname(__FILE__), 'assets', 'cat.swf'))
|
11
|
+
TEST_JPG = File.expand_path(File.join(File.dirname(__FILE__), 'assets', '300x250.jpg'))
|
12
|
+
|
13
|
+
include OpenX::Services
|
14
|
+
|
15
|
+
undef :default_test
|
16
|
+
|
17
|
+
def setup
|
18
|
+
assert(
|
19
|
+
File.exists?(Base::CONFIGURATION_YAML),
|
20
|
+
'Please create the credentials file'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def agency
|
25
|
+
@agency ||= Agency.create!(
|
26
|
+
{
|
27
|
+
:name => "Testing! - #{Time.now}",
|
28
|
+
:contact_name => 'Contact Name!',
|
29
|
+
:email => 'foo@bar.com'
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def advertiser
|
35
|
+
@advertiser ||= Advertiser.create!(
|
36
|
+
{
|
37
|
+
:name => "adv-#{Time.now}",
|
38
|
+
:contact_name => 'Contact Name!',
|
39
|
+
:email => 'foo@bar.com'
|
40
|
+
}.merge(:agency => agency)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def campaign
|
45
|
+
@campaign ||= Campaign.create!(
|
46
|
+
{
|
47
|
+
:advertiser => advertiser,
|
48
|
+
:name => "Campaign-#{Time.now}",
|
49
|
+
:impressions => 2000
|
50
|
+
}
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def publisher
|
55
|
+
@publisher ||= Publisher.create!(
|
56
|
+
{
|
57
|
+
:agency => agency,
|
58
|
+
:name => "Publisher! - #{Time.now}",
|
59
|
+
:contact_name => 'Aaron Patterson',
|
60
|
+
:email => 'aaron@tenderlovemaking.com',
|
61
|
+
:username => 'one',
|
62
|
+
:password => 'two',
|
63
|
+
}
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def zone
|
68
|
+
@zone ||= Zone.create!(
|
69
|
+
{
|
70
|
+
:publisher => publisher,
|
71
|
+
:name => "Zone - #{Time.now}",
|
72
|
+
:type => Zone::BANNER,
|
73
|
+
:width => 300,
|
74
|
+
:height => 250,
|
75
|
+
}
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def banner
|
80
|
+
@banner ||= Banner.create!({
|
81
|
+
:name => "Banner-#{Time.now}",
|
82
|
+
:storage_type => Banner::LOCAL_SQL,
|
83
|
+
:campaign => campaign,
|
84
|
+
:url => 'http://tenderlovemaking.com/',
|
85
|
+
:file_name => 'oogabooga',
|
86
|
+
:image => OpenX::Image.new(File.open(TEST_SWF, 'rb'))
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
90
|
+
def destroy
|
91
|
+
@banner.destroy if defined? @banner
|
92
|
+
@zone.destroy if defined? @zone
|
93
|
+
@publisher.destroy if defined? @publisher
|
94
|
+
@campaign.destroy if defined? @campaign
|
95
|
+
@advertiser.destroy if defined? @advertiser
|
96
|
+
@agency.destroy if defined? @agency
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AdvertiserTest < OpenX::TestCase
|
4
|
+
def test_create_advertiser
|
5
|
+
advertiser = nil
|
6
|
+
assert_nothing_raised {
|
7
|
+
advertiser = Advertiser.create!(init_params.merge({
|
8
|
+
:agency => agency,
|
9
|
+
}))
|
10
|
+
}
|
11
|
+
assert_not_nil advertiser
|
12
|
+
init_params.each do |k,v|
|
13
|
+
assert_equal(v, advertiser.send(:"#{k}"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_destroy
|
18
|
+
a = nil
|
19
|
+
assert_nothing_raised {
|
20
|
+
a = Advertiser.create!(init_params.merge({:agency => agency}))
|
21
|
+
}
|
22
|
+
id = a.id
|
23
|
+
assert_nothing_raised {
|
24
|
+
a.destroy
|
25
|
+
}
|
26
|
+
assert_raises(XMLRPC::FaultException) {
|
27
|
+
Advertiser.find(id)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_advertiser_with_agency
|
32
|
+
advertiser = nil
|
33
|
+
assert_nothing_raised {
|
34
|
+
advertiser = agency.create_advertiser!(init_params)
|
35
|
+
}
|
36
|
+
assert_not_nil advertiser
|
37
|
+
init_params.each do |k,v|
|
38
|
+
assert_equal(v, advertiser.send(:"#{k}"))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_find_advertiser
|
43
|
+
advertiser = nil
|
44
|
+
assert_nothing_raised {
|
45
|
+
advertiser = agency.create_advertiser!(init_params)
|
46
|
+
}
|
47
|
+
assert_not_nil advertiser
|
48
|
+
|
49
|
+
original = advertiser
|
50
|
+
advertiser = Advertiser.find(advertiser.id)
|
51
|
+
assert_equal(original, advertiser)
|
52
|
+
assert_not_nil advertiser
|
53
|
+
assert_not_nil advertiser.agency
|
54
|
+
init_params.each do |k,v|
|
55
|
+
assert_equal(v, advertiser.send(:"#{k}"))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_find_all_advertisers
|
60
|
+
advertiser = nil
|
61
|
+
assert_nothing_raised {
|
62
|
+
advertiser = agency.create_advertiser!(init_params)
|
63
|
+
}
|
64
|
+
assert_not_nil advertiser
|
65
|
+
|
66
|
+
advertisers = Advertiser.find(:all, agency.id)
|
67
|
+
|
68
|
+
advertiser = advertisers.find { |a| a.id == advertiser.id }
|
69
|
+
assert_not_nil advertiser
|
70
|
+
init_params.each do |k,v|
|
71
|
+
assert_equal(v, advertiser.send(:"#{k}"))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def init_params
|
76
|
+
{
|
77
|
+
:name => 'Test advertiser',
|
78
|
+
:contact_name => 'Contact name',
|
79
|
+
:email => 'email@example.com',
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
data/test/test_agency.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AgencyTest < OpenX::TestCase
|
4
|
+
def destroy
|
5
|
+
Agency.find(:all).each do |agency|
|
6
|
+
agency.destroy if agency.name == init_params[:name]
|
7
|
+
end
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_create!
|
12
|
+
a = nil
|
13
|
+
assert_nothing_raised {
|
14
|
+
a = Agency.create!(init_params)
|
15
|
+
}
|
16
|
+
assert_not_nil a
|
17
|
+
assert_not_nil a.id
|
18
|
+
init_params.each { |k,v|
|
19
|
+
assert_equal(v, a.send(:"#{k}"))
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_modify
|
24
|
+
a = nil
|
25
|
+
assert_nothing_raised {
|
26
|
+
a = Agency.create!(init_params)
|
27
|
+
}
|
28
|
+
assert_not_nil a
|
29
|
+
assert_not_nil a.id
|
30
|
+
a.name = 'Awesome name!'
|
31
|
+
a.save!
|
32
|
+
|
33
|
+
a = Agency.find(a.id)
|
34
|
+
assert_equal('Awesome name!', a.name)
|
35
|
+
a.destroy
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_find
|
39
|
+
a = nil
|
40
|
+
assert_nothing_raised {
|
41
|
+
a = Agency.create!(init_params)
|
42
|
+
}
|
43
|
+
a = Agency.find(a.id)
|
44
|
+
init_params.each { |k,v|
|
45
|
+
assert_equal(v, a.send(:"#{k}"))
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_find_all
|
50
|
+
a = nil
|
51
|
+
assert_nothing_raised {
|
52
|
+
a = Agency.create!(init_params)
|
53
|
+
}
|
54
|
+
list = Agency.find(:all)
|
55
|
+
assert list.all? { |x| x.is_a?(Agency) }
|
56
|
+
assert list.any? { |x| x.name == init_params[:name] }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_destroy
|
60
|
+
a = nil
|
61
|
+
assert_nothing_raised {
|
62
|
+
a = Agency.create!(init_params)
|
63
|
+
}
|
64
|
+
id = a.id
|
65
|
+
assert_nothing_raised {
|
66
|
+
a.destroy
|
67
|
+
}
|
68
|
+
assert_raises(XMLRPC::FaultException) {
|
69
|
+
Agency.find(id)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_static_destroy
|
74
|
+
a = nil
|
75
|
+
assert_nothing_raised {
|
76
|
+
a = Agency.create!(init_params)
|
77
|
+
}
|
78
|
+
id = a.id
|
79
|
+
assert_nothing_raised {
|
80
|
+
Agency.destroy(id)
|
81
|
+
}
|
82
|
+
assert_raises(XMLRPC::FaultException) {
|
83
|
+
Agency.find(id)
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def init_params
|
88
|
+
{
|
89
|
+
:name => 'Testing!',
|
90
|
+
:contact_name => 'Contact Name!',
|
91
|
+
:email => 'foo@bar.com'
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|