Class: PagelimeReceiverController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/app/controllers/pagelime_receiver_controller.rb

Instance Method Summary collapse

Instance Method Details

#after_publish_callbackObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/app/controllers/pagelime_receiver_controller.rb', line 7

def after_publish_callback
  
	page_key = Base64.encode64(params[:path])
  Rails.cache.delete("cms:#{page_key}")
  Rails.cache.delete("cms:shared")

# don't do the prefetch below, as the page isn't done publishing (mySQL transaction hasn't completed) at the point when this gets called  	
=begin
	begin
		new_content = fetch_cms_xml(params[:path]);
	rescue
	end
=end
	
	render :inline => "cache cleared", :status => 200
	
end

#after_publish_callback_oldObject



25
26
27
28
29
30
31
32
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/app/controllers/pagelime_receiver_controller.rb', line 25

def after_publish_callback_old
  
  # the page_id will come from the request
  page_id = params[:page_id]
  
  # TODO: use the API to get content    
  uri = URI.parse("http://qa.cms.pagelime.com/API/Account/SOAP/Page.asmx/Get")
  http = Net::HTTP.new(uri.host, uri.port)
  # http.use_ssl = true
  http.open_timeout = 2
  http.read_timeout = 7
  # http.set_debug_output $stderr
  data = {:apiKey => "0fa155c4-9c42-4df6-856a-5cff6e2ff631", :pageId => page_id}.to_json
  response = http.post(uri.path,data,{"content-type"=>"application/json; charset=utf-8","accept"=>"application/json, text/javascript, */*"})

  page_json = JSON.parse(response.body)
  page_json = page_json["d"]
  
  # try to find existing page
  page = PagelimePage.find_by_page_id(page_id)
  if (page)
    # delete existing content
    page.editable_areas.destroy
    page..destroy
  else
    # if no page is found, create a new one
    page = PagelimePage.new
  end

  # set the page data
  page.page_id = page_id
  page.path = page_json[:Path]
  page.title = page_json[:Title]
  page.date_published = DateTime.now
  
  # save the page
  page.save
  
  # for each piece of content
  for page_content_json in page_json["EditableRegions"]
    
    # create the content data
    page_content = PagelimeContent.new
    page_content.client_id = page_content_json[:ClientID]
    page_content.page = page
    page_content.html = page_content_json[:Html]
    
    # save content
    page_content.save
    
  end
  
  # for each piece of meta data
  for  in page_json["MetaDataJSON"]
    
    # create the content data
     = PagelimeMetaData.new
    .name = [0]
    .content = [1]
    .page = page
    
    # save content
    .save
    
  end
  
  # respond with an OK status or CREATED status
  render :status => 200
  
end

#indexObject



3
4
5
# File 'lib/app/controllers/pagelime_receiver_controller.rb', line 3

def index
  render :inline => "working", :status => 200
end