bsm-openx 1.9.3 → 1.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.3
1
+ 1.9.4
@@ -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.3"
8
+ s.version = "1.9.4"
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-13}
12
+ s.date = %q{2010-09-14}
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 = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/openx.rb",
27
27
  "lib/openx/image.rb",
28
28
  "lib/openx/invocation.rb",
29
+ "lib/openx/persistance.rb",
29
30
  "lib/openx/services.rb",
30
31
  "lib/openx/services/advertiser.rb",
31
32
  "lib/openx/services/agency.rb",
@@ -33,12 +34,11 @@ Gem::Specification.new do |s|
33
34
  "lib/openx/services/base.rb",
34
35
  "lib/openx/services/campaign.rb",
35
36
  "lib/openx/services/channel.rb",
36
- "lib/openx/services/persistance.rb",
37
37
  "lib/openx/services/publisher.rb",
38
38
  "lib/openx/services/session.rb",
39
- "lib/openx/services/targeting_rule.rb",
40
- "lib/openx/services/targeting_rules.rb",
41
39
  "lib/openx/services/zone.rb",
40
+ "lib/openx/targeting_rule.rb",
41
+ "lib/openx/targeting_rules.rb",
42
42
  "lib/openx/xmlrpc_client.rb",
43
43
  "test/assets/300x250.jpg",
44
44
  "test/assets/cat.swf",
@@ -1,6 +1,9 @@
1
1
  module OpenX
2
+ autoload :Persistance, 'openx/persistance'
2
3
  autoload :Image, 'openx/image'
3
4
  autoload :Invocation, 'openx/invocation'
5
+ autoload :TargetingRule, 'openx/targeting_rule'
6
+ autoload :TargetingRules, 'openx/targeting_rules'
4
7
  autoload :Services, 'openx/services'
5
8
  autoload :XmlrpcClient, 'openx/xmlrpc_client'
6
9
  autoload :XmlrpcSessionClient, 'openx/xmlrpc_client'
@@ -0,0 +1,63 @@
1
+ module OpenX
2
+ module Persistance
3
+
4
+ module ClassMethods
5
+
6
+ def create!(params = {})
7
+ new(params).save!
8
+ end
9
+
10
+ def find(id, *args)
11
+ if id == :all
12
+ responses = remote.call(find_all, *args)
13
+ responses.map do |response|
14
+ new(translate(response))
15
+ end
16
+ else
17
+ response = remote.call(find_one, id)
18
+ new(translate(response))
19
+ end
20
+ end
21
+
22
+ def destroy(id)
23
+ new(:id => id).destroy
24
+ end
25
+
26
+ private
27
+
28
+ def translate(response)
29
+ params = {}
30
+ self.translations.each do |k,v|
31
+ params[k] = response[v.to_s] if response[v.to_s]
32
+ end
33
+ params
34
+ end
35
+
36
+ end
37
+
38
+ module InstanceMethods
39
+
40
+ def save!
41
+ params = {}
42
+ self.class.translations.keys.each do |k|
43
+ value = send(:"#{k}")
44
+ params[self.class.translations[k].to_s] = value if value
45
+ end
46
+
47
+ if new_record?
48
+ @id = remote.call(self.class.create, params)
49
+ else
50
+ remote.call(self.class.update, params)
51
+ end
52
+ self
53
+ end
54
+
55
+ def destroy
56
+ remote.call(self.class.delete, id)
57
+ @id = nil
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -2,7 +2,6 @@ require 'yaml'
2
2
 
3
3
  module OpenX
4
4
  module Services
5
- autoload :Persistance, 'openx/services/persistance'
6
5
  autoload :Base, 'openx/services/base'
7
6
  autoload :Session, 'openx/services/session'
8
7
  autoload :Advertiser, 'openx/services/advertiser'
@@ -12,8 +11,6 @@ module OpenX
12
11
  autoload :Publisher, 'openx/services/publisher'
13
12
  autoload :Zone, 'openx/services/zone'
14
13
  autoload :Channel, 'openx/services/channel'
15
- autoload :TargetingRule, 'openx/services/targeting_rule'
16
- autoload :TargetingRules, 'openx/services/targeting_rules'
17
14
 
18
15
  @@connection = nil
19
16
 
@@ -81,12 +81,14 @@ module OpenX
81
81
  end
82
82
 
83
83
  def targeting
84
- remote.call('ox.getBannerTargeting', self.id) do |line|
84
+ raise "Banner must be saved" if new_record?
85
+ remote.call('ox.getBannerTargeting', self.id).map do |line|
85
86
  TargetingRule.instantiate(line)
86
87
  end
87
88
  end
88
89
 
89
90
  def targeting=(rules)
