Module: Diversion::Encode::Json

Included in:
Diversion::Encode
Defined in:
lib/diversion/encode/json.rb

Class Method Summary collapse

Class Method Details

.get_url(attrs, options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/diversion/encode/json.rb', line 9

def get_url(attrs, options)
  # raw json
  json_raw = attrs.to_json

  # build json (slightly lighter than ruby hash)
  json = Url::encode_url(json_raw)

  # if we are signing the url then generate the signature
  sig = Signing::sign_data(options[:sign_key], options[:sign_length], json_raw)
  sig = "-#{sig}" unless sig.empty?

  # get url and include port if needed
  unless options[:port] == 80
    url = "#{options[:host]}:#{options[:port]}#{options[:path]}#{json}#{sig}"
  else
    url = "#{options[:host]}#{options[:path]}#{json}#{sig}"
  end
  url
end