Skip to content

Commit 737883c

Browse files
authored
Merge pull request #26 from contentstack/feature/Ruby-reference-support
Added reference support for ruby SDK
2 parents 5f91b45 + 4b84de7 commit 737883c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/contentstack/api.rb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ def self.init_api(api_key, delivery_token, environment, host, branch, live_previ
2424
end
2525

2626
def self.live_preview_query(query= {})
27-
@live_preview[:content_type_uid] = query[:content_type_uid]
28-
@live_preview[:live_preview] = query[:live_preview]
27+
@live_preview[:content_type_uid] = query[:content_type_uid] || query["content_type_uid"]
28+
@live_preview[:live_preview] = query[:live_preview] || query["live_preview"]
29+
@live_preview[:entry_uid] = query[:entry_uid] || query["entry_uid"]
30+
if @live_preview[:content_type_uid].present? && @live_preview[:entry_uid].present?
31+
path = "/content_types/#{@live_preview[:content_type_uid]}/entries/#{@live_preview[:entry_uid]}"
32+
@live_preview_response = send_preview_request(path)
33+
end
2934
end
3035

3136
def self.fetch_content_types(uid="")
@@ -80,7 +85,7 @@ def self.fetch_retry(path, query=nil, count=0)
8085
raise Contentstack::Error.new(response) #Retry Limit exceeded
8186
end
8287
else
83-
response
88+
to_render_content(response)
8489
end
8590
end
8691

@@ -184,5 +189,24 @@ def self.send_preview_request(path, q=nil)
184189
raise Contentstack::Error.new(error.to_s)
185190
end
186191
end
192+
193+
def self.to_render_content(resp)
194+
if resp.class == Hash
195+
if resp.key?('uid') && resp['uid'] == @live_preview[:entry_uid]
196+
resp = resp.merge(@live_preview_response)
197+
else
198+
resp_keys = resp.keys
199+
resp_keys.each {|key|
200+
resp[key] = to_render_content(resp[key])
201+
}
202+
end
203+
elsif resp.class == Array
204+
resp.each_with_index {|value, index|
205+
resp[index] = to_render_content(value)
206+
}
207+
end
208+
resp
209+
end
210+
187211
end
188212
end

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.5.0"
2+
VERSION = "0.6.1"
33
end

0 commit comments

Comments
 (0)