Class: Pop
- Inherits:
-
RestfulModel
- Object
- RestfulModel
- Pop
- Defined in:
- lib/pop.rb
Defined Under Namespace
Classes: AssetMustBeSaved, TemplateRequired
Instance Attribute Summary collapse
-
#background_image_asset_id ⇒ Object
Returns the value of attribute background_image_asset_id.
-
#clone_link_enabled ⇒ Object
Returns the value of attribute clone_link_enabled.
-
#clone_link_url ⇒ Object
Returns the value of attribute clone_link_url.
-
#collaboration_interstitial_text ⇒ Object
Returns the value of attribute collaboration_interstitial_text.
-
#collaboration_link_enabled ⇒ Object
Returns the value of attribute collaboration_link_enabled.
-
#collaboration_link_url ⇒ Object
Returns the value of attribute collaboration_link_url.
-
#collaboration_webhook ⇒ Object
Returns the value of attribute collaboration_webhook.
-
#custom_code ⇒ Object
Returns the value of attribute custom_code.
-
#custom_links ⇒ Object
Returns the value of attribute custom_links.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#label_names ⇒ Object
Returns the value of attribute label_names.
-
#name ⇒ Object
Returns the value of attribute name.
-
#newly_populated_regions ⇒ Object
readonly
Returns the value of attribute newly_populated_regions.
-
#newly_populated_tags ⇒ Object
readonly
Returns the value of attribute newly_populated_tags.
-
#password ⇒ Object
Returns the value of attribute password.
-
#published_pop_url ⇒ Object
Returns the value of attribute published_pop_url.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tracers ⇒ Object
Returns the value of attribute tracers.
-
#unpopulated_api_regions ⇒ Object
Returns the value of attribute unpopulated_api_regions.
-
#unpopulated_api_tags ⇒ Object
Returns the value of attribute unpopulated_api_tags.
Attributes inherited from RestfulModel
Instance Method Summary collapse
- #analytics ⇒ Object
- #as_json(options = {}) ⇒ Object
- #disable_cloning ⇒ Object
- #disable_collaboration ⇒ Object
- #edit_url ⇒ Object
- #enable_cloning! ⇒ Object
- #enable_collaboration!(interstitial_text = '', webhook = nil) ⇒ Object
- #has_unpopulated_region(region_identifier) ⇒ Object
- #has_unpopulated_tag(tag_identifier) ⇒ Object
- #inflate(json) ⇒ Object
-
#initialize(parent) ⇒ Pop
constructor
A new instance of Pop.
- #populate_region(region_identifier, assets) ⇒ Object
- #populate_tag(tag_identifier, tag_contents) ⇒ Object
- #publish! ⇒ Object
- #type_of_unpopulated_region(region_identifier) ⇒ Object
- #unpublish! ⇒ Object
Methods inherited from RestfulModel
#==, collection_name, #destroy, #path, #save!, #update
Constructor Details
#initialize(parent) ⇒ Pop
Returns a new instance of Pop.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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. = parent..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 |
Instance Attribute Details
#background_image_asset_id ⇒ Object
Returns the value of attribute background_image_asset_id.
26 27 28 |
# File 'lib/pop.rb', line 26 def background_image_asset_id @background_image_asset_id end |
#clone_link_enabled ⇒ Object
Returns the value of attribute clone_link_enabled.
20 21 22 |
# File 'lib/pop.rb', line 20 def clone_link_enabled @clone_link_enabled end |
#clone_link_url ⇒ Object
Returns the value of attribute clone_link_url.
21 22 23 |
# File 'lib/pop.rb', line 21 def clone_link_url @clone_link_url end |
#collaboration_interstitial_text ⇒ Object
Returns the value of attribute collaboration_interstitial_text.
23 24 25 |
# File 'lib/pop.rb', line 23 def collaboration_interstitial_text @collaboration_interstitial_text end |
#collaboration_link_enabled ⇒ Object
Returns the value of attribute collaboration_link_enabled.
22 23 24 |
# File 'lib/pop.rb', line 22 def collaboration_link_enabled @collaboration_link_enabled end |
#collaboration_link_url ⇒ Object
Returns the value of attribute collaboration_link_url.
24 25 26 |
# File 'lib/pop.rb', line 24 def collaboration_link_url @collaboration_link_url end |
#collaboration_webhook ⇒ Object
Returns the value of attribute collaboration_webhook.
25 26 27 |
# File 'lib/pop.rb', line 25 def collaboration_webhook @collaboration_webhook end |
#custom_code ⇒ Object
Returns the value of attribute custom_code.
19 20 21 |
# File 'lib/pop.rb', line 19 def custom_code @custom_code end |
#custom_links ⇒ Object
Returns the value of attribute custom_links.
18 19 20 |
# File 'lib/pop.rb', line 18 def custom_links @custom_links end |
#domain ⇒ Object
Returns the value of attribute domain.
27 28 29 |
# File 'lib/pop.rb', line 27 def domain @domain end |
#label_names ⇒ Object
Returns the value of attribute label_names.
13 14 15 |
# File 'lib/pop.rb', line 13 def label_names @label_names end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/pop.rb', line 10 def name @name end |
#newly_populated_regions ⇒ Object (readonly)
Returns the value of attribute newly_populated_regions.
30 31 32 |
# File 'lib/pop.rb', line 30 def newly_populated_regions @newly_populated_regions end |
#newly_populated_tags ⇒ Object (readonly)
Returns the value of attribute newly_populated_tags.
31 32 33 |
# File 'lib/pop.rb', line 31 def @newly_populated_tags end |
#password ⇒ Object
Returns the value of attribute password.
28 29 30 |
# File 'lib/pop.rb', line 28 def password @password end |
#published_pop_url ⇒ Object
Returns the value of attribute published_pop_url.
15 16 17 |
# File 'lib/pop.rb', line 15 def published_pop_url @published_pop_url end |
#slug ⇒ Object
Returns the value of attribute slug.
12 13 14 |
# File 'lib/pop.rb', line 12 def slug @slug end |
#template_id ⇒ Object
Returns the value of attribute template_id.
9 10 11 |
# File 'lib/pop.rb', line 9 def template_id @template_id end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/pop.rb', line 11 def title @title end |
#tracers ⇒ Object
Returns the value of attribute tracers.
14 15 16 |
# File 'lib/pop.rb', line 14 def tracers @tracers end |
#unpopulated_api_regions ⇒ Object
Returns the value of attribute unpopulated_api_regions.
16 17 18 |
# File 'lib/pop.rb', line 16 def unpopulated_api_regions @unpopulated_api_regions end |
#unpopulated_api_tags ⇒ Object
Returns the value of attribute unpopulated_api_tags.
17 18 19 |
# File 'lib/pop.rb', line 17 def @unpopulated_api_tags end |
Instance Method Details
#analytics ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/pop.rb', line 151 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 = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pop.rb', line 73 def as_json( = {}) raise TemplateRequired.new if [:api_representation] && !template_id if [:api_representation] hash = {} hash[:pop] = super() hash[:populate_tags] = @newly_populated_tags hash[:populate_regions] = @newly_populated_regions hash else super() end end |
#disable_cloning ⇒ Object
117 118 119 120 |
# File 'lib/pop.rb', line 117 def disable_cloning self.clone_link_enabled = false self.clone_link_url = nil # doesn't get saed, just for developer interface end |
#disable_collaboration ⇒ Object
107 108 109 110 |
# File 'lib/pop.rb', line 107 def disable_collaboration self.collaboration_link_enabled = false self.collaboration_link_url = nil end |
#edit_url ⇒ Object
96 97 98 |
# File 'lib/pop.rb', line 96 def edit_url return @_api.api_server.gsub('api.', 'www.') + "/edit/#{self._id}" end |
#enable_cloning! ⇒ Object
112 113 114 115 |
# File 'lib/pop.rb', line 112 def enable_cloning! self.clone_link_enabled = true self.save! # go and populate our model with the clone link end |
#enable_collaboration!(interstitial_text = '', webhook = nil) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/pop.rb', line 100 def enable_collaboration!(interstitial_text = '', webhook = nil) self.collaboration_link_enabled = true self.collaboration_webhook = webhook self.collaboration_interstitial_text = interstitial_text self.save! # go and populate our model with the collaboration link end |
#has_unpopulated_region(region_identifier) ⇒ Object
122 123 124 |
# File 'lib/pop.rb', line 122 def has_unpopulated_region(region_identifier) self.unpopulated_api_regions.include?(region_identifier) end |
#has_unpopulated_tag(tag_identifier) ⇒ Object
142 143 144 |
# File 'lib/pop.rb', line 142 def has_unpopulated_tag(tag_identifier) self..include?(tag_identifier) end |
#inflate(json) ⇒ Object
66 67 68 69 70 71 |
# 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) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/pop.rb', line 131 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 }) self.unpopulated_api_regions.delete(region_identifier) end |
#populate_tag(tag_identifier, tag_contents) ⇒ Object
146 147 148 149 |
# File 'lib/pop.rb', line 146 def populate_tag(tag_identifier, tag_contents) @newly_populated_tags[tag_identifier] = tag_contents self..delete(tag_identifier) end |
#publish! ⇒ Object
88 89 90 |
# File 'lib/pop.rb', line 88 def publish! update('POST', 'publish') end |
#type_of_unpopulated_region(region_identifier) ⇒ Object
126 127 128 129 |
# File 'lib/pop.rb', line 126 def type_of_unpopulated_region(region_identifier) return false unless self.has_unpopulated_region(region_identifier) self.unpopulated_api_regions[region_identifier]['type'] end |
#unpublish! ⇒ Object
92 93 94 |
# File 'lib/pop.rb', line 92 def unpublish! update('POST', 'unpublish') end |