module Diversion::Encode::Json

Public Class Methods

get_url(attrs, options) click to toggle source
# 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