Module: Diversion::Encode::Params

Defined in:
lib/diversion/encode/params.rb

Class Method Summary collapse

Class Method Details

.get_url(attrs, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/diversion/encode/params.rb', line 5

def get_url(attrs, options)
  # if we are signing the url then generate the signature
  sig = Signing::sign_data(options[:sign_key], options[:sign_length], attrs.to_param)
  sig_param = ""
  unless sig.empty?
    sig_param = "&s=#{sig}"
  end

  params = CGI::escape(attrs.to_param)

  # get url and include port if needed
  unless options[:port] == 80
    url = "#{options[:host]}:#{options[:port]}#{options[:path]}?d=#{params}#{sig_param}"
  else
    url = "#{options[:host]}#{options[:path]}?d=#{params}#{sig_param}"
  end
  url
end