33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rmobio/ads/ad_mobs.rb', line 33
def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent,userid=request.env["HTTP_USERID"],kw_type="broad")
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"] = useragent if useragent
admob_post["i"] = ip if ip
admob_post["p"] = url if url
admob_post["t"] = MD5.hexdigest(userid) 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
|