Class: Neuron::Client::Zone

Inherits:
Object show all
Includes:
Base, ZoneCalculations
Defined in:
lib/neuron-client/model/zone.rb

Constant Summary collapse

ADS_BY_PRIORITY_TTL =

seconds

60
REDIRECT =
"Redirect"
IRIS =
"Iris"
VAST =
"Vast"
RESPONSE_TYPES =
[REDIRECT, IRIS, VAST]
IRIS_2_0 =
'2_0'
IRIS_2_5 =
'2_5'
IRIS_VERSIONS =
[IRIS_2_0, IRIS_2_5]
TEMPLATE_SLUGS =
['300x250']
PLAYLIST_MODES =
['MAXI', 'MINI']
PLAYBACK_MODE_OPTIONS =
[['Auto Play', 'AUTO'], ['Click To Play','CTP'], ['Rollover To Play', 'RTP']]
PLAYBACK_MODES =
Hash[PLAYBACK_MODE_OPTIONS].values
OVERLAY_PROVIDERS =
['NAMI', 'PREDICTV']
ATTRIBUTES =
[
  :id,
  :ad_links,
  :name,
  :response_type, # string in RESPONSE_TYPES
  :template_slug, # nil, or string in TEMPLATE_SLUGS
  :channel,       # nil, or slug
  :expand,        # nil, or "Yes" or "No"
  :iris_version,  # nil, or string in IRIS_VERSIONS
  # Iris 2.0
  :mute,          # nil, or "Yes" or "No"
  :autoplay,      # nil, or "Yes" or "No"
  # Iris 2.5
  :playlist_mode, # nil, or string in PLAYLIST_MODES
  :volume,        # nil, or 1-100s
  :color,         # nil, or string (hex color - '333333')
  :playback_mode, # nil, or string in PLAYBACK_MODES
  :overlay_provider, # nil, or string in OVERLAY_PROVIDERS
  :overlay_feed_url, # nil, or string URL

  :created_at,    # string, datetime in UTC
  :updated_at,    # string, datetime in UTC
]
STATISTIC_TYPES =
{
  'requests' => [],
  'blocks' => ['reason'],
  'defaults' => [],
  'unitloads' => [],
  'selections' => ['ad'],
  'undeliveries' => ['ad'],
  'impressions' => ['ad'],
  'redirects' => ['ad'],
  'clicks' => ['ad']
}

Instance Method Summary collapse

Methods included from ZoneCalculations

#calculate_ads_by_priority

Methods included from Base

#apply_attributes!, #destroy, included, #initialize, #new_record?, #save, #to_create_hash, #to_hash, #to_update_hash, #update_attributes, #valid?

Methods included from Base::ClassAndInstanceMethods

#all, #api=, #create, #create!, #find, #validate=

Instance Method Details

#ads_by_priorityObject



107
108
109
110
111
112
113
114
115
# File 'lib/neuron-client/model/zone.rb', line 107

def ads_by_priority
  if connected_to_membase?
    connection.fetch("Zone:#{id}:ads_by_priority", ADS_BY_PRIORITY_TTL) do
      calculate_ads_by_priority
    end
  else
    calculate_ads_by_priority
  end
end

#attributesObject



49
50
51
# File 'lib/neuron-client/model/zone.rb', line 49

def attributes
  ATTRIBUTES
end

#find_ad(ad_id) ⇒ Object



57
58
59
# File 'lib/neuron-client/model/zone.rb', line 57

def find_ad(ad_id)
  Ad.find(ad_id)
end

#id=(id) ⇒ Object



53
54
55
# File 'lib/neuron-client/model/zone.rb', line 53

def id=(id)
  @id = id.to_s
end

#recent(statistic, parameters = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/neuron-client/model/zone.rb', line 73

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? || STATISTIC_TYPES[statistic.to_s].include?(by.to_s)
      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("zones/#{id}/recent/#{statistic}", parameters)
end


100
101
102
103
104
105
# File 'lib/neuron-client/model/zone.rb', line 100

def unlink(ad_id)
  connected_to_admin!
  validate_id!(ad_id)
  validate_uuid!(id)
  connection.delete("zones/#{id}/ads/#{ad_id}")
end