Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/contentstack/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/contentstack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Contentstack
VERSION = "0.5.0"
VERSION = "0.6.1"
end