rmobio 1.1.0
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/lib/rmobio/ads/ad_mobs.rb +83 -0
- data/lib/rmobio/ads/ad_sense.rb +190 -0
- data/lib/rmobio/ads/m_khoj.rb +54 -0
- data/lib/rmobio/ads/smaato.rb +106 -0
- data/lib/rmobio/ads.rb +24 -0
- data/lib/rmobio/auth.rb +155 -0
- data/lib/rmobio/cas.rb +24 -0
- data/lib/rmobio/client_info.rb +194 -0
- data/lib/rmobio/config_manager.rb +63 -0
- data/lib/rmobio/raketasks.rb +143 -0
- data/lib/rmobio/utils.rb +213 -0
- data/lib/rmobio/webservices/soap/drivers.rb +62 -0
- data/lib/rmobio/webservices/soap/geocode.rb +19 -0
- data/lib/rmobio/webservices/soap/messaging.rb +75 -0
- data/lib/rmobio/webservices/soap/platform.rb +21 -0
- data/lib/rmobio/webservices/soap/registration.rb +106 -0
- data/lib/rmobio/webservices/soap/rss.rb +49 -0
- data/lib/rmobio/webservices.rb +72 -0
- data/lib/rmobio.rb +22 -0
- metadata +84 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
=begin
|
19
|
+
Some summary should go here
|
20
|
+
=end
|
21
|
+
|
22
|
+
#require 'rexml/document'
|
23
|
+
require 'open-uri'
|
24
|
+
require 'hpricot'
|
25
|
+
|
26
|
+
module Rmobio
|
27
|
+
module ClientInfo
|
28
|
+
|
29
|
+
#== checkClient
|
30
|
+
#=== The method checks the client type, version and family by analyzing the request header.
|
31
|
+
#=== HTTP_ACCEPT
|
32
|
+
#* If header contains application/pxml => 'xf' (xforms client)
|
33
|
+
#* If header contains wml or wap => 'wap'
|
34
|
+
#* If header contains applicaton/html => 'html'
|
35
|
+
#* Otherwise, default to html => 'html'
|
36
|
+
# If xf cient, the "POST" parameters are parsed to name/value pairs in params
|
37
|
+
#
|
38
|
+
#=== HTTP_CLIENT_INFO_URL
|
39
|
+
#
|
40
|
+
#* If header exists => 0.8 client
|
41
|
+
#* If header doesn't exist => 0.6 client
|
42
|
+
# Samle of what HTTP_CLIENT_INFO_URL returns:
|
43
|
+
# http://homer.mobiolabs.com/gateway/public/clientServices/getCapability?id=1.0.5:Motorola:V3
|
44
|
+
#
|
45
|
+
#=== HTTP_MOBIO_AGENT
|
46
|
+
#* If header contains WM5 => Window Mobile family
|
47
|
+
#
|
48
|
+
#== Return Codes
|
49
|
+
# The method returns the following instance varables:
|
50
|
+
# @client => 'xf' or 'html' or 'wap'
|
51
|
+
# params[] => array contains name/value pairs of all parameters from POST request
|
52
|
+
# @paramsdoc => POST request in xml (parsed by hpricot)
|
53
|
+
#
|
54
|
+
# @client_version => '0.6' or '0.8'
|
55
|
+
#
|
56
|
+
def checkClient
|
57
|
+
logger.debug('checkClient http_accept header:')
|
58
|
+
logger.debug(request.env['HTTP_ACCEPT'])
|
59
|
+
|
60
|
+
if request.env['HTTP_MOBIO_AGENT'] or request.env['HTTP_ACCEPT']=~/application\/pxml/
|
61
|
+
@client="xf"
|
62
|
+
elsif ((request.env['HTTP_ACCEPT']=~/wml/) ||
|
63
|
+
(request.env['HTTP_ACCEPT']=~/wap/) )
|
64
|
+
@client="wap"
|
65
|
+
else
|
66
|
+
@client="html"
|
67
|
+
end
|
68
|
+
|
69
|
+
if @client == "xf"
|
70
|
+
headers.delete("Cache-Control")
|
71
|
+
headers['Content-Type']="application/mform"
|
72
|
+
@body = request.body.read.to_s if request.body
|
73
|
+
if request.env['REQUEST_METHOD'] == "POST" and @body
|
74
|
+
paramsFromXml(@body,'data')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# now check client version
|
79
|
+
#
|
80
|
+
@client_version = request.env['HTTP_CLIENT_INFO_URL']? '0.8' : '0.6'
|
81
|
+
|
82
|
+
# check if it's Window Mobile family
|
83
|
+
@client_family = request.env['HTTP_MOBIO_AGENT']=~/WM5/? 'wm': 'other'
|
84
|
+
|
85
|
+
# get user_id
|
86
|
+
@user_id=request.env['HTTP_USERID']
|
87
|
+
if (@user_id.nil?)
|
88
|
+
@user_id="101"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# creates params[] array from xml in argument xml
|
94
|
+
def paramsFromXml(xml,parentname)
|
95
|
+
@paramsdoc = Hpricot(xml)
|
96
|
+
|
97
|
+
if not parentname.nil?
|
98
|
+
doc = @paramsdoc.search("/" + parentname + "/*")
|
99
|
+
doc.each do |x|
|
100
|
+
params[(x.name).to_sym]= x.inner_html
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
#== getDeviceAttrValue(attribute, default)
|
107
|
+
#=== To get the value for a device attribute
|
108
|
+
# This utility queries the device capability service to get the value for
|
109
|
+
# a particular device attribute.
|
110
|
+
#
|
111
|
+
#=== Sample device url:
|
112
|
+
# http://homer.mobiolabs.com/gateway/public/clientServices/getCapability?id=.0.6.28:SonyEriccson:K750i
|
113
|
+
#=== Sample device attributes:
|
114
|
+
# <mob:Client>
|
115
|
+
# <mob:client-id>.0.6.28:Sony-Ericsson:Z800</mob:client-id>
|
116
|
+
# <mob:name>Sony-Ericsson/Z800</mob:name>
|
117
|
+
# <mob:height>220</mob:height>
|
118
|
+
# <mob:width>176</mob:width>
|
119
|
+
# <mob:bit-depth>0</mob:bit-depth>
|
120
|
+
# <mob:memory>1.5 MB</mob:memory>
|
121
|
+
# <mob:memory-heap>0</mob:memory-heap>
|
122
|
+
# <mob:memory-rms>0</mob:memory-rms>
|
123
|
+
# </mob:Client>
|
124
|
+
#
|
125
|
+
#=== parameter
|
126
|
+
#* attribute => the device attribute string, ex: "width", "height"
|
127
|
+
#* default => default value if attribute is not available in the client_info_url
|
128
|
+
#
|
129
|
+
#=== return
|
130
|
+
# Value of the attribute
|
131
|
+
#
|
132
|
+
def getDeviceAttrValue(attribute, default)
|
133
|
+
|
134
|
+
if request.env['HTTP_CLIENT_INFO_URL']
|
135
|
+
logger.debug 'HTTP_CLIENT_INFO_URL:'+request.env['HTTP_CLIENT_INFO_URL']
|
136
|
+
begin
|
137
|
+
doc = Hpricot.XML(open(request.env['HTTP_CLIENT_INFO_URL']))
|
138
|
+
value = doc.search("//mob:" + attribute).inner_html
|
139
|
+
if value and not value.empty?
|
140
|
+
default = value
|
141
|
+
end
|
142
|
+
rescue
|
143
|
+
# do nothing
|
144
|
+
end
|
145
|
+
end
|
146
|
+
default
|
147
|
+
end
|
148
|
+
|
149
|
+
#== get_device_info
|
150
|
+
#=== For asset management
|
151
|
+
#
|
152
|
+
#=== Sample device url:
|
153
|
+
# http://xenimage1-3:8080/gateway/public/clientServices/getCapability?id=.0.6.28:Sony-Ericsson:Z800
|
154
|
+
#
|
155
|
+
# All client attributes are stored in Hash plus "iconsize" which is "13" or "17"
|
156
|
+
# If device width is null or 0, it defaults to '176' for asset to work.
|
157
|
+
#
|
158
|
+
def get_device_info
|
159
|
+
device={:iconsize=> "13"}
|
160
|
+
|
161
|
+
if request.env['HTTP_CLIENT_INFO_URL']
|
162
|
+
logger.debug 'HTTP_CLIENT_INFO_URL:'+request.env['HTTP_CLIENT_INFO_URL']
|
163
|
+
begin
|
164
|
+
doc = Hpricot.XML(open(request.env['HTTP_CLIENT_INFO_URL']))
|
165
|
+
|
166
|
+
doc.search("//mob:Client/*").each do |x|
|
167
|
+
if x.inner_html and not x.inner_html.empty?
|
168
|
+
# strip off "mob:"
|
169
|
+
name = x.name[4..-1]
|
170
|
+
device[name.to_sym] = x.inner_html
|
171
|
+
end
|
172
|
+
|
173
|
+
if x.name == "mob:fontsize"
|
174
|
+
if x.inner_html.to_i >=21
|
175
|
+
device[:iconsize] = "17"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
rescue
|
181
|
+
# do nothing
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Make sure we always have a device width for asset to work
|
186
|
+
if device[:width].nil? or device[:width]==0
|
187
|
+
device[:width] = '176'
|
188
|
+
end
|
189
|
+
device
|
190
|
+
end #end get_device_info
|
191
|
+
|
192
|
+
end #end Device_Info
|
193
|
+
|
194
|
+
end #end Mobio
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
=begin
|
19
|
+
This module manages yaml-based configuration sets. Uses some logic from the
|
20
|
+
rfacebook gem.
|
21
|
+
=end
|
22
|
+
module Rmobio
|
23
|
+
module ConfigManager
|
24
|
+
if defined? RAILS_DEFAULT_LOGGER
|
25
|
+
logger = RAILS_DEFAULT_LOGGER
|
26
|
+
else
|
27
|
+
logger = nil
|
28
|
+
end
|
29
|
+
begin
|
30
|
+
app_yaml_file = YAML.load_file("#{RAILS_ROOT}/config/rmobio.yml")
|
31
|
+
rescue Exception => e
|
32
|
+
raise StandardError, "config/rmobio.yml could not be loaded."
|
33
|
+
end
|
34
|
+
|
35
|
+
if app_yaml_file
|
36
|
+
if app_yaml_file[RAILS_ENV]
|
37
|
+
MOBIO_CONFIG = app_yaml_file[RAILS_ENV]
|
38
|
+
|
39
|
+
# Replace all properties containing @somekey@ with the value of
|
40
|
+
# "somekey"
|
41
|
+
MOBIO_CONFIG.each do |key, value|
|
42
|
+
filter_value = value.to_s.strip
|
43
|
+
filter_key = /@(.*)@/.match(filter_value).to_s.strip
|
44
|
+
if not filter_key.nil? and not filter_key == ''
|
45
|
+
filter_key = filter_key.gsub(/@/,'')
|
46
|
+
if not filter_key.nil? and not filter_value.nil? and not filter_key == ''
|
47
|
+
filter_value = filter_value.gsub(/@.*@/, MOBIO_CONFIG[filter_key.strip])
|
48
|
+
logger.debug('filtered key: ' + key + ' filtered value: ' + filter_value) unless logger.nil?
|
49
|
+
MOBIO_CONFIG[key] = filter_value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
raise StandardError, "config/rmobio.yml exists, but doesn't have a configuration for RAILS_ENV=#{RAILS_ENV}."
|
55
|
+
end
|
56
|
+
else
|
57
|
+
raise StandardError, "config/rmobio.yml does not exist."
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Now we want to initialize the MOBIO_CONFIG constant
|
63
|
+
include Rmobio::ConfigManager
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'rake'
|
19
|
+
require 'rake/clean'
|
20
|
+
require 'rake/testtask'
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
require 'tasks/rails'
|
23
|
+
require 'rake/gempackagetask'
|
24
|
+
require 'rake/rdoctask'
|
25
|
+
require 'fileutils'
|
26
|
+
require 'rcov/rcovtask'
|
27
|
+
|
28
|
+
CLEAN.include('pkg/*')
|
29
|
+
CLEAN.include('coverage/*')
|
30
|
+
|
31
|
+
# BEGIN CRUISE SECTION
|
32
|
+
def get_version
|
33
|
+
if not defined? PKG_VERSION
|
34
|
+
@version = `svnversion #{RAILS_ROOT}`
|
35
|
+
if @version.nil? || @version == 'exported'
|
36
|
+
@version = '1.0.0'
|
37
|
+
else
|
38
|
+
@version =~ /([0-9]+)/
|
39
|
+
@version = $1
|
40
|
+
if @version.nil?
|
41
|
+
@version = '1.0.0'
|
42
|
+
else
|
43
|
+
@version = '1.0.' + @version
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
@version = PKG_VERSION
|
48
|
+
end
|
49
|
+
@version
|
50
|
+
end
|
51
|
+
|
52
|
+
task :reconnect do
|
53
|
+
require 'active_record'
|
54
|
+
configurations = ActiveRecord::Base.configurations
|
55
|
+
if configurations and configurations.has_key?("test") and configurations["test"]["adapter"] == 'mysql'
|
56
|
+
ActiveRecord::Base.establish_connection(:test)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
task :install_gem do
|
61
|
+
target = ENV['GEM_INSTALL_DIR']
|
62
|
+
unless target.nil?
|
63
|
+
cp("pkg/" + PKG_NAME + "-" + get_version + ".gem", target)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
task :package_gem do
|
68
|
+
ENV['RAILS_ENV'] = 'test'
|
69
|
+
spec = Gem::Specification.new do |s|
|
70
|
+
if not defined? DEP_ADD
|
71
|
+
DEP_ADD = true
|
72
|
+
end
|
73
|
+
s.name = PKG_NAME
|
74
|
+
s.version = get_version
|
75
|
+
s.authors = PKG_AUTHORS
|
76
|
+
s.email = PKG_EMAILS
|
77
|
+
s.homepage = PKG_HOMEPAGE
|
78
|
+
s.platform = Gem::Platform::RUBY
|
79
|
+
s.summary = PKG_SUMMARY
|
80
|
+
s.description = PKG_DESCRIPTION
|
81
|
+
if not defined? PKG_INCLUDE
|
82
|
+
s.files = FileList.new('**/*').to_a
|
83
|
+
else
|
84
|
+
s.files = FileList[PKG_INCLUDE].to_a
|
85
|
+
end
|
86
|
+
s.has_rdoc = false
|
87
|
+
s.add_dependency("rmobio", ">= 1.1.0") unless DEP_ADD == false
|
88
|
+
s.add_dependency("hpricot", ">= 0.6")
|
89
|
+
end
|
90
|
+
|
91
|
+
Rake::GemPackageTask.new(spec) do |p|
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
task :rcov do
|
96
|
+
Rcov::RcovTask.new do |t|
|
97
|
+
t.rcov_opts << '-T --rails'
|
98
|
+
t.libs << 'test'
|
99
|
+
t.test_files = FileList['test/*/*_test.rb']
|
100
|
+
t.verbose = true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
task :cruise =>[:clean, 'db:test:purge', 'reconnect', 'db:migrate', :rcov, :package_gem, :package, :install_gem] do
|
105
|
+
end
|
106
|
+
# END CRUISE SECTION
|
107
|
+
|
108
|
+
# BEGIN CONFIG SECTION
|
109
|
+
namespace :rmobio do
|
110
|
+
desc "Set up the rmobio.yml configuration file. This is put into config/rmobio.yml.
|
111
|
+
Using similar logic to the rfacebook plugin."
|
112
|
+
task :setup do
|
113
|
+
|
114
|
+
filename = "#{RAILS_ROOT}/config/rmobio.yml"
|
115
|
+
puts "Setting up rmobio configuration file: config/rmobio.yml"
|
116
|
+
|
117
|
+
file = File.new(filename, "w")
|
118
|
+
file <<
|
119
|
+
"
|
120
|
+
development:
|
121
|
+
app_server_external: http://someexternalhost:someport
|
122
|
+
app_server_internal: http://somehost:someport
|
123
|
+
#example of a filtered property
|
124
|
+
service_base_url: @app_server_external@/service
|
125
|
+
|
126
|
+
test:
|
127
|
+
app_server_external: http://someexternalhost:someport
|
128
|
+
app_server_internal: http://somehost:someport
|
129
|
+
#example of a filtered property
|
130
|
+
service_base_url: @app_server_external@/service
|
131
|
+
|
132
|
+
production:
|
133
|
+
app_server_external: http://someexternalhost:someport
|
134
|
+
app_server_internal: http://somehost:someport
|
135
|
+
#example of a filtered property
|
136
|
+
service_base_url: @app_server_external@/service
|
137
|
+
"
|
138
|
+
file.close_write
|
139
|
+
puts " [1] Created config/rmobio.yml <-- Please add the appropriate configuration options for your application!"
|
140
|
+
puts "Done."
|
141
|
+
end
|
142
|
+
end
|
143
|
+
# END CONFIG SECTION
|
data/lib/rmobio/utils.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
=begin
|
19
|
+
Some summary should go here
|
20
|
+
=end
|
21
|
+
|
22
|
+
#require 'rexml/document'
|
23
|
+
require 'open-uri'
|
24
|
+
require 'hpricot'
|
25
|
+
|
26
|
+
module Rmobio
|
27
|
+
module Utils
|
28
|
+
|
29
|
+
#== cachControl
|
30
|
+
#=== Adding cache control to response header
|
31
|
+
def cacheControl(cacheStr='priority=P3;max-age=604800')
|
32
|
+
headers.delete("Cache-Control");
|
33
|
+
headers["Cache-Control"] = cacheStr;
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#== cacheloader
|
38
|
+
#=== A utility method to add cache control to images, styles and files
|
39
|
+
# To add a cache control, edit the configuration file 'cachehints.txt' with
|
40
|
+
# filename and header. Here is a ample configuration:
|
41
|
+
#
|
42
|
+
#
|
43
|
+
#<tt>logo.png: priority=P2;max-age=1296000</tt>
|
44
|
+
#
|
45
|
+
#<tt>base.rhtml: priority=P2;max-age=1296000</tt>
|
46
|
+
#
|
47
|
+
#
|
48
|
+
# The utility assumes base directory for images files in RAILS_ROOT/public/images
|
49
|
+
# and other files in RAILS_ROOT/apps/views.
|
50
|
+
#
|
51
|
+
#
|
52
|
+
# To access the image in your xform, use the following pattern:
|
53
|
+
#<tt><icon>recipe/loader?name=logo.png</icon></tt>
|
54
|
+
# To access the style in your xform, use the following pattern:
|
55
|
+
#<tt><style xmlns="http://www.mobio.com/ext" src="recipe/loader?name=layouts/base.rhtml"/></tt>
|
56
|
+
#
|
57
|
+
# where the controller 'recipe' should provide a method 'loader' that calls this
|
58
|
+
# utility:
|
59
|
+
# def loader
|
60
|
+
# cacheloader
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
def cacheloader
|
64
|
+
if (name=params[:name]).nil?
|
65
|
+
# Can't do anything, just return empty content so we don't get
|
66
|
+
# 'no template' error.
|
67
|
+
render :text => ''
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
# Default cache configuration file
|
72
|
+
cache_hints = File::join RAILS_ROOT, 'public/cachehints.txt'
|
73
|
+
|
74
|
+
# Add cache header
|
75
|
+
headers.delete("Cache-Control")
|
76
|
+
if File.file?(cache_hints)
|
77
|
+
file = File.new(cache_hints,"r")
|
78
|
+
hintsTxt = file.read(File.size(cache_hints))
|
79
|
+
file.close()
|
80
|
+
hintsTxt.each_line do |line|
|
81
|
+
if line.index(name) == 0
|
82
|
+
line.scan(/(.*):(.*)/) do |garbage, ccheader|
|
83
|
+
headers["Cache-Control"] = ccheader.strip
|
84
|
+
end
|
85
|
+
break
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if name=~ /.png$/
|
91
|
+
# for now hardcode the image directory
|
92
|
+
filePath = File::join RAILS_ROOT, 'public/images/', name
|
93
|
+
file = File.new(filePath,"r")
|
94
|
+
filecontents = file.read(File.size(filePath))
|
95
|
+
file.close()
|
96
|
+
|
97
|
+
headers["Content-Type"] = "image/png"
|
98
|
+
|
99
|
+
render :text => filecontents
|
100
|
+
return
|
101
|
+
elsif name =~ /.xfs$/ or name =~ /.rxf/
|
102
|
+
headers["Content-Type"] = "application/mform"
|
103
|
+
else
|
104
|
+
headers["Content-Type"] = "application/xml"
|
105
|
+
end
|
106
|
+
|
107
|
+
render :template => name
|
108
|
+
end
|
109
|
+
|
110
|
+
#== cacheimg
|
111
|
+
#=== A utility method to add cache control to images
|
112
|
+
#=== This utility is deprecated, use cacheloader instead
|
113
|
+
# To add a cache control for an image file in RAILS_ROOT/public/images, edit
|
114
|
+
# the configuration file "cachehints.txt with image name and header. Ex:
|
115
|
+
#
|
116
|
+
# logo.png: priority=P2;max-age=1296000
|
117
|
+
#
|
118
|
+
# To access the image in your xforms, use the following pattern:
|
119
|
+
# <icon>img?name=logo.png</icon>
|
120
|
+
# Where the controller should provide an img method that just call this cacheimg utility.
|
121
|
+
#
|
122
|
+
# Sample cachehints.txt:
|
123
|
+
# Skins_176A2-a.png: priority=P2;max-age=1296000
|
124
|
+
# logo.png: priority=P2;max-age=1296000
|
125
|
+
#
|
126
|
+
def cacheimg
|
127
|
+
public_folder = File::join RAILS_ROOT, "public/images"
|
128
|
+
filePath = File::join RAILS_ROOT, "public/images", params['name']
|
129
|
+
file = File.new(filePath,"r")
|
130
|
+
filecontents = file.read(File.size(filePath))
|
131
|
+
file.close()
|
132
|
+
|
133
|
+
|
134
|
+
headers["Content-Type"] = "image/png"
|
135
|
+
headers.delete("Cache-Control")
|
136
|
+
fileDir = File.dirname(filePath)
|
137
|
+
fileName = File.basename(filePath)
|
138
|
+
hints = File::join fileDir, "cachehints.txt"
|
139
|
+
if File.file?(hints)
|
140
|
+
file = File.new(hints,"r")
|
141
|
+
hintsTxt = file.read(File.size(hints))
|
142
|
+
file.close()
|
143
|
+
hintsTxt.each_line do |line|
|
144
|
+
if line.index(fileName) == 0
|
145
|
+
line.scan(/(.*):(.*)/) do |garbage, ccheader|
|
146
|
+
headers["Cache-Control"] = ccheader.strip
|
147
|
+
end
|
148
|
+
break
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
render :text => filecontents
|
153
|
+
end
|
154
|
+
|
155
|
+
#== backURL(key)
|
156
|
+
# This utility handles back url to GLP if page is cached.
|
157
|
+
# It expects params[:burl] or a session key and renders
|
158
|
+
# the following xml data back to the caller:
|
159
|
+
#
|
160
|
+
# <data xmlns="">
|
161
|
+
# <burl>blah blah url</burl>
|
162
|
+
# </data>
|
163
|
+
#
|
164
|
+
# The returned instance data <burl> is determined by the following rules:
|
165
|
+
#* params[:burl] if parameter exists, the url in the session is also updated
|
166
|
+
#* session[:key] if params[:burl] is nil
|
167
|
+
#* empty string if none of the above
|
168
|
+
#
|
169
|
+
#
|
170
|
+
# To access the backurl from your xfroms, use the following pattern:
|
171
|
+
#
|
172
|
+
# <xf:instance id="homepage" src="storeBackurl?burl=SOMEURL" />
|
173
|
+
#
|
174
|
+
# Where the controller should provide a "storeBackurl" method that just call this backURL utility:
|
175
|
+
# def storeBackurl
|
176
|
+
# backURL("recipe_burl")
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
#=== Parameter
|
180
|
+
# key => a unique session key to store the burl for the app
|
181
|
+
#
|
182
|
+
def backURL(key)
|
183
|
+
url = backurl_xml(key)
|
184
|
+
headers['Content-Type']='application/xml'
|
185
|
+
render :text => "<data xmlns=\"\">" + url + "</data>"
|
186
|
+
end # end backURLg
|
187
|
+
|
188
|
+
# if you want to just return partial backurl without headers and no rendering
|
189
|
+
def backurl_xml(key)
|
190
|
+
if params[:burl]
|
191
|
+
url = params[:burl].gsub(/&/,'&')
|
192
|
+
session[key] = url
|
193
|
+
elsif session[key]
|
194
|
+
url = session[key]
|
195
|
+
else
|
196
|
+
# don't know what to do, just return an empty url
|
197
|
+
url = ''
|
198
|
+
end
|
199
|
+
logger.debug('back url ' + key + ': ' + url)
|
200
|
+
"<burl>" + url + "</burl>"
|
201
|
+
end # end backurl_xml
|
202
|
+
|
203
|
+
def logHeaders
|
204
|
+
logger.debug( "Logging Headers...")
|
205
|
+
request.env.keys.each do |header|
|
206
|
+
logger.debug( header.to_s + ': ' + request.env[header].to_s)
|
207
|
+
end
|
208
|
+
logger.debug("End of Headers...")
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
end #end Utils
|
213
|
+
end #end Mobio
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
###
|
19
|
+
# This class uses class-based-instance variables to store a driver
|
20
|
+
# for each type of WSDL based webservice that needs to be accessed.
|
21
|
+
# :author Nate Agrin
|
22
|
+
###
|
23
|
+
|
24
|
+
require 'soap/wsdlDriver'
|
25
|
+
|
26
|
+
module Rmobio
|
27
|
+
module WebServices
|
28
|
+
class WsdlDriver
|
29
|
+
# class-level-instance variables
|
30
|
+
# see http://wiseheartdesign.com/2006/9/22/class-level-instance-variables/
|
31
|
+
@wsdl = nil
|
32
|
+
@driver = nil
|
33
|
+
|
34
|
+
# class level methods
|
35
|
+
class << self
|
36
|
+
attr_accessor :wsdl, :driver
|
37
|
+
|
38
|
+
# sets the wsdl variable and attempts to create a SOAP::WSDLDriver object
|
39
|
+
def wsdl=(wsdl)
|
40
|
+
@wsdl = wsdl
|
41
|
+
@driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# instance method for returning the underlying rpc_driver
|
46
|
+
def driver
|
47
|
+
self.class.driver
|
48
|
+
end
|
49
|
+
|
50
|
+
# instance method for returning the underlying wsdl address
|
51
|
+
def wsdl
|
52
|
+
self.class.wsdl
|
53
|
+
end
|
54
|
+
|
55
|
+
# this may not be very useful because responses require interpertation
|
56
|
+
def method_missing(method_id, *args)
|
57
|
+
driver.send method_id, args if driver.respond_to?(method_id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2007 Mobio Networks, Inc.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#
|
17
|
+
|
18
|
+
class Geocode < Mobio::WebServices::WsdlDriver
|
19
|
+
end
|