Module: Idapted::Helpers::InstanceMethods

Defined in:
lib/eco_apps/utils/helpers.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_ip_addressObject



28
29
30
31
32
33
34
35
36
# File 'lib/eco_apps/utils/helpers.rb', line 28

def authenticate_ip_address
  INTRANET_IP.each do |ip|
    return if ip.contains?(request.remote_ip)
  end
  respond_to do |format|
    format.html{ render :text => "Access Denied!" }
    format.xml{ render :xml => {:info => "Access Denied!"}.to_xml, :status => :forbidden}
  end
end

#url_of(app_name, url_key, options = {}) ⇒ Object



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