Created
February 29, 2012 16:12
-
-
Save dolarsrg/1942070 to your computer and use it in GitHub Desktop.
Takes an url, detects its params and adds to it the vars from the hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes an url, detects its params and adds to it the vars from the hash | |
# Example of use: | |
# > add_url_vars("http://www.example.com/signup?token=HIWORLD", {:s => 'HIAGAIN', :s32 => 'BYE'}) | |
# => "http://www.example.com/signup?token=HIWORLD&s=HIAGAIN&s32=BYE" | |
def add_url_vars(url, vars={}) | |
uri = URI.parse(url) | |
pre_vars = get_url_vars(url) | |
vars_total = [] | |
for var in pre_vars | |
vars_total << "#{var[0]}=#{var[1][0]}" | |
end | |
for var in vars | |
vars_total << "#{var[0]}=#{var[1]}" | |
end | |
return "#{uri.scheme}://#{uri.host}#{uri.path}?#{vars_total.join('&')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment