Module: Rmobio::Ads::AdMobs
- Defined in:
- lib/rmobio/ads/ad_mobs.rb
Instance Method Summary collapse
- #getAd(keywords, adClient) ⇒ Object
-
#getAdByPage(adClient) ⇒ Object
the keyword search version also evaluates the supplied page so for admobs they are the same.
Instance Method Details
#getAd(keywords, adClient) ⇒ Object
29 30 31 32 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 |
# File 'lib/rmobio/ads/ad_mobs.rb', line 29 def getAd(keywords,adClient) logger.info("Retrieving AdMobs ad") admob_params = {:admob_site_id => adClient, # REQUIRED - get from admob.com, value is generally set in rmobio.yml :admob_pc => "", # OPTIONAL - Postal Code, e.g. "90210" :admob_dob => "", # OPTIONAL - Date of Birth formatted like YYYYMMDD, e.g. "19800229" :admob_gender => "", # OPTIONAL - Gender, m[ale] or f[emale] :admob_keywords => keywords} # change to "live" when ready to deploy 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"] # build url 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 # request ad 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 |
#getAdByPage(adClient) ⇒ Object
the keyword search version also evaluates the supplied page so for admobs they are the same
75 76 77 |
# File 'lib/rmobio/ads/ad_mobs.rb', line 75 def getAdByPage(adClient) getAd("",adClient) end |