Class: Mack::Rendering::Url

Inherits:
Base
  • Object
show all
Defined in:
lib/rendering/classes/url.rb

Overview

Used when someone calls render(:url => “www.mackframework.com”)

Instance Attribute Summary

Attributes inherited from Base

#options, #view_binder

Instance Method Summary collapse

Methods inherited from Base

#initialize, #params

Constructor Details

This class inherits a constructor from Mack::Rendering::Base

Instance Method Details

#renderObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rendering/classes/url.rb', line 7

def render
  options = {:method => :get, :domain => app_config.mack.site_domain, :raise_exception => false}.merge(self.options)
  case options[:method]
  when :get
    do_render_url(options) do |uri, options|
      unless options[:parameters].empty?
        uri = uri.to_s
        uri << "?"
        options[:parameters].each_pair do |k,v|
          uri << URI.encode(k.to_s)
          uri << "="
          uri << URI.encode(v.to_s)
          uri << "&"
        end
        uri.gsub!(/&$/, "")
        uri = URI.parse(uri)
      end
      Net::HTTP.get_response(uri)
    end
  when :post
    do_render_url(options) do |uri, options|
      Net::HTTP.post_form(uri, options[:parameters] || {})
    end
  else
    raise Mack::Errors::UnsupportRenderUrlMethodType.new(options[:method])
  end
end