def getAd(keywords,adClient)
doTinyUrl=true
@@userId=request.env['HTTP_USERID']
if (@@userId.nil?)
@@userId="101"
end
adArgs= SequencedHash.new
adArgs["ad_type"]="text"
adArgs["client"]=adClient
adArgs["format"]="mobile_single"
adArgs["ip"]=request.remote_ip
adArgs["markup"]="xhtml"
adArgs["output"]="wml"
adArgs["oe"]="utf-8"
adArgs["url"]="http:%3A%2Fwww.getmobio.com"
adArgs["useragent"]||=@@mobioUseragent
adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]
if (keywords)
adArgs["kw"]=CGI::escape(keywords)
adArgs["kw_type"]="broad"
end
adURL=@@adServer + "?"
first=1
adArgs.each_key do |x|
if adArgs[x]
(adURL=adURL+"&") unless first
first=nil
adURL = adURL + x + "=" + adArgs[x]
end
end
@ad=open(adURL).read
if @ad
logger.info "Returned ad" + @ad
adDoc = REXML::Document.new @ad
@text = adDoc.elements['//p']
if @text
if defined? @text[1].attributes['href'] and @text[1].attributes['href']
@adurl = doTinyUrl ? tinyUrl(@text[1].attributes['href']) : @text[1].attributes['href']
else
@adurl = "nolink.rwap"
end
@urltext=@text[1].text
@extratext=@text[2].to_s if @text[2]
if (@text.size>3 and @text[3])
@phone = (doTinyUrl ? tinyUrl(@text[3].attributes['href']) : @text[3].attributes['href']) if defined? @text[3].attributes['href'] and @text[3].attributes['href']
@phonetext=@text[3].text if defined? @text[3].text and @text[3].text
end
end
end
@ad
end