# # 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 . # require 'collections/sequenced_hash' module Rmobio module Ads module Smaato @@adServer="http://dev.soma.smaato.com:8080/wap/reqAd.jsp" def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent) getAd(nil,adClient,ip,url,useragent) end # this returns an adfrom Google's mobile AdSense, given a supplied set of keywords # Smaato doesn't seem to use the IP, the URL or the useragent def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent) logger.info "Smaato ad retrieval" =begin Example: http://dev.soma.smaato.com:8080/wap/reqAd.jsp?pub=3517&adspace=137 &format=JPG&numads=10&offline=true&user=&response=XML &width=176&height=208&device=Sony&devip=123.45.67.89&carrier=o2 &lang=de =end @@userId=request.env['HTTP_USERID'] # build up the various arguments in the adArgs hash adArgs= SequencedHash.new adArgs["pub"]=adClient # replace with real publisher ID adArgs["adspace"]="137" # what is the ad space ID that we need here?! adArgs["format"]="JPG" adArgs["numads"]="1" adArgs["offline"]="true" adArgs["width"]="176" # get these from device capabilities service instead! adArgs["height"]="208" # get these from device capabilities service instead adArgs["response"]="XML" adArgs["user"]=@@userId if (keywords) adArgs["kws"]=CGI::escape(keywords) end # now built the URL to call out to based upon the base URL and ad hash adURL=@@adServer + "?" first=1 # dont put ampersand on first one adArgs.each_key do |x| if adArgs[x] (adURL=adURL+"&") unless first first=nil # start putting in &s adURL = adURL + x + "=" + adArgs[x] end end =begin CALL: http://dev.soma.smaato.com:8080/wap/reqAd.jsp? pub=3517&adspace=0&format=JPG&numads=1&offline=false&width=100&height=100&response=XML&user=101&kws=India =end # ok, now call google's mobile adSense service and get back the full ad @adxml=open(adURL).read =begin RESULT: error375No request data found. success101 77bbb740be3c54debc5076f2be48df41 http://dev.soma.smaato.com:8080/wap/getAd.jsp?id=1358&l=77bbb740be3c54debc5076f2be48df41&o=false =end if (@adxml) adDoc = REXML::Document.new @adxml @adelement = adDoc.elements["//ad"] if (@adelement) @adurl=@adelement.elements["link"].text @urltext=@adelement.elements["adtext"].text @urltext||="LINK TO AD" end end end end end end