diff --git a/lib/contentstack/api.rb b/lib/contentstack/api.rb index d55da61..3cc65ea 100644 --- a/lib/contentstack/api.rb +++ b/lib/contentstack/api.rb @@ -24,8 +24,13 @@ def self.init_api(api_key, delivery_token, environment, host, branch, live_previ end def self.live_preview_query(query= {}) - @live_preview[:content_type_uid] = query[:content_type_uid] - @live_preview[:live_preview] = query[:live_preview] + @live_preview[:content_type_uid] = query[:content_type_uid] || query["content_type_uid"] + @live_preview[:live_preview] = query[:live_preview] || query["live_preview"] + @live_preview[:entry_uid] = query[:entry_uid] || query["entry_uid"] + if @live_preview[:content_type_uid].present? && @live_preview[:entry_uid].present? + path = "/content_types/#{@live_preview[:content_type_uid]}/entries/#{@live_preview[:entry_uid]}" + @live_preview_response = send_preview_request(path) + end end def self.fetch_content_types(uid="") @@ -80,7 +85,7 @@ def self.fetch_retry(path, query=nil, count=0) raise Contentstack::Error.new(response) #Retry Limit exceeded end else - response + to_render_content(response) end end @@ -184,5 +189,24 @@ def self.send_preview_request(path, q=nil) raise Contentstack::Error.new(error.to_s) end end + + def self.to_render_content(resp) + if resp.class == Hash + if resp.key?('uid') && resp['uid'] == @live_preview[:entry_uid] + resp = resp.merge(@live_preview_response) + else + resp_keys = resp.keys + resp_keys.each {|key| + resp[key] = to_render_content(resp[key]) + } + end + elsif resp.class == Array + resp.each_with_index {|value, index| + resp[index] = to_render_content(value) + } + end + resp + end + end end diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index 46a27ef..f82aac0 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.5.0" + VERSION = "0.6.1" end \ No newline at end of file