Class: OpenX::Services::Banner

Inherits:
Base
  • Object
show all
Includes:
Statistics
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

Constants inherited from Base

OpenX::Services::Base::CONFIGURATION_YAML

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Statistics

#get_statistics

Methods inherited from Base

#<=>, configuration, configuration=, connection, connection=, create!, destroy, #destroy, has_one, #new_record?, openx_accessor, #save!

Constructor Details

#initialize(params = {}) ⇒ Banner

Returns a new instance of Banner.

Raises:

  • (ArgumentError)


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

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openx/services/banner.rb', line 20

def find(id, *args)
  session   = self.connection
  server    = XmlrpcClient.new2("#{session.url}")
  if id == :all
    responses = server.call(find_all(), session, *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 { |response|
      new(translate(response))
    }
  else
    response  = server.call(find_one(), session, id)
    new(translate(response))
  end
end

Instance Method Details

#daily_statistics(start_on = Date.today, end_on = Date.today, local_time_zone = true) ⇒ Object

Returns statistics in Array of Hashes by day, which are: impressions, clicks, requests and revenue. Each day is represented by XMLRPC::DateTime which has instant variables: @year, @month, @day, @hour, @min, @sec



93
94
95
# File 'lib/openx/services/banner.rb', line 93

def daily_statistics start_on = Date.today, end_on = Date.today, local_time_zone = true
  self.get_statistics('ox.bannerDailyStatistics', start_on, end_on, local_time_zone)
end

#publisher_statistics(start_on = Date.today, end_on = Date.today, local_time_zone = true) ⇒ Object

Returns statistics in Array of Hashes by publisher, which are: impression, clicks, requests and revenue. Also returns publisherName and publisherId



99
100
101
# File 'lib/openx/services/banner.rb', line 99

def publisher_statistics start_on = Date.today, end_on = Date.today, local_time_zone = true
  self.get_statistics('ox.bannerPublisherStatistics', start_on, end_on, local_time_zone)
end

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

Alias for daily_statistics method to keep consistency with OpenX API calls. Originally it was call for ox.bannerDailyStatistics so it is kept for compatibility with the previous version of the gem.



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

def statistics start_on = Date.today, end_on = Date.today, local_time_zone = true
  daily_statistics start_on, end_on, local_time_zone
end

#targetingObject



109
110
111
112
# File 'lib/openx/services/banner.rb', line 109

def targeting
  session = self.class.connection
  @server.call('ox.getBannerTargeting', session, self.id)
end

#targeting=(targeting) ⇒ Object



114
115
116
117
# File 'lib/openx/services/banner.rb', line 114

def targeting= targeting
  session = self.class.connection
  @server.call('ox.setBannerTargeting', session, self.id, targeting)
end

#zone_statistics(start_on = Date.today, end_on = Date.today, local_time_zone = true) ⇒ Object

Returns statistics in Array of Hashes by zone, which are: impression, clicks, requests, conversions and revenue. Also returns publisherName, publisherId, zoneName, zoneId



105
106
107
# File 'lib/openx/services/banner.rb', line 105

def zone_statistics start_on = Date.today, end_on = Date.today, local_time_zone = true
  self.get_statistics('ox.bannerZoneStatistics', start_on, end_on, local_time_zone)
end