rmobio 1.1.21 → 1.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ module Rmobio
26
26
  module Ads
27
27
  module AdMobs
28
28
 
29
- def getAd(keywords,adClient)
29
+ def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
30
30
  logger.info("Retrieving AdMobs ad")
31
31
  admob_params = {:admob_site_id => adClient, # REQUIRED - get from admob.com, value is generally set in rmobio.yml
32
32
  :admob_pc => "", # OPTIONAL - Postal Code, e.g. "90210"
@@ -43,9 +43,9 @@ module Rmobio
43
43
  # build url
44
44
  admob_post = {}
45
45
  admob_post["s"] = admob_params[:admob_site_id]
46
- admob_post["u"] = request.user_agent
47
- admob_post["i"] = request.remote_ip
48
- admob_post["p"] = request.request_uri
46
+ admob_post["u"] = useragent if useragent
47
+ admob_post["i"] = ip if ip
48
+ admob_post["p"] = url if url
49
49
  admob_post["t"] = MD5.hexdigest(session.session_id)
50
50
  admob_post["v"] = admob_version
51
51
  admob_post["d[pc]"] = admob_params[:admob_pc]
@@ -22,53 +22,40 @@ and released "page scraping version"
22
22
  =end
23
23
  require 'digest/sha1'
24
24
  require 'collections/sequenced_hash'
25
+ require 'open-uri'
25
26
 
26
27
  module Rmobio
27
28
  module Ads
28
29
  module AdSense
29
30
 
30
31
  @@adServer="http://pagead2.googlesyndication.com/pagead/ads"
31
- @@mobioUseragent="Mobio" # we should probably come up with a better string
32
+ @@mobio_useragent="Mobio" # we should probably come up with a better string
33
+ @@default_ip="127.0.0.1"
32
34
 
33
35
  def getAdParms
34
36
  getAd(params[:keywords],params[:adClient])
35
37
  end
36
-
37
-
38
- #$GLOBALS['google']['ad_type']='text';
39
- #$GLOBALS['google']['channel']='8618723264';
40
- #$GLOBALS['google']['client']='pub-0061196910475770';
41
- #$GLOBALS['google']['format']='mobile_single';
42
- #$GLOBALS['google']['https']=$_SERVER['HTTPS'];
43
- #$GLOBALS['google']['host']=$_SERVER['HTTP_HOST'];
44
- #$GLOBALS['google']['ip']=$_SERVER['REMOTE_ADDR'];
45
- #$GLOBALS['google']['markup']='xhtml';
46
- #$GLOBALS['google']['oe']='utf8';
47
- #$GLOBALS['google']['output']='xhtml';
48
- #$GLOBALS['google']['ref']=$_SERVER['HTTP_REFERER'];
49
- #$GLOBALS['google']['url']=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
50
- #$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];
51
-
52
- def getAdByPage(adClient)
53
38
 
39
+ # this returns an ad from Google's mobile AdSense, given the current page
40
+ # * ad_client - your Google adsense ID
41
+ # * ip - optional, the IP you want to tell Google its coming from
42
+ # * url - optional, the page you want to put an ad on. Defaults to what is detected
43
+ # * useragent - the useragent of the mobile browser. Defaults to what is detected.
44
+ def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
54
45
  @@userId=request.env['HTTP_USERID']
55
- if (@@userId.nil?)
56
- @@userId="101"
57
- end
58
-
59
46
  adArgs= SequencedHash.new
60
47
  adArgs["ad_type"]="text"
61
48
  adArgs["channel"]="8618723264"
62
49
  adArgs["client"]=adClient
63
50
  adArgs["format"]="mobile_single"
64
- adArgs["host"]=request.host
65
- adArgs["ip"]=request.remote_ip
51
+ adArgs["host"]=request.host if request.host
52
+ adArgs["ip"]=URI.escape(ip) if ip
66
53
  adArgs["markup"]="xhtml"
67
54
  adArgs["output"]="xhtml"
68
55
  adArgs["oe"]="utf8"
69
- adArgs["ref"]=request.referer
70
- adArgs["url"]="http://"+request.env["HTTP_HOST"]+request.env["REQUEST_URI"]
71
- #adArgs["useragent"]=request.user_agent
56
+ #adArgs["ref"]=referer
57
+ adArgs["url"]=url if url
58
+ adArgs["useragent"]=URI.escape(useragent) if useragent
72
59
  adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid
73
60
 
74
61
  # now built the URL to call out to based upon the base URL and ad hash
@@ -82,33 +69,33 @@ module Rmobio
82
69
  end
83
70
  end
84
71
  # ok, now call google's mobile adSense service and get back the full ad
85
- @pagead=open(adURL).read
72
+ @pagead=open(adURL,"User-Agent"=>useragent).read
86
73
 
87
74
  end
88
75
 
89
76
  # this returns an ad from Google's mobile AdSense, given a supplied set of keywords
90
77
  # * keywords - keywords to use for search
91
- # * ad Client - your Google adsense ID
92
- def getAd(keywords,adClient)
78
+ # * ad_client - your Google adsense ID
79
+ # * ip - optional, the IP you want to say the request is coming from
80
+ # * url - optional, the page you want to put an ad on
81
+ # * useragent - the browser this is for. Defaults to the one detected
82
+ def getAd(keywords,ad_client,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
93
83
  doTinyUrl=true
84
+
85
+ @user_id=request.env['HTTP_USERID'] if request.env['HTTP_USERID']
94
86
 
95
- @@userId=request.env['HTTP_USERID']
96
- if (@@userId.nil?)
97
- @@userId="101"
98
- end
99
87
  # build up the various arguments in the adArgs hash
100
88
  adArgs= SequencedHash.new
101
- adArgs["ad_type"]="text"
102
- adArgs["client"]=adClient
103
- adArgs["format"]="mobile_single"
104
- adArgs["ip"]=request.remote_ip
89
+ adArgs["ad_type"]="text_image"
90
+ adArgs["client"]=ad_client
91
+ adArgs["format"]="mobile_single"
92
+ adArgs["ip"]=URI.escape(ip) if ip
105
93
  adArgs["markup"]="xhtml"
106
- adArgs["output"]="wml"
94
+ adArgs["output"]="xhtml"
107
95
  adArgs["oe"]="utf-8"
108
- adArgs["url"]="http:%3A%2Fwww.getmobio.com" # mobio's home site
109
- # adArgs["useragent"]=request.user_agent - doesn't actually work with the supplied useragent from the browser!
110
- adArgs["useragent"]||=@@mobioUseragent # its our runner so default to our useragent if no other one is available
111
- adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20] # oneway hashed userid
96
+ adArgs["url"]=url if url
97
+ adArgs["useragent"]=URI.escape(useragent) if useragent
98
+ adArgs["eip"]=Digest::SHA1.hexdigest(@user_id)[0..20] # oneway hashed userid
112
99
  if (keywords)
113
100
  adArgs["kw"]=CGI::escape(keywords)
114
101
  adArgs["kw_type"]="broad"
@@ -123,8 +110,9 @@ module Rmobio
123
110
  adURL = adURL + x + "=" + adArgs[x]
124
111
  end
125
112
  end
113
+
126
114
  # ok, now call google's mobile adSense service and get back the full ad
127
- @ad=open(adURL).read
115
+ @ad=open(adURL,"User-Agent"=>CGI::escape(useragent)).read
128
116
  if @ad
129
117
  logger.info "Returned ad" + @ad
130
118
  adDoc = REXML::Document.new @ad
@@ -26,22 +26,17 @@ module Rmobio
26
26
  module MKhoj
27
27
 
28
28
 
29
- def getAd(keywords,adClient)
30
- getAdByPage(adClient) # keywords have no effect in mKhoj
29
+ def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
30
+ getAdByPage(adClient,ip,url,useragent) # keywords have no effect in mKhoj
31
31
  end
32
32
 
33
- def getAdByPage(adClient)
33
+ def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
34
34
  # mKhoj just detects your URL, so you don't really need an adClient variable for this particular network!
35
- # but we have it here for consistency
36
- handset = request.user_agent if request.user_agent
37
- # handset="nokia6030/"
38
- handset = URI.escape(handset)
39
- #carrier = URI.escape(request.remote_ip)
40
- carrier="59.181.113.59" # only works with India carriers!!
35
+ #carrier="59.181.113.59" # only works with India carriers!!
41
36
 
42
- adUrl="http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset=nokia6030/&carrier=59.181.113.59"
37
+ adUrl = "http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset="+URI.escape(useragent)+"&carrier="+ip
38
+ #adUrl="http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset=nokia6030/&carrier=59.181.113.59"
43
39
  logger.info "Calling: " + adUrl
44
- #adUrl = "http://www.mkhoj.com/view/Traffic/ShowAd.aspx?siteId=330ed28f-0de9-4c4f-b0a8-1f2118358c80&handset="+handset+"&carrier="+carrier
45
40
  begin
46
41
  @ad = open(adUrl).read
47
42
  logger.info "Returned ad: " + @ad
@@ -5,10 +5,10 @@ module Rmobio
5
5
  module Ads
6
6
  module NoNetwork
7
7
 
8
- def getAd(keywords,adClient)
8
+ def getAd(keywords,adClient,ip,url,useragent)
9
9
  end
10
10
 
11
- def getAdByPage(adClient)
11
+ def getAdByPage(adClient,ip,url,useragent)
12
12
 
13
13
  end
14
14
 
@@ -22,12 +22,13 @@ module Rmobio
22
22
  module Smaato
23
23
  @@adServer="http://dev.soma.smaato.com:8080/wap/reqAd.jsp"
24
24
 
25
- def getAdByPage(adClient)
26
- getAd(nil,adClient)
25
+ def getAdByPage(adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
26
+ getAd(nil,adClient,ip,url,useragent)
27
27
  end
28
28
 
29
29
  # this returns an adfrom Google's mobile AdSense, given a supplied set of keywords
30
- def getAd(keywords,adClient)
30
+ # Smaato doesn't seem to use the IP, the URL or the useragent
31
+ def getAd(keywords,adClient,ip=request.remote_ip,url=request.request_uri,useragent=request.user_agent)
31
32
  logger.info "Smaato ad retrieval"
32
33
  =begin
33
34
  Example:
@@ -37,9 +38,7 @@ http://dev.soma.smaato.com:8080/wap/reqAd.jsp?pub=3517&adspace=137
37
38
  &lang=de
38
39
  =end
39
40
  @@userId=request.env['HTTP_USERID']
40
- if (@@userId.nil?)
41
- @@userId="101"
42
- end
41
+
43
42
  # build up the various arguments in the adArgs hash
44
43
  adArgs= SequencedHash.new
45
44
  adArgs["pub"]=adClient # replace with real publisher ID
@@ -50,7 +49,7 @@ http://dev.soma.smaato.com:8080/wap/reqAd.jsp?pub=3517&adspace=137
50
49
  adArgs["width"]="176" # get these from device capabilities service instead!
51
50
  adArgs["height"]="208" # get these from device capabilities service instead
52
51
  adArgs["response"]="XML"
53
- adArgs["user"]=@@userId # user agent for our browser.
52
+ adArgs["user"]=@@userId
54
53
  if (keywords)
55
54
  adArgs["kws"]=CGI::escape(keywords)
56
55
  end
data/lib/rmobio/ads.rb CHANGED
@@ -23,10 +23,8 @@ and documented at http://opssrv01/wiki/index.php/Mobio_Rails_Application_Framewo
23
23
  if MOBIO_CONFIG['ad_network']
24
24
  adlib="rmobio/ads/" + MOBIO_CONFIG['ad_network']
25
25
  else
26
- puts "Not using ad network"
27
26
  adlib='rmobio/ads/' + 'no_network'
28
27
  end
29
28
  require adlib
30
- puts "Including " + adlib.camelize
31
29
  eval("include " + adlib.camelize)
32
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmobio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.21
4
+ version: 1.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mobio Networks
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-22 00:00:00 -07:00
12
+ date: 2008-05-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements: []
84
84
 
85
85
  rubyforge_project:
86
- rubygems_version: 1.1.1
86
+ rubygems_version: 1.0.1
87
87
  signing_key:
88
88
  specification_version: 2
89
89
  summary: Rmobio API