#
# Copyright (C) 2007 Mobio Networks, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
=begin
this provides advertising call from AdMobs
=end
require 'net/http'
require 'uri'
require 'md5'
module Rmobio
module Ads
module AdMobs
def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
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"] = useragent if useragent
admob_post["i"] = ip if ip
admob_post["p"] = url if url
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 = ""
rescue
end
@ad=admob_contents
end
# the keyword search version also evaluates the supplied page so
# for admobs they are the same
def getAdByPage(adClient)
getAd("",adClient)
end
end
end
end