Module: Rmobio::ClientInfo
- Defined in:
- lib/rmobio/client_info.rb
Instance Method Summary collapse
-
#checkClient ⇒ Object
checkClient === The method checks the client type, version and family by analyzing the request header.
-
#get_device_info ⇒ Object
get_device_info === For asset management === Sample device url: dev.getmobio.com/hub/devicecap/devices/capability?id=1.0.5:Motorola:V3m.
-
#getDeviceAttrValue(attribute, default) ⇒ Object
getDeviceAttrValue(attribute, default) === To get the value for a device attribute This utility queries the device capability service to get the value for a particular device attribute.
-
#paramsFromXml(xml, parentname) ⇒ Object
creates params[] array from xml in argument xml.
Instance Method Details
#checkClient ⇒ Object
checkClient
The method checks the client type, version and family by analyzing the request header.
HTTP_ACCEPT
-
If header contains application/pxml => ‘xf’ (xforms client)
-
If header contains wml or wap => ‘wap’
-
If header contains applicaton/html => ‘html’
-
Otherwise, default to html => ‘html’
If xf cient, the “POST” parameters are parsed to name/value pairs in params
HTTP_CLIENT_INFO_URL
-
If header exists => 0.8 client
-
If header doesn’t exist => 0.6 client
Sample of what HTTP_CLIENT_INFO_URL returns: dev.getmobio.com/hub/devicecap/devices/capability?id=1.0.5:Motorola:V3m
HTTP_MOBIO_AGENT
-
If header contains WM5 => Window Mobile family
Return Codes
The method returns the following instance varables: params[] => array contains name/value pairs of all parameters from POST request
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 |
# File 'lib/rmobio/client_info.rb', line 56 def checkClient logger.debug('checkClient http_accept header:') logger.debug(request.env['HTTP_ACCEPT']) if request.env['HTTP_MOBIO_AGENT'] or request.env['HTTP_ACCEPT']=~/application\/pxml/ @client="xf" elsif (request.env['HTTP_ACCEPT']=~/application\/xhtml/) headers['Content-Type']="text/html" @client = "xhtml" elsif ((request.env['HTTP_ACCEPT']=~/wml/) || (request.env['HTTP_ACCEPT']=~/wap/) ) @client="wap" else headers['Content-Type']="text/html" @client="html" end # Get the rxml transformer for the client type @xml = TransformerFactory::get_transformer(@client) if @client == "xf" headers.delete("Cache-Control") headers['Content-Type']="application/mform" @body = request.body.read.to_s if request.body if request.env['REQUEST_METHOD'] == "POST" and @body paramsFromXml(@body,'data') end end # now check client version # @client_version = request.env['HTTP_CLIENT_INFO_URL']? '0.8' : '0.6' # check if it's Window Mobile family @client_family = request.env['HTTP_MOBIO_AGENT']=~/WM5/? 'wm': 'other' # get user_id @user_id=request.env['HTTP_USERID'] if (@user_id.nil?) @user_id="101" end end |
#get_device_info ⇒ Object
get_device_info
For asset management
Sample device url:
dev.getmobio.com/hub/devicecap/devices/capability?id=1.0.5:Motorola:V3m
All client attributes are stored in Hash plus “iconsize” which is “13” or “17” If device width is null or 0, it defaults to ‘176’ for asset to work.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rmobio/client_info.rb', line 164 def get_device_info device={:iconsize=> "13"} if request.env['HTTP_CLIENT_INFO_URL'] logger.debug 'HTTP_CLIENT_INFO_URL:'+request.env['HTTP_CLIENT_INFO_URL'] begin doc = Hpricot.XML(open(request.env['HTTP_CLIENT_INFO_URL'])) doc.search("//mob:Client/*").each do |x| if x.inner_html and not x.inner_html.empty? # strip off "mob:" name = x.name[4..-1] device[name.to_sym] = x.inner_html end if x.name == "mob:fontsize" if x.inner_html.to_i >=21 device[:iconsize] = "17" end end end rescue # do nothing end end # Make sure we always have a device width for asset to work if device[:width].nil? or device[:width]==0 device[:width] = '176' end device end |
#getDeviceAttrValue(attribute, default) ⇒ Object
getDeviceAttrValue(attribute, default)
To get the value for a device attribute
This utility queries the device capability service to get the value for a particular device attribute.
Sample device url:
dev.getmobio.com/hub/devicecap/devices/capability?id=1.0.5:Motorola:V3m
Sample device attributes:
<mob:Client>
<mob:client-id>.0.6.28:Sony-Ericsson:Z800</mob:client-id>
<mob:name>Sony-Ericsson/Z800</mob:name>
<mob:height>220</mob:height>
<mob:width>176</mob:width>
<mob:bit-depth>0</mob:bit-depth>
<mob:memory>1.5 MB</mob:memory>
<mob:memory-heap>0</mob:memory-heap>
<mob:memory-rms>0</mob:memory-rms>
</mob:Client>
parameter
-
attribute => the device attribute string, ex: “width”, “height”
-
default => default value if attribute is not available in the client_info_url
return
Value of the attribute
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rmobio/client_info.rb', line 138 def getDeviceAttrValue(attribute, default) if request.env['HTTP_CLIENT_INFO_URL'] logger.debug 'HTTP_CLIENT_INFO_URL:'+request.env['HTTP_CLIENT_INFO_URL'] begin doc = Hpricot.XML(open(request.env['HTTP_CLIENT_INFO_URL'])) value = doc.search("//mob:" + attribute).inner_html if value and not value.empty? default = value end rescue # do nothing end end default end |
#paramsFromXml(xml, parentname) ⇒ Object
creates params[] array from xml in argument xml
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rmobio/client_info.rb', line 100 def paramsFromXml(xml,parentname) @paramsdoc = Hpricot(xml) if not parentname.nil? doc = @paramsdoc.search("/" + parentname + "/*") doc.each do |x| params[(x.name).to_sym]= x.inner_html end end end |