91
+ raise "Banner must be saved" if new_record?
90
92
  remote.call('ox.setBannerTargeting', self.id, rules)
91
93
  end
92
94
  end
@@ -31,7 +31,7 @@ module OpenX
31
31
  end
32
32
  end
33
33
 
34
- # Applied targeting to channel. See OpenX::Services::TargetingRules for details
34
+ # Applied targeting to channel. See OpenX::TargetingRules for details
35
35
  def targeting=(rules)
36
36
  raise "Channel must be saved" if new_record?
37
37
  remote.call("ox.setChannelTargeting", self.id, rules)
@@ -0,0 +1,121 @@
1
+ module OpenX
2
+ class TargetingRule < Hash
3
+ TYPES = {
4
+ 'Client' => %w(Browser Domain Ip Language Os Useragent),
5
+ 'Geo' => %w(Areacode City Continent Country Dma Latlong Netspeed Organisation Postalcode Region),
6
+ 'Site' => %w(Channel Pageurl Referingpage Source Variable),
7
+ 'Time' => %w(Date Day Hour)
8
+ }.freeze
9
+
10
+ DATA_KEYS = ['comparison', 'data', 'logical'].freeze
11
+ ALL_KEYS = (DATA_KEYS + ['type']).freeze
12
+
13
+ attr_reader :type
14
+
15
+ def self.instantiate(hash)
16
+ rule = new(hash['type'])
17
+ DATA_KEYS.each {|k| rule.update k => hash[k] }
18
+ rule
19
+ end
20
+
21
+ def initialize(type)
22
+ super().update('type' => verify_type(type), 'logical' => 'and')
23
+ end
24
+
25
+ def equal?(value)
26
+ update 'comparison' => '==', 'data' => convert(value)
27
+ end
28
+ alias_method :eq?, :equal?
29
+ alias_method :is?, :equal?
30
+
31
+ def not_equal?(value)
32
+ update 'comparison' => '!=', 'data' => convert(value)
33
+ end
34
+ alias_method :ne?, :not_equal?
35
+ alias_method :not?, :not_equal?
36
+
37
+ def lt?(value)
38
+ update 'comparison' => '<', 'data' => convert(value)
39
+ end
40
+ alias_method :<, :lt?
41
+
42
+ def gt?(value)
43
+ update 'comparison' => '>', 'data' => convert(value)
44
+ end
45
+ alias_method :>, :gt?
46
+
47
+ def lte?(value)
48
+ update 'comparison' => '<=', 'data' => convert(value)
49
+ end
50
+ alias_method :<=, :lte?
51
+
52
+ def gte?(value)
53
+ update 'comparison' => '>=', 'data' => convert(value)
54
+ end
55
+ alias_method :>=, :gte?
56
+
57
+ def match?(value)
58
+ update 'comparison' => '=x', 'data' => convert(value)
59
+ end
60
+ alias_method :=~, :match?
61
+
62
+ def &(other)
63
+ other.logical('and')
64
+ end
65
+
66
+ def |(other)
67
+ other.logical('or')
68
+ end
69
+
70
+ def no_match?(value)
71
+ update 'comparison' => '!x', 'data' => convert(value)
72
+ end
73
+
74
+ def include?(*values)
75
+ update 'comparison' => '=~', 'data' => convert(values)
76
+ end
77
+ alias_method :contains?, :include?
78
+
79
+ def exclude?(*values)
80
+ update 'comparison' => '!~', 'data' => convert(values)
81
+ end
82
+ alias_method :does_not_contain?, :exclude?
83
+
84
+ def with(value)
85
+ update 'data' => convert(value)
86
+ end
87
+
88
+ def compare(value)
89
+ update 'comparison' => value
90
+ end
91
+
92
+ def logical(value)
93
+ value = value.to_s
94
+ update 'logical' => (value == 'or' ? value : 'and')
95
+ end
96
+
97
+ def complete?
98
+ values_at(*ALL_KEYS).all? {|v| !v.nil? }
99
+ end
100
+
101
+ private
102
+
103
+ def verify_type(type)
104
+ group, component = type.to_s.split(':').last(2)
105
+ raise "Invalid type '#{self['type']}'" unless TYPES.key?(group) && TYPES[group].include?(component)
106
+ "#{group}:#{component}"
107
+ end
108
+
109
+ def convert(value)
110
+ case value
111
+ when Array
112
+ value.map {|v| convert(v) }.join(',')
113
+ when Regexp
114
+ value.source
115
+ else
116
+ value.to_s
117
+ end
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,24 @@
1
+ module OpenX
2
+
3
+ # Create targeting rule sets. Example:
4
+ #
5
+ # rules = OpenX::TargetingRules.new do |t|
6
+ # t['Site:Pageurl'].include?('test') &
7
+ # t['Client:Ip'].match?(/^127\./) |
8
+ # t['Geo:Country'].include?('GB', 'US')
9
+ # end
10
+ class TargetingRules < Array
11
+
12
+ def initialize(&block)
13
+ super([])
14
+ block.call(self)
15
+ end
16
+
17
+ def [](key)
18
+ rule = TargetingRule.new(key)
19
+ push(rule)
20
+ rule
21
+ end
22
+
23
+ end
24
+ end
@@ -25,8 +25,8 @@ module OpenX
25
25
  Advertiser = OpenX::Services::Advertiser
