Module: Rmobio::Ads::Smaato
- Defined in:
- lib/rmobio/ads/smaato.rb
Constant Summary collapse
- @@adServer =
"http://dev.soma.smaato.com:8080/wap/reqAd.jsp"
Instance Method Summary collapse
-
#getAd(keywords, adClient) ⇒ Object
this returns an adfrom Google’s mobile AdSense, given a supplied set of keywords.
- #getAdByPage(adClient) ⇒ Object
Instance Method Details
#getAd(keywords, adClient) ⇒ Object
this returns an adfrom Google’s mobile AdSense, given a supplied set of keywords
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rmobio/ads/smaato.rb', line 30 def getAd(keywords,adClient) 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'] if (@@userId.nil?) @@userId="101" end # 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 # user agent for our browser. 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: <?xml version="1.0"?><response xmlns="http://dev.soma.smaato.com:8080/wap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dev.soma.smaato.com:8080/wap/ http://dev.soma.smaato.com:8080/wap/smaatoapi.xsd"> <event-response><status>error</status><error>375</error><desc>No request data found.</desc></event-response> <status>success</status><user><id>101</id></user> <ads> <ad id="1358" type="JPEG" width="112" height="20" refresh="1206058763039" caching="false" priority="0"> <log-id>77bbb740be3c54debc5076f2be48df41</log-id><valid start="1204849163039" end="1212707963039" max="999999" /> <link>http://dev.soma.smaato.com:8080/wap/getAd.jsp?id=1358&l=77bbb740be3c54debc5076f2be48df41&o=false</link><action target="http://dev.soma.smaato.com:8080/wap/lp.jsp?id=1358&l=77bbb740be3c54debc5076f2be48df41&o=false&a=6&t=http://www.smaato.mobi" type="LINK" acc="server" /> <adtext /> </ad> </ads> </response> =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 |
#getAdByPage(adClient) ⇒ Object
25 26 27 |
# File 'lib/rmobio/ads/smaato.rb', line 25 def getAdByPage(adClient) getAd(nil,adClient) end |