def getAd(keywords,adClient)
logger.info("Retrieving AdMobs ad")
admob_params = {:admob_site_id => adClient,
:admob_pc => "",
:admob_dob => "",
:admob_gender => "",
:admob_keywords => keywords}
admob_mode = "test"
admob_endpoint = "http://r.admob.com/ad_source.php"
admob_version = "20071126-RUBY-19db4ba7ab087721"
admob_timeout = 1.0
admob_ignore = Set["HTTP_PRAGMA", "HTTP_CACHE_CONTROL", "HTTP_CONNECTION", "HTTP_USER_AGENT", "HTTP_COOKIE"]
admob_post = {}
admob_post["s"] = admob_params[:admob_site_id]
admob_post["u"] = request.user_agent
admob_post["i"] = request.remote_ip
admob_post["p"] = request.request_uri
admob_post["t"] = MD5.hexdigest(session.session_id)
admob_post["v"] = admob_version
admob_post["d[pc]"] = admob_params[:admob_pc]
admob_post["d[dob]"] = admob_params[:admob_dob]
admob_post["d[gender]"] = admob_params[:admob_gender]
admob_post["k"] = admob_params[:admob_keywords]
request.env.each {|k,v| admob_post["h[#{k}]"] = v unless admob_ignore.include?(k.upcase)}
admob_post["m"] = "test" if admob_mode == "test"
begin
admob_uri = URI.parse(admob_endpoint)
admob_request = Net::HTTP::Post.new(admob_uri.path)
admob_request.set_form_data(admob_post)
admob_conn = Net::HTTP.new(admob_uri.host, admob_uri.port)
admob_conn.read_timeout = admob_timeout
admob_conn.open_timeout = admob_timeout
admob_response = admob_conn.start {|admob_http| admob_http.request(admob_request) }
admob_contents = admob_response.body
rescue Timeout::Error => te
admob_contents = "<img src=\"http://t.admob.com/li.php/c.gif/#{admob_params[:admob_site_id]}/1/#{admob_timeout}/#{MD5.hexdigest(request.request_uri)}\" alt=\"\" width=\"1\" height=\"1\" />"
rescue
end
@ad=admob_contents
end