Module: Rmobio::Ads::AdSense
- Defined in:
- lib/rmobio/ads/ad_sense.rb
Constant Summary collapse
- @@adServer =
"http://pagead2.googlesyndication.com/pagead/ads"
- @@mobioUseragent =
we should probably come up with a better string
"Mobio"
Instance Method Summary collapse
-
#getAd(keywords, adClient) ⇒ Object
this returns an ad from Google’s mobile AdSense, given a supplied set of keywords * keywords - keywords to use for search * ad Client - your Google adsense ID.
-
#getAdByPage(adClient) ⇒ Object
$GLOBALS[‘ad_type’]=‘text’; $GLOBALS[‘channel’]=‘8618723264’; $GLOBALS[‘client’]=‘pub-0061196910475770’; $GLOBALS[‘format’]=‘mobile_single’; $GLOBALS[‘https’]=$_SERVER; $GLOBALS[‘host’]=$_SERVER; $GLOBALS[‘ip’]=$_SERVER; $GLOBALS[‘markup’]=‘xhtml’; $GLOBALS[‘oe’]=‘utf8’; $GLOBALS[‘output’]=‘xhtml’; $GLOBALS[‘ref’]=$_SERVER; $GLOBALS[‘url’]=$_SERVER .
- #getAdParms ⇒ Object
Instance Method Details
#getAd(keywords, adClient) ⇒ Object
this returns an ad from Google’s mobile AdSense, given a supplied set of keywords
-
keywords - keywords to use for search
-
ad Client - your Google adsense ID
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rmobio/ads/ad_sense.rb', line 92 def getAd(keywords,adClient) doTinyUrl=true @@userId=request.env['HTTP_USERID'] if (@@userId.nil?) @@userId="101" end # build up the various arguments in the adArgs hash 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" # mobio's home site # adArgs["useragent"]=request.user_agent - doesn't actually work with the supplied useragent from the browser! adArgs["useragent"]||=@@mobioUseragent # its our runner so default to our useragent if no other one is available adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid if (keywords) adArgs["kw"]=CGI::escape(keywords) adArgs["kw_type"]="broad" 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 # ok, now call google's mobile adSense service and get back the full ad @ad=open(adURL).read if @ad logger.info "Returned ad" + @ad adDoc = REXML::Document.new @ad @text = adDoc.elements['//p'] if @text # do we have a <p> element # ok, now text has the full ad display content including links # grab @url, @urltext (link text for url), @phone, @phonetext (link text for call) 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] # this should have everything else that is not a child element if (@text.size>3 and @text[3]) # only process @text[3] for phone stuff if it exists @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 # if we get an ad back from adsense @ad # return the full ad text end |
#getAdByPage(adClient) ⇒ Object
$GLOBALS[‘ad_type’]=‘text’; $GLOBALS[‘channel’]=‘8618723264’; $GLOBALS[‘client’]=‘pub-0061196910475770’; $GLOBALS[‘format’]=‘mobile_single’; $GLOBALS[‘https’]=$_SERVER; $GLOBALS[‘host’]=$_SERVER; $GLOBALS[‘ip’]=$_SERVER; $GLOBALS[‘markup’]=‘xhtml’; $GLOBALS[‘oe’]=‘utf8’; $GLOBALS[‘output’]=‘xhtml’; $GLOBALS[‘ref’]=$_SERVER; $GLOBALS[‘url’]=$_SERVER . $_SERVER; $GLOBALS[‘useragent’]=$_SERVER;
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 |
# File 'lib/rmobio/ads/ad_sense.rb', line 52 def getAdByPage(adClient) @@userId=request.env['HTTP_USERID'] if (@@userId.nil?) @@userId="101" end adArgs= SequencedHash.new adArgs["ad_type"]="text" adArgs["channel"]="8618723264" adArgs["client"]=adClient adArgs["format"]="mobile_single" adArgs["host"]=request.host adArgs["ip"]=request.remote_ip adArgs["markup"]="xhtml" adArgs["output"]="xhtml" adArgs["oe"]="utf8" adArgs["ref"]=request.referer adArgs["url"]="http://"+request.env["HTTP_HOST"]+request.env["REQUEST_URI"] #adArgs["useragent"]=request.user_agent adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid # 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 # ok, now call google's mobile adSense service and get back the full ad @pagead=open(adURL).read end |
#getAdParms ⇒ Object
33 34 35 |
# File 'lib/rmobio/ads/ad_sense.rb', line 33 def getAdParms getAd(params[:keywords],params[:adClient]) end |