11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/eco_apps/utils/helpers.rb', line 11
def url_of(app_name, url_key, options={})
app = CoreService.app(app_name.to_s)
app_url = YAML.load(app.url)
app_url = app_url[Rails.env] if app_url.is_a?(Hash)
api = YAML.load(app.api)
begin
url = api["url"][url_key.to_s] || ""
options.each{|k,v| url = url.gsub(":#{k}", v.to_s)}
params = options[:params]
params = params.map{|t| "#{t.first}=#{t.last}"}.join("&") if params.instance_of?(Hash)
[app_url.gsub(/\/$/,""), url.gsub(/^\//,"")].join("/") + (params.blank? ? "" : "?#{params}")
rescue Exception => e
raise "#{url_key} of #{app_name} seems not configured correctly in #{app_name}'s site_config.yml"
end
end
|