Class: OpenX::Services::Banner

Inherits:
Base
  • Object
show all
Defined in:
lib/openx/services/banner.rb

Constant Summary collapse

LOCAL_SQL =
'sql'
LOCAL_WEB =
'web'
EXTERNAL =
'url'
HTML =
'html'
TEXT =
'txt'
RUNNING =
0
PAUSED =
1

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, establish_connection, has_one, #new_record?, openx_accessor, remote, with_connection

Methods included from Persistance::ClassMethods

#create!, #destroy, #find

Methods included from Persistance::InstanceMethods

#destroy, #save!

Constructor Details

#initialize(params = {}) ⇒ Banner

Returns a new instance of Banner.

Raises:

  • (ArgumentError)


73
74
75
76
77
# File 'lib/openx/services/banner.rb', line 73

def initialize(params = {})
  raise ArgumentError.new("Missing campaign_id") unless params[:campaign_id] || params[:campaign]
  params[:campaign_id] ||= params[:campaign].id
  super(params)
end

Class Method Details

.find(id, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openx/services/banner.rb', line 16

def find(id, *args)
  if id == :all
    responses = remote.call(find_all, *args)
    response  = responses.first
    return [] unless response
    responses = [response]

    ### Annoying..  For some reason OpenX returns a linked list.
    ### Probably a bug....
    while response.key?('aImage')
      response = response.delete('aImage')
      break unless response
      responses << response
    end

    responses.map do |response|
      new(translate(response))
    end
  else
    response  = remote.call(find_one, id)
    new(translate(response))
  end
end

Instance Method Details

#statistics(start_on = Date.today, end_on = Date.today) ⇒ Object



79
80
81
# File 'lib/openx/services/banner.rb', line 79

def statistics start_on = Date.today, end_on = Date.today
  remote.call('ox.bannerDailyStatistics', self.id, start_on, end_on)
end

#targetingObject



83
84
85
86
87
88
# File 'lib/openx/services/banner.rb', line 83

def targeting
  raise "Banner must be saved" if new_record?
  remote.call('ox.getBannerTargeting', self.id).map do |line|
    TargetingRule.instantiate(line)
  end
end

#targeting=(rules) ⇒ Object



90
91
92
93
# File 'lib/openx/services/banner.rb', line 90

def targeting=(rules)
  raise "Banner must be saved" if new_record?
  remote.call('ox.setBannerTargeting', self.id, rules)
end