Skip to content

Instantly share code, notes, and snippets.

@colindean
Forked from acid/dont.rb
Created April 15, 2011 18:13
Show Gist options
  • Save colindean/922172 to your computer and use it in GitHub Desktop.
Save colindean/922172 to your computer and use it in GitHub Desktop.
require 'digest/md5'
class Hash
def to_query
require 'uri'
self.collect{ |k,v| k.to_s.downcase + '=' + URI::escape(v)}.join('&')
end
end
caPin = "1234"
caSubDomain = "track"
query = {
:caOrderValue => '0.00',
:caOrderReference => 'blafoo',
:caEventID => 'somenumber',
:caComment => '',
:caMultiple => '1',
:caItems => '',
:caCustomerID => '',
:caProductID => '',
:caVoucherCode => '',
:caSLang => 'ruby',
:caLang => 'de_DE',
:caProgramID => '5678',
:caVer => '1.2', #version
}
query[:cachecksum] = Digest::MD5.hexdigest(caPin+query.to_query)
#i'm sure this could be better written server-side and serve up exactly what's
#needed
#it could also benefit from structure from URI::HTTP once that's done
#oh, and haml will make it pretty
caUri = '://'+caSubDomain+'.coolaffiliate.com/transaction.html?'+query.to_query;
puts '<script language="javascript" type="text/javascript">'
puts 'if (location.protocol.toLowerCase() == "https:"){caProtocol="https";}else{caProtocol="http";}'
puts 'caUri = caProtocol + "'+caUri+'" + "&caprotocol=" + caProtocol + "&calocation=" + location.href;'
puts 'document.write(\'<sc\'+\'ript language="JavaScript" type="text/javascript" src="\'+caUri+\'"></sc\'+\'ript>\');'
puts '</script>'
puts '<noscript><img src="https://'+caSubDomain+'.coolaffiliate.com/transaction.html?'+query.to_query+'&caprotocol=https" alt="" width="1" height="1"/>'
puts '</noscript>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment