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

Instance Method Details

#getAd(keywords, adClient, ip = request.remote_ip, url = request.request_uri, useragent = request.user_agent) ⇒ Object

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



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
# File 'lib/rmobio/ads/smaato.rb', line 31

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: 
<?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&amp;l=77bbb740be3c54debc5076f2be48df41&amp;o=false</link><action target="http://dev.soma.smaato.com:8080/wap/lp.jsp?id=1358&amp;l=77bbb740be3c54debc5076f2be48df41&amp;o=false&amp;a=6&amp;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, ip = request.remote_ip, url = request.request_uri, useragent = request.user_agent) ⇒ Object



25
26
27
# File 'lib/rmobio/ads/smaato.rb', line 25

def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
  getAd(nil,adClient,ip,url,useragent)    
end