26
26
  Session = OpenX::Services::Session
27
27
  Channel = OpenX::Services::Channel
28
- TargetingRule = OpenX::Services::TargetingRule
29
- TargetingRules = OpenX::Services::TargetingRules
28
+ TargetingRule = OpenX::TargetingRule
29
+ TargetingRules = OpenX::TargetingRules
30
30
 
31
31
  undef :default_test
32
32
 
@@ -110,7 +110,7 @@ module OpenX
110
110
  end
111
111
 
112
112
  def targeting_rules
113
- @targeting_rules ||= OpenX::Services::TargetingRules.new do |t|
113
+ @targeting_rules ||= OpenX::TargetingRules.new do |t|
114
114
  t['Site:Pageurl'].include?('test') &
115
115
  t['Client:Ip'].match?(/^127\./) |
116
116
  t['Geo:Country'].include?('GB', 'US')
@@ -41,7 +41,6 @@ class TargetingRuleTest < OpenX::TestCase
41
41
  end
42
42
 
43
43
  test "comparisons" do
44
- assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule == 'GB|H9')
45
44
  assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.eq?('GB|H9'))
46
45
  assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.equal?('GB|H9'))
47
46
  assert_equal({"logical"=>"and", "type"=>"Geo:Region", "comparison"=>"==", "data" => "GB|H9"}, new_rule.is?('GB|H9'))
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: 53
4
+ hash: 59
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 3
10
- version: 1.9.3
9
+ - 4
10
+ version: 1.9.4
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-13 00:00:00 +01:00
21
+ date: 2010-09-14 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies: []
24
24
 
@@ -41,6 +41,7 @@ files:
41
41
  - lib/openx.rb
42
42
  - lib/openx/image.rb
43
43
  - lib/openx/invocation.rb
44
+ - lib/openx/persistance.rb
44
45
  - lib/openx/services.rb
45
46
  - lib/openx/services/advertiser.rb
46
47
  - lib/openx/services/agency.rb
@@ -48,12 +49,11 @@ files:
48
49
  - lib/openx/services/base.rb
49
50
  - lib/openx/services/campaign.rb
50
51
  - lib/openx/services/channel.rb
51
- - lib/openx/services/persistance.rb
52
52
  - lib/openx/services/publisher.rb
53
53
  - lib/openx/services/session.rb
54
- - lib/openx/services/targeting_rule.rb
55
- - lib/openx/services/targeting_rules.rb
56
54
  - lib/openx/services/zone.rb
55
+ - lib/openx/targeting_rule.rb
56
+ - lib/openx/targeting_rules.rb
57
57
  - lib/openx/xmlrpc_client.rb
58
58
  - test/assets/300x250.jpg
59
59
  - test/assets/cat.swf
@@ -1,64 +0,0 @@
1
- module OpenX
2
- module Services
3
- module Persistance
4
-
5
- module ClassMethods
6
-
7
- def create!(params = {})
8
- new(params).save!
9
- end
10
-
11
- def find(id, *args)
12
- if id == :all
13
- responses = remote.call(find_all, *args)
14
- responses.map do |response|
15
- new(translate(response))
16
- end
17
- else
18
- response = remote.call(find_one, id)
19
- new(translate(response))
20
- end
21
- end
22
-
23
- def destroy(id)
24
- new(:id => id).destroy
25
- end
26
-
27
- private
28
-
29
- def translate(response)
30
- params = {}
31
- self.translations.each do |k,v|
32
- params[k] = response[v.to_s] if response[v.to_s]
33
- end
34
- params
35
- end
36
-
37
- end
38
-
39
- module InstanceMethods
40
-
41
- def save!
42
- params = {}
43
- self.class.translations.keys.each do |k|
44
- value = send(:"#{k}")
45
- params[self.class.translations[k].to_s] = value if value
46
- end
47
-
48
- if new_record?
49
- @id = remote.call(self.class.create, params)
50
- else
51
- remote.call(self.class.update, params)
52
- end
53
- self
54
- end
55
-
56
- def destroy
57
- remote.call(self.class.delete, id)
58
- @id = nil
59
- end
60
-
61
- end
62
- end
63
- end
64
- end
@@ -1,125 +0,0 @@
1
- module OpenX
2
- module Services
3
-
4
- class TargetingRule < Hash
5
- TYPES = {
6
- 'Client' => %w(Browser Domain Ip Language Os Useragent),
7
- 'Geo' => %w(Areacode City Continent Country Dma Latlong Netspeed Organisation Postalcode Region),
8
- 'Site' => %w(Channel Pageurl Referingpage Source Variable),
9
- 'Time' => %w(Date Day Hour)
10
- }.freeze
11
-
12
- DATA_KEYS = ['comparison', 'data', 'logical'].freeze
13
- ALL_KEYS = (DATA_KEYS + ['type']).freeze
14
-
15
- attr_reader :type
16
-
17
- def self.instantiate(hash)
18
- rule = new(hash['type'])
19
- DATA_KEYS.each {|k| rule.update k => hash[k] }
20
- rule
21
- end
22
-
23
- def initialize(type)
24
- super().update('type' => verify_type(type), 'logical' => 'and')
25
- end
26
-
27
- def equal?(value)
28
- update 'comparison' => '==', 'data' => convert(value)
29
- end
30
- alias_method :eq?, :equal?
31
- alias_method :is?, :equal?
32
- alias_method :==, :equal?
33
-
34
- def not_equal?(value)
35
- update 'comparison' => '!=', 'data' => convert(value)
36
- end
37
- alias_method :ne?, :not_equal?
38
- alias_method :not?, :not_equal?
39
-
40
- def lt?(value)
41
- update 'comparison' => '<', 'data' => convert(value)
42
- end
43
- alias_method :<, :lt?
44
-
45
- def gt?(value)
46
- update 'comparison' => '>', 'data' => convert(value)
47
- end
48
- alias_method :>, :gt?
49
-
50
- def lte?(value)
51
- update 'comparison' => '<=', 'data' => convert(value)
52
- end
53
- alias_method :<=, :lte?
54
-
55
- def gte?(value)
56
- update 'comparison' => '>=', 'data' => convert(value)
57
- end
58
- alias_method :>=, :gte?
59
-
60
- def match?(value)
61
- update 'comparison' => '=x', 'data' => convert(value)
62
- end
63
- alias_method :=~, :match?
64
-
65
- def &(other)
66
- other.logical('and')
67
- end
68
-
69
- def |(other)
70
- other.logical('or')
71
- end
72
-
73
- def no_match?(value)
74
- update 'comparison' => '!x', 'data' => convert(value)
75
- end
76
-
77
- def include?(*values)
78
- update 'comparison' => '=~', 'data' => convert(values)
79
- end
80
- alias_method :contains?, :include?
81
-
82
- def exclude?(*values)
83
- update 'comparison' => '!~', 'data' => convert(values)
84
- end
85
- alias_method :does_not_contain?, :exclude?
86
-
87
- def with(value)
88
- update 'data' => convert(value)
89
- end
90
-
91
- def compare(value)
92
- update 'comparison' => value
93
- end
94
-
95
- def logical(value)
96
- value = value.to_s
97
- update 'logical' => (value == 'or' ? value : 'and')
98
- end
99
-
100
- def complete?
101
- values_at(*ALL_KEYS).all? {|v| !v.nil? }
102
- end
103
-
104
- private
105
-
106
- def verify_type(type)
107
- group, component = type.to_s.split(':').last(2)
108
- raise "Invalid type '#{self['type']}'" unless TYPES.key?(group) && TYPES[group].include?(component)
109
- "#{group}:#{component}"
110
- end
111
-
112
- def convert(value)
113
- case value
114
- when Array
115
- value.map {|v| convert(v) }.join(',')
116
- when Regexp
117
- value.source
118
- else
119
- value.to_s
120
- end
121
- end
122
-
123
- end
124
- end
125
- end
@@ -1,26 +0,0 @@
1
- module OpenX
2
- module Services
3
-
4
- # Create targeting rule sets. Example:
5
- #
6
- # rules = OpenX::Services::TargetingRules.new do |t|
7
- # t['Site:Pageurl'].include?('test') &
8
- # t['Client:Ip'].match?(/^127\./) |
9
- # t['Geo:Country'].include?('GB', 'US')
10
- # end
11
- class TargetingRules < Array
12
-
13
- def initialize(&block)
14
- super([])
15
- block.call(self)
16
- end
17
-
18
- def [](key)
19
- rule = TargetingRule.new(key)
20
- push(rule)
21
- rule
22
- end
23
-
24
- end
25
- end
26
- end