Module: Rmobio::Ads::Smaato

Defined in:
lib/rmobio/ads/smaato.rb

Constant Summary collapse

@@adServer =
"http://soma.smaato.com/oapi/reqAd.jsp"

Instance Method Summary collapse

Instance Method Details

#get_ad(keywords, ad_client, request, kw_type = "broad") ⇒ Object



28
29
30
# File 'lib/rmobio/ads/smaato.rb', line 28

def get_ad(keywords,ad_client,request,kw_type="broad")
  getAd(keywords,ad_client,ip=request.remote_ip,request.request_uri,request.user_agent,request.env["HTTP_USERID"],kw_type)
end

#getAd(keywords, adClient, ip = request.remote_ip, url = request.request_uri, useragent = request.user_agent, userid = request.env["HTTP_USERID"], kw_type = "broad") ⇒ 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



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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rmobio/ads/smaato.rb', line 38

def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent,userid=request.env["HTTP_USERID"],kw_type="broad")
  # build up the various arguments in the adArgs hash
  adArgs= SequencedHash.new
  adArgs["pub"]=adClient 
  adArgs["adspace"]=MOBIO_CONFIG['adspace'] # what is the ad space ID that we need here?!
  adArgs["format"]="JPG"
  adArgs["numads"]="1"
  adArgs["offline"]="true"
  adArgs["response"]="XML"
  adArgs["ownid"]=userid  
  
  # supply device information from the Mobio device capability service based on the user agent   
  adArgs["device"]=capability("name",useragent)
  adArgs["device"]||="SonyEricsson%20K750i"
  adArgs["width"]=capability("width",useragent) # get these from device capabilities service instead!
  adArgs["width"]||=(MOBIO_CONFIG['default_width'].to_s)
  adArgs["height"]=capability("height",useragent)  # get these from device capabilities service instead
  adArgs["height"]||=(MOBIO_CONFIG['default_height'].to_s)
  
  adArgs["devip"]=ip if ip and ip.size>0
  adArgs["kws"]=CGI::escape(keywords) if keywords and keywords.size>0

  # now build 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].to_s
    end
  end
  p "URL to retrieve ad: " +adURL
  # result will have content, linktext, linkurl and optionally calltext, callurl, moretext
  result={}
  result['content']=open(adURL).read
=begin
RESULT: 
	<response xsi:schemaLocation="http://soma.smaato.com/oapi/ http://soma.smaato.com/oapi/smaatoapi.xsd">
	<event-response>
<status>error</status>
<error>375</error>
<desc>No request data found.</desc>
</event-response>
<status>success</status>
	<user>
<id>265563</id>
</user>
	<ads>
	<ad id="1000253060" type="JPEG" width="167" height="30" refresh="1215816516646" caching="true" priority="0">
<log-id>8c7871a957ad65cc7e3c3047c5ade89c</log-id>
<valid start="1214606916646" end="1222382916646" max="999999"/>
	<link>
http://soma.smaato.com/oapi/getAd.jsp?id=1000253060&l=8c7871a957ad65cc7e3c3047c5ade89c&o=true&t=ext
</link>
<action target="http://soma.smaato.com/oapi/lp.jsp?id=1000253060&l=8c7871a957ad65cc7e3c3047c5ade89c&o=false&a=6&t=ext" type="LINK" acc="server"/>
<adtext/>
</ad>
</ads>
</response>
=end
  p result['content']
  if (result['content'])
    doc=XmlSimple.xml_in(result['content']) 
    ad=doc["ads"][0]["ad"][0]
    if (ad)
      p ad
      result['linkurl']=ad["link"]
      result['linktext']=ad["adtext"]
      result['linktext']||="LINK TO AD" 
    end
  end
  result
end

#getAdByPage(adClient, ip = request.remote_ip, url = request.request_uri, useragent = request.user_agent, userid = request.env["HTTP_USERID"], kw_type = "broad") ⇒ Object



32
33
34
# File 'lib/rmobio/ads/smaato.rb', line 32

def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent,userid=request.env["HTTP_USERID"],kw_type="broad")
  getAd(nil,adClient,ip,url,useragent,userid,kw_type)    
end