Class: Neuron::Client::Ad
Constant Summary
collapse
- ACTIVE_TTL =
60
- PRESSURE_TTL =
60
- REDIRECT =
'Redirect'
- VIDEO_AD =
'VideoAd'
- VAST_NETWORK =
'VastNetwork'
- ACUDEO_NETWORK =
'AcudeoNetwork'
- RESPONSE_TYPES =
[REDIRECT, VIDEO_AD, VAST_NETWORK, ACUDEO_NETWORK]
- SOCIAL_TYPES =
%w(facebook googleplus twitter youtube)
- TIME_ZONES =
ActiveSupport::TimeZone.all.collect{|tz| tz.name }
- FREQUENCY_CAP_WINDOWS =
%w(Day Hour)
- VAST_TRACKER_TYPES =
%w(impression clickTracking firstQuartile midpoint thirdQuartile complete)
- ATTRIBUTES =
[
:id, :approved, :daily_cap, :day_partitions, :end_datetime, :frequency_cap, :geo_target_netacuity_ids, :ideal_impressions_per_hour, :name, :overall_cap, :pixel_ids, :response_type, :start_datetime, :time_zone, :zone_links,
:created_at, :updated_at,
:today_impressed, :total_impressed,
:redirect_url,
:video_flv_url, :clickthru_url, :companion_ad_html, :social_urls, :vast_tracker_urls,
:vast_url,
:acudeo_program_id, ]
- STATISTIC_TYPES =
%w(selections undeliveries impressions redirects clicks)
Instance Method Summary
collapse
#calculate_active?, #calculate_pressure
Methods included from Base
#apply_attributes!, #destroy, #id=, included, #initialize, #new_record?, #save, #to_hash, #update_attributes, #valid?
#all, #api=, #create, #create!, #find, #validate=
Instance Method Details
#active? ⇒ Boolean
124
125
126
127
128
129
130
131
132
|
# File 'lib/neuron-client/model/ad.rb', line 124
def active?
if connected_to_membase?
connection.fetch("Ad:#{id}:active", ACTIVE_TTL) do
calculate_active?(Time.now, total_impressed, today_impressed)
end
else
calculate_active?(Time.now, total_impressed, today_impressed)
end
end
|
#attributes ⇒ Object
65
66
67
|
# File 'lib/neuron-client/model/ad.rb', line 65
def attributes
ATTRIBUTES
end
|
134
135
136
137
138
139
140
141
142
|
# File 'lib/neuron-client/model/ad.rb', line 134
def pressure
if connected_to_membase?
connection.fetch("Ad:#{id}:pressure", PRESSURE_TTL) do
calculate_pressure(Time.now, total_impressed, today_impressed)
end
else
calculate_pressure(Time.now, total_impressed, today_impressed)
end
end
|
#recent(statistic, parameters = {}) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/neuron-client/model/ad.rb', line 71
def recent(statistic, parameters={})
connected_to_admin!
by = (parameters[:by] || parameters['by']).to_s
minutes = parameters[:minutes] || parameters['minutes']
group_by = parameters[:group_by] || parameters['group_by']
parameters = {}
parameters['by'] = by unless by.blank?
parameters['minutes'] = minutes.to_i if minutes.to_i > 0
parameters['group_by'] = group_by.to_s unless group_by.blank?
if validate?
unless STATISTIC_TYPES.include?(statistic.to_s)
raise "Unsupported statistic: #{statistic}"
end
unless by.blank? || by == 'zone'
raise "Unsupported by: #{by}"
end
unless minutes.blank? || minutes.to_i > 0
raise "Unsupported minutes: #{minutes}"
end
unless group_by.blank? || group_by == 'hour'
raise "Unsupported group_by: #{group_by}"
end
end
connection.get("ads/#{id}/recent/#{statistic}", parameters)
end
|
#today_impressed ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/neuron-client/model/ad.rb', line 113
def today_impressed
if connected_to_membase?
now_adjusted_for_ad_time_zone = Time.now.in_time_zone(self.time_zone)
formatted_date = now_adjusted_for_ad_time_zone.strftime('%Y%m%d') key = "count_delivery_#{formatted_date}_ad_#{id}"
connection.get(key,1).to_f
else
@today_impressed || 0
end
end
|
#total_impressed ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/neuron-client/model/ad.rb', line 104
def total_impressed
if connected_to_membase?
key = "count_delivery_ad_#{id}"
connection.get(key,1).to_f
else
@total_impressed || 0
end
end
|
#unlink(zone_id) ⇒ Object
98
99
100
101
102
|
# File 'lib/neuron-client/model/ad.rb', line 98
def unlink(zone_id)
connected_to_admin!
validate_uuid!(zone_id)
connection.delete("ads/#{id}/zones/#{zone_id}")
end
|