By adding key and private_key to the attrs array here, they will automatically get added to the path.  Then, below, you are manually adding key or signature (the if key u << path << "&key=" << key elsif client && private_key u << path << "&signature=" << sign(path) ).  So say you had set client and private_key previously in your code.  The URL would come out having BOTH private_key and signature.  And if you had set key previously, key would be in the URL twice.
"&