admob 1.1.0 → 1.1.1
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.
- data/History.txt +4 -0
- data/README.txt +2 -1
- data/lib/admob.rb +21 -9
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -20,7 +20,8 @@ Enables easy integration of AdMob services (ads and/or analytics) into a RoR mob
|
|
20
20
|
c.timeout = 1
|
21
21
|
c.encoding = 'UTF-8'
|
22
22
|
c.raise_exceptions = false
|
23
|
-
c.cookie_domain = 'example.com'
|
23
|
+
c.cookie_domain = 'example.com' # you can override this setting in AdMob::set_cookie()
|
24
|
+
c.cookie_path = '/' # you can override this setting in AdMob::set_cookie()
|
24
25
|
end
|
25
26
|
* In a view, where you want an ad, place an ad request.
|
26
27
|
* Note: You must provide your publisher_id and/or analytics_id in the default setting, or when you make the ad request (see below).
|
data/lib/admob.rb
CHANGED
@@ -8,10 +8,10 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
|
8
8
|
# This module encapsulates functionality (ad requests, analytics requests) provided by AdMob. See README.txt for usage.
|
9
9
|
module AdMob
|
10
10
|
|
11
|
-
GEM_VERSION = '1.1.
|
11
|
+
GEM_VERSION = '1.1.1'
|
12
12
|
|
13
13
|
ENDPOINT = URI.parse('http://r.admob.com/ad_source.php')
|
14
|
-
PUBCODE_VERSION = '
|
14
|
+
PUBCODE_VERSION = '20090106-RUBY-8708a7ab5f2b70b6'
|
15
15
|
DEFAULT_TIMEOUT = 1.0
|
16
16
|
|
17
17
|
# Make an AdMob ad/analytics request. The first param is the request variable from Rails; the second is a unique session
|
@@ -41,6 +41,14 @@ module AdMob
|
|
41
41
|
def self.request(request, session_id, params = {})
|
42
42
|
raise_exceptions = params[:raise_exceptions].nil? ? AdMob::Defaults.raise_exceptions : params[:raise_exceptions]
|
43
43
|
|
44
|
+
if raise_exceptions and !params[:cookie_domain].nil?
|
45
|
+
raise AdMob::Error.new("Cannot set cookie_domain in AdMob::request(), set the cookie_domain in the call to AdMob::set_cookie()")
|
46
|
+
end
|
47
|
+
|
48
|
+
if raise_exceptions and !params[:cookie_path].nil?
|
49
|
+
raise AdMob::Error.new("Cannot set cookie_path in AdMob::request(), set the cookie_path in the call to AdMob::set_cookie()")
|
50
|
+
end
|
51
|
+
|
44
52
|
# Build the post request
|
45
53
|
post_data = self.build_post_data(request, session_id, params)
|
46
54
|
if post_data.nil?
|
@@ -86,6 +94,9 @@ module AdMob
|
|
86
94
|
end
|
87
95
|
|
88
96
|
# This function should be called from an ActionController to set a cookie on behalf of AdMob.
|
97
|
+
# If you need to override the default cookie domain or cookie path, pass these as optional parameters to AdMob::set_cookie().
|
98
|
+
# AdMob::set_cookie(request, cookies, :cookie_domain => 'example.com', :cookie_path => '/videos')
|
99
|
+
# You can NOT pass cookie_domain or cookie_path as optional parameters to AdMob::request()
|
89
100
|
# AdMob recommends using a before_filter in your ActionController::Base class (usually in app/controllers/application.rb) to call set_cookie on each request.
|
90
101
|
# Here is a sample application.rb.
|
91
102
|
# require 'admob'
|
@@ -99,7 +110,7 @@ module AdMob
|
|
99
110
|
# AdMob::set_cookie(request, cookies)
|
100
111
|
# end
|
101
112
|
# end
|
102
|
-
def self.set_cookie(request, cookies)
|
113
|
+
def self.set_cookie(request, cookies, params = {})
|
103
114
|
# don't make a new cookie if one already exists
|
104
115
|
return if request.env['admobuu'] or cookies[:admobuu]
|
105
116
|
|
@@ -107,10 +118,10 @@ module AdMob
|
|
107
118
|
value = MD5.hexdigest(rand().to_s + request.user_agent + request.remote_ip + Time.now.to_f.to_s)
|
108
119
|
new_cookie = { :value => value,
|
109
120
|
:expires => Time.at(0x7fffffff), # end of 32 bit time
|
110
|
-
:path => "/" }
|
121
|
+
:path => params[:cookie_path] || AdMob::Defaults.cookie_path || "/" }
|
111
122
|
|
112
|
-
|
113
|
-
|
123
|
+
domain = params[:cookie_domain] || AdMob::Defaults.cookie_domain
|
124
|
+
if domain
|
114
125
|
domain = '.' + domain if domain[0].chr != '.'
|
115
126
|
new_cookie[:domain] = domain
|
116
127
|
end
|
@@ -121,7 +132,7 @@ module AdMob
|
|
121
132
|
end
|
122
133
|
|
123
134
|
# Provides access to AdMob config, used for setting default request info.
|
124
|
-
# Currently, can be used to set defaults for: publisher_id, analytics_id, ad encoding, request timeout, cookie_domain,
|
135
|
+
# Currently, can be used to set defaults for: publisher_id, analytics_id, ad encoding, request timeout, cookie_domain, cookie_path
|
125
136
|
# and whether exceptions are raised when something goes wrong.
|
126
137
|
# For example, in environment.rb:
|
127
138
|
# require 'admob'
|
@@ -131,7 +142,8 @@ module AdMob
|
|
131
142
|
# c.encoding = 'SJIS'
|
132
143
|
# c.timeout = 3
|
133
144
|
# c.raise_exceptions = true
|
134
|
-
# c.cookie_domain = 'example.com'
|
145
|
+
# c.cookie_domain = 'example.com' # this can also be passed to AdMob::set_cookie() but not AdMob::request()
|
146
|
+
# c.cookie_path = '/' # this can also be passed to AdMob::set_cookie() but not AdMob:request()
|
135
147
|
# end
|
136
148
|
def self.config
|
137
149
|
yield AdMob::Defaults
|
@@ -148,7 +160,7 @@ private
|
|
148
160
|
# Stores default values for AdMob requests. Set these defaults via AdMob::config.
|
149
161
|
class Defaults
|
150
162
|
class << self
|
151
|
-
attr_accessor :publisher_id, :analytics_id, :encoding, :timeout, :raise_exceptions, :cookie_domain
|
163
|
+
attr_accessor :publisher_id, :analytics_id, :encoding, :timeout, :raise_exceptions, :cookie_domain, :cookie_path
|
152
164
|
end
|
153
165
|
end
|
154
166
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AdMobAdMob
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|