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")
adArgs= SequencedHash.new
adArgs["pub"]=adClient
adArgs["adspace"]=MOBIO_CONFIG['adspace'] adArgs["format"]="JPG"
adArgs["numads"]="1"
adArgs["offline"]="true"
adArgs["response"]="XML"
adArgs["ownid"]=userid
adArgs["device"]=capability("name",useragent)
adArgs["device"]||="SonyEricsson%20K750i"
adArgs["width"]=capability("width",useragent) adArgs["width"]||=(MOBIO_CONFIG['default_width'].to_s)
adArgs["height"]=capability("height",useragent) 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
adURL=@@adServer + "?"
first=1 adArgs.each_key do |x|
if adArgs[x]
(adURL=adURL+"&") unless first
first=nil adURL = adURL + x + "=" + adArgs[x].to_s
end
end
p "URL to retrieve ad: " +adURL
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
|