class Pop

Attributes

background_image_asset_id[RW]
collaboration_interstitial_text[RW]
collaboration_webhook[RW]
custom_code[RW]
domain[RW]
label_names[RW]
name[RW]
newly_populated_regions[R]
newly_populated_tags[R]
password[RW]
published_pop_url[RW]
slug[RW]
template_id[RW]
title[RW]
tracers[RW]
unpopulated_api_regions[RW]
unpopulated_api_tags[RW]

Public Class Methods

new(parent) click to toggle source
# File lib/pop.rb, line 33
def initialize(parent)
  if parent.is_a?(Template)
    @_api = parent.instance_variable_get :@_api
    self.template_id = parent._id
    self.title = parent.title
    self.name = parent.name
    self.domain = parent.domain
    self.password = parent.password
    self.label_names = parent.label_names.dup if parent.label_names
    self.background_image_asset_id = parent.background_image_asset_id
    self.unpopulated_api_regions = parent.api_regions.dup
    self.unpopulated_api_tags = parent.api_tags.dup
    self.custom_code = parent.custom_code
    self.custom_links = parent.custom_links.dup if parent.custom_links

  elsif parent.is_a?(RestfulModelCollection)
    @_api = parent.instance_variable_get :@_api

  elsif parent.is_a?(Populr)
    @_api = parent
  else
    raise "You must create a pop with a template, collection, or API model."
  end

  # We could choose to make parent the restfulModelCollection that is passed to us,
  # but that would result in PUTs and POSTs to /templates/:id/pops, which isn't
  # how the API is currently set up. For now, all pop PUTS, POSTs, etc... go to /pops/
  @_parent = @_api.pops

  @newly_populated_regions = {}
  @newly_populated_tags = {}
end

Public Instance Methods

analytics() click to toggle source
# File lib/pop.rb, line 150
def analytics
  analytics = nil
  action_url = @_api.url_for_path(self.path('analytics'))
  RestClient.send('get', action_url){ |response,request,result|
    analytics = Populr.interpret_response(result, response, {:expected_class => Object})
  }
  analytics
end
as_json(options = {}) click to toggle source
Calls superclass method RestfulModel#as_json
# File lib/pop.rb, line 73
def as_json(options = {})
  raise TemplateRequired.new if options[:api_representation] && !template_id

  if options[:api_representation]
    hash = {}
    hash[:pop] = super(options)
    hash[:populate_tags] = @newly_populated_tags
    hash[:populate_regions] = @newly_populated_regions
    hash
  else
    super(options)
  end
end
disable_cloning() click to toggle source
# File lib/pop.rb, line 116
def disable_cloning
  self.clone_link_enabled = false
  self.clone_link_url = nil # doesn't get saed, just for developer interface
end
disable_collaboration() click to toggle source
# File lib/pop.rb, line 106
def disable_collaboration
  self.collaboration_link_enabled = false
  self.collaboration_link_url = nil
end
edit_url() click to toggle source
# File lib/pop.rb, line 95
def edit_url
  return @_api.api_server.gsub('api.', 'www.') + "/edit/#{_id}"
end
enable_cloning!() click to toggle source
# File lib/pop.rb, line 111
def enable_cloning!
  self.clone_link_enabled = true
  save! # go and populate our model with the clone link
end
enable_collaboration!(interstitial_text = '', webhook = nil) click to toggle source
# File lib/pop.rb, line 99
def enable_collaboration!(interstitial_text = '', webhook = nil)
  self.collaboration_link_enabled = true
  self.collaboration_webhook = webhook
  self.collaboration_interstitial_text = interstitial_text
  save! # go and populate our model with the collaboration link
end
has_unpopulated_region(region_identifier) click to toggle source
# File lib/pop.rb, line 121
def has_unpopulated_region(region_identifier)
  unpopulated_api_regions.include?(region_identifier)
end
has_unpopulated_tag(tag_identifier) click to toggle source
# File lib/pop.rb, line 141
def has_unpopulated_tag(tag_identifier)
  unpopulated_api_tags.include?(tag_identifier)
end
inflate(json) click to toggle source
Calls superclass method RestfulModel#inflate
# File lib/pop.rb, line 66
def inflate(json)
  super(json)
  self.tracers = RestfulModelCollection.new(Tracer, @_api, self)
  @newly_populated_regions = {}
  @newly_populated_tags = {}
end
populate_region(region_identifier, assets) click to toggle source
# File lib/pop.rb, line 130
def populate_region(region_identifier, assets)
  assets = [assets] unless assets.is_a?(Array)

  @newly_populated_regions[region_identifier] ||= []
  @newly_populated_regions[region_identifier].concat(assets.map {|a|
    raise AssetMustBeSaved.new unless a._id
    a._id
  })
  unpopulated_api_regions.delete(region_identifier)
end
populate_tag(tag_identifier, tag_contents) click to toggle source
# File lib/pop.rb, line 145
def populate_tag(tag_identifier, tag_contents)
  @newly_populated_tags[tag_identifier] = tag_contents
  unpopulated_api_tags.delete(tag_identifier)
end
publish!() click to toggle source
# File lib/pop.rb, line 87
def publish!
  update('POST', 'publish')
end
type_of_unpopulated_region(region_identifier) click to toggle source
# File lib/pop.rb, line 125
def type_of_unpopulated_region(region_identifier)
  return false unless has_unpopulated_region(region_identifier)
  unpopulated_api_regions[region_identifier]['type']
end
unpublish!() click to toggle source
# File lib/pop.rb, line 91
def unpublish!
  update('POST', 'unpublish')
end