require 'rack/utils' require 'uri' module Vinz class Url def initialize(uri, crypto) @uri = uri.is_a?(String) ? URI.parse(uri) : uri @crypto = crypto @param_key = '_creq' end def pack(message) uri = @uri.clone query = Rack::Utils.parse_nested_query(uri.query) query[@param_key] = @crypto.encode(message) uri.query = Rack::Utils.build_nested_query(query) uri end def unpack query = Rack::Utils.parse_nested_query(@uri.query) @crypto.decode(query[@param_key]) end end end