bsm-openx 1.9.1

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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.swp
2
+ .svn/
3
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'activesupport', :require => 'active_support/test_case'
5
+ gem 'rake'
6
+ gem 'jeweler'
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.0)
5
+ gemcutter (0.6.1)
6
+ git (1.2.5)
7
+ jeweler (1.4.0)
8
+ gemcutter (>= 0.1.0)
9
+ git (>= 1.2.5)
10
+ rubyforge (>= 2.0.0)
11
+ json_pure (1.4.6)
12
+ rake (0.8.7)
13
+ rubyforge (2.0.4)
14
+ json_pure (>= 1.1.7)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ activesupport
21
+ jeweler
22
+ rake
data/README.txt ADDED
@@ -0,0 +1,85 @@
1
+ = OpenX
2
+
3
+ A Ruby interface to the OpenX XML-RPC API.
4
+
5
+ == SYNOPSIS:
6
+
7
+ OpenX.configuration = {
8
+ 'username' => 'admin',
9
+ 'password' => 'password',
10
+ 'url' => 'http://localhost/www/api/v2/xmlrpc/',
11
+ 'timeout' => 10, # Optional
12
+ 'reconnect' => true # Optional
13
+ }
14
+
15
+ OpenX::Services::Agency.find(:all).each do |agency|
16
+ puts agency.name
17
+
18
+ # Look up publishers
19
+ agency.publishers.each do |publisher|
20
+ puts "-- #{publisher.name}"
21
+ end
22
+
23
+ # Create a publisher
24
+ OpenX::Services::Publisher.create!(
25
+ :agency => agency,
26
+ :name => 'My Test Publisher',
27
+ :contact_name => 'Aaron Patterson',
28
+ :email => 'aaron@tenderlovemaking.com',
29
+ :username => 'user',
30
+ :password => 'password'
31
+ )
32
+ end
33
+
34
+ == REQUIREMENTS:
35
+
36
+ * ruby
37
+
38
+ == INSTALL:
39
+
40
+ * sudo gem install bsm-openx
41
+ * Update your $HOME/.openx/credentials.yml file.
42
+ You can set your own path via OpenX.config_file = '/path/pto/file.yml'.
43
+ Here is a sample:
44
+
45
+ ---
46
+ production:
47
+ username: admin
48
+ password: admin
49
+ url: http://www.example.com/www/api/v2/xmlrpc/
50
+ invocation_url: http://www.example.com/www/delivery/axmlrpc.php
51
+
52
+ The YAML file lists configuration for each environment. The gem uses the
53
+ 'production' environment by default. Trailing slash is required on the 'url'.
54
+ 'invocation_url' is only used by the OpenX::Invocation methods to serve
55
+ advertisements over XML-RPC
56
+
57
+ == LICENSE:
58
+
59
+ (The MIT License)
60
+
61
+ Copyright (c) 2010:
62
+
63
+ * {Aaron Patterson}[http://tenderlovemaking.com]
64
+ * Andy Smith
65
+ * {TouchLocal P/L}[http://www.touchlocal.com]
66
+ * Dimitrij Denissenko
67
+
68
+ Permission is hereby granted, free of charge, to any person obtaining
69
+ a copy of this software and associated documentation files (the
70
+ 'Software'), to deal in the Software without restriction, including
71
+ without limitation the rights to use, copy, modify, merge, publish,
72
+ distribute, sublicense, and/or sell copies of the Software, and to
73
+ permit persons to whom the Software is furnished to do so, subject to
74
+ the following conditions:
75
+
76
+ The above copyright notice and this permission notice shall be
77
+ included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
80
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
81
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
82
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
83
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
84
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
85
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ $: << File.join(File.dirname(__FILE__), "lib")
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'openx'
7
+
8
+ Rake::TestTask.new(:test) do |test|
9
+ test.test_files = FileList["test/**/test_*.rb"].sort
10
+ test.libs << "test"
11
+ test.verbose = false
12
+ test.warning = true
13
+ end
14
+
15
+ task :default => :test
16
+
17
+ namespace :openx do
18
+ task :clean do
19
+ ENV['OPENX_ENV'] = 'test'
20
+ include OpenX::Services
21
+
22
+ Agency.find(:all) do |agency|
23
+ Advertiser.find(:all, agency.id).each do |advertiser|
24
+ Campaign.find(:all, advertiser.id).each do |campaign|
25
+ Banner.find(:all, campaign.id).each do |banner|
26
+ banner.destroy
27
+ end
28
+ campaign.destroy
29
+ end
30
+ advertiser.destroy
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+
38
+ begin
39
+ require 'jeweler'
40
+ Jeweler::Tasks.new do |gemspec|
41
+ gemspec.name = "bsm-openx"
42
+ gemspec.summary = "A Ruby interface to the OpenX XML-RPC API"
43
+ gemspec.description = "A Ruby interface to the OpenX XML-RPC API"
44
+ gemspec.email = "dimitrij@blacksquaremedia.com"
45
+ gemspec.homepage = "http://github.com/dim/openx"
46
+ gemspec.authors = ["Aaron Patterson", "Andy Smith", "TouchLocal P/L", "Dimitrij Denissenko"]
47
+ end
48
+ Jeweler::GemcutterTasks.new
49
+ rescue LoadError
50
+ puts "Jeweler not available. Install it with: gem install jeweler"
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.9.1
data/bsm-openx.gemspec ADDED
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{bsm-openx}
8
+ s.version = "1.9.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aaron Patterson", "Andy Smith", "TouchLocal P/L", "Dimitrij Denissenko"]
12
+ s.date = %q{2010-09-09}
13
+ s.description = %q{A Ruby interface to the OpenX XML-RPC API}
14
+ s.email = %q{dimitrij@blacksquaremedia.com}
15
+ s.extra_rdoc_files = [
16
+ "README.txt"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "README.txt",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bsm-openx.gemspec",
26
+ "lib/openx.rb",
27
+ "lib/openx/image.rb",
28
+ "lib/openx/invocation.rb",
29
+ "lib/openx/services.rb",
30
+ "lib/openx/services/advertiser.rb",
31
+ "lib/openx/services/agency.rb",
32
+ "lib/openx/services/banner.rb",
33
+ "lib/openx/services/base.rb",
34
+ "lib/openx/services/campaign.rb",
35
+ "lib/openx/services/channel.rb",
36
+ "lib/openx/services/persistance.rb",
37
+ "lib/openx/services/publisher.rb",
38
+ "lib/openx/services/session.rb",
39
+ "lib/openx/services/targeting_rule.rb",
40
+ "lib/openx/services/targeting_rules.rb",
41
+ "lib/openx/services/zone.rb",
42
+ "lib/openx/xmlrpc_client.rb",
43
+ "test/assets/300x250.jpg",
44
+ "test/assets/cat.swf",
45
+ "test/helper.rb",
46
+ "test/test_advertiser.rb",
47
+ "test/test_agency.rb",
48
+ "test/test_banner.rb",
49
+ "test/test_base.rb",
50
+ "test/test_campaign.rb",
51
+ "test/test_channel.rb",
52
+ "test/test_openx.rb",
53
+ "test/test_publisher.rb",
54
+ "test/test_services.rb",
55
+ "test/test_session.rb",
56
+ "test/test_targeting_rule.rb",
57
+ "test/test_targeting_rules.rb",
58
+ "test/test_zone.rb"
59
+ ]
60
+ s.homepage = %q{http://github.com/dim/openx}
61
+ s.rdoc_options = ["--charset=UTF-8"]
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = %q{1.3.7}
64
+ s.summary = %q{A Ruby interface to the OpenX XML-RPC API}
65
+ s.test_files = [
66
+ "test/test_openx.rb",
67
+ "test/test_channel.rb",
68
+ "test/test_targeting_rule.rb",
69
+ "test/test_zone.rb",
70
+ "test/test_session.rb",
71
+ "test/helper.rb",
72
+ "test/test_campaign.rb",
73
+ "test/test_base.rb",
74
+ "test/test_agency.rb",
75
+ "test/test_advertiser.rb",
76
+ "test/test_services.rb",
77
+ "test/test_banner.rb",
78
+ "test/test_targeting_rules.rb",
79
+ "test/test_publisher.rb"
80
+ ]
81
+
82
+ if s.respond_to? :specification_version then
83
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
84
+ s.specification_version = 3
85
+
86
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
87
+ else
88
+ end
89
+ else
90
+ end
91
+ end
92
+
data/lib/openx.rb ADDED
@@ -0,0 +1,41 @@
1
+ module OpenX
2
+ autoload :Image, 'openx/image'
3
+ autoload :Invocation, 'openx/invocation'
4
+ autoload :Services, 'openx/services'
5
+ autoload :XmlrpcClient, 'openx/xmlrpc_client'
6
+ autoload :XmlrpcSessionClient, 'openx/xmlrpc_client'
7
+
8
+ @@env = ENV['OPENX_ENV'] || 'production'
9
+ @@config_file = File.join(ENV['HOME'], '.openx', 'credentials.yml')
10
+ @@configuration = nil
11
+
12
+ DEFAULT_OPTIONS = { 'retry' => true, 'timeout' => 10 }
13
+
14
+ class << self
15
+
16
+ def env
17
+ @@env
18
+ end
19
+
20
+ def env=(value)
21
+ @@env = value
22
+ end
23
+
24
+ def configuration
25
+ @@configuration ||= DEFAULT_OPTIONS.merge(YAML.load_file(config_file)[env])
26
+ end
27
+
28
+ def configuration=(value)
29
+ @@configuration = value
30
+ end
31
+
32
+ def config_file
33
+ @@config_file
34
+ end
35
+
36
+ def config_file=(value)
37
+ @@config_file = value
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ module OpenX
2
+ class Image
3
+ include XMLRPC::Marshallable
4
+ attr_accessor :filename, :content, :editswf
5
+
6
+ def initialize(hash_or_file)
7
+ @editswf = 0
8
+ if hash_or_file.is_a?(File)
9
+ @filename = File.basename(hash_or_file.path)
10
+ @editswf = File.basename(@filename, '.swf') == @filename ? 0 : 1
11
+ @content = XMLRPC::Base64.new(hash_or_file.read)
12
+ else
13
+ raise ArgumentError unless hash_or_file.key?(:filename)
14
+ raise ArgumentError unless hash_or_file.key?(:content)
15
+ hash_or_file.each { |k,v| send(:"#{k}=", v) }
16
+ unless self.content.is_a?(XMLRPC::Base64)
17
+ self.content = XMLRPC::Base64.new(self.content)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,62 @@
1
+ module OpenX
2
+ class Invocation
3
+ class << self
4
+ DEFAULTS = {
5
+ :count => 1,
6
+ :campaignid => 0,
7
+ :target => '',
8
+ :source => '',
9
+ :with_text => false,
10
+ :exclusions => [],
11
+ :inclusions => [],
12
+ :exclude_by_campaignid => false,
13
+ :exclude_by_bannerid => false
14
+ }.freeze
15
+
16
+ #
17
+ # banner = OpenX::Invocation.view("Plumber")
18
+ #
19
+ # banners = OpenX::Invocation.view("Plumber", :count => 2, :exclude_by_campaignid => true) ;nil
20
+ # banners.each do |banner|
21
+ # puts "Banner #{banner['bannerid']}"
22
+ # end; nil
23
+ #
24
+ def view(what, params = {})
25
+ params = DEFAULTS.merge(params)
26
+ url = OpenX::Services.configuration['invocation_url']
27
+ settings = {:cookies => [], :remote_addr => 'localhost'}
28
+
29
+ context = [] # used by reference after initial use
30
+ params[:exclusions].each { |item| context << convert_to_context(false, item) }
31
+ params[:inclusions].each { |item| context << convert_to_context(true, item) }
32
+ count = params[:count].to_i
33
+
34
+ remote_params = [ what, params[:campaignid], params[:target], params[:source], params[:with_text], context]
35
+ server = XmlrpcClient.new(url)
36
+
37
+ out = []
38
+ if count > 0
39
+ (0...count).each do
40
+ out << banner = server.call('openads.view', settings, *remote_params)
41
+ if count > 1
42
+ if params[:exclude_by_campaignid]
43
+ campaign_id = banner['campaignid']
44
+ context << convert_to_context(false, "campaignid:#{campaign_id}")
45
+ elsif params[:exclude_by_bannerid]
46
+ banner_id = banner['bannerid']
47
+ context << convert_to_context(false, "bannerid:#{banner_id}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ count > 1 ? out : out.first
53
+ end
54
+
55
+ def convert_to_context(is_inclusion, item)
56
+ key = is_inclusion ? '==' : '!='
57
+ { key => item }
58
+ end
59
+ protected :convert_to_context
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+
3
+ module OpenX
4
+ module Services
5
+ autoload :Persistance, 'openx/services/persistance'
6
+ autoload :Base, 'openx/services/base'
7
+ autoload :Session, 'openx/services/session'
8
+ autoload :Advertiser, 'openx/services/advertiser'
9
+ autoload :Agency, 'openx/services/agency'
10
+ autoload :Campaign, 'openx/services/campaign'
11
+ autoload :Banner, 'openx/services/banner'
12
+ autoload :Publisher, 'openx/services/publisher'
13
+ autoload :Zone, 'openx/services/zone'
14
+ autoload :Channel, 'openx/services/channel'
15
+ autoload :TargetingRule, 'openx/services/targeting_rule'
16
+ autoload :TargetingRules, 'openx/services/targeting_rules'
17
+
18
+ @@connection = nil
19
+
20
+ # Default connection
21
+ def self.default_connection
22
+ @@connection ||= establish_connection(OpenX.configuration)
23
+ end
24
+
25
+ def self.establish_connection(config)
26
+ connection = Session.new(config['url'])
27
+ connection.create config['username'], config['password']
28
+ connection
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module OpenX
2
+ module Services
3
+ class Advertiser < Base
4
+ openx_accessor :name => :advertiserName,
5
+ :contact_name => :contactName,
6
+ :email => :emailAddress,
7
+ :username => :username,
8
+ :password => :password,
9
+ :agency_id => :agencyId,
10
+ :id => :advertiserId
11
+
12
+ has_one :agency
13
+
14
+ self.create = 'ox.addAdvertiser'
15
+ self.update = 'ox.modifyAdvertiser'
16
+ self.delete = 'ox.deleteAdvertiser'
17
+ self.find_one = 'ox.getAdvertiser'
18
+ self.find_all = 'ox.getAdvertiserListByAgencyId'
19
+
20
+ def initialize(params = {})
21
+ raise "need agency" unless params[:agency_id] || params[:agency]
22
+ params[:agency_id] ||= params[:agency].id
23
+ super(params)
24
+ end
25
+
26
+ def campaigns
27
+ Campaign.find(:all, self.id)
28
+ end
29
+ end
30
+ end
31
+ end