user_agent_info 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
@@ -0,0 +1,18 @@
1
+ = UserAgentInfo
2
+
3
+ == simplify user-agent detection in Rails
4
+
5
+ == Usage
6
+
7
+ It extends ActionController::Request and parses the requests HTTP_USER_AGENT header so it can be queried.
8
+ The supported browsers are IE, Firefox, Chrome, Opera this translates into the methods isIE?, isFirefox?, isChrome, isOpera?
9
+ You can also supply a version like isIE?('6.0') and you can query if it is worse or/and better then a version isIE_or_worse?('6.0')
10
+
11
+ === Example
12
+ class UpgradeBrowserController < ApplicationController
13
+ def index
14
+ @upgrade = request.user_agent_info.isIE_or_worse?('6.0')
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |s|
4
+ s.name = "user_agent_info"
5
+ s.summary = "Simplifies user-agent detection"
6
+ s.email = "mehmet@celik.be"
7
+ s.homepage = "http://github.com/mehmetc/user_agent_info"
8
+ s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
9
+ s.authors = ["Mehmet Celik"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
12
+ rescue LoadError
13
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: ActionController</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">ActionController</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ </td>
59
+ </tr>
60
+
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
@@ -0,0 +1,140 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: ActionController::Request</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">ActionController::Request</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/user_agent_info_rb.html">
59
+ lib/user_agent_info.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <hr size="1"></hr>
83
+ </div>
84
+
85
+
86
+ </div>
87
+
88
+ <div id="method-list">
89
+ <h3 class="section-bar">Methods</h3>
90
+
91
+ <div class="name-list">
92
+ <a href="#M000001">user_agent_info</a>&nbsp;&nbsp;
93
+ </div>
94
+ </div>
95
+
96
+ </div>
97
+
98
+
99
+ <!-- if includes -->
100
+
101
+ <div id="section">
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ <!-- if method_list -->
111
+ <div id="methods">
112
+ <h3 class="section-bar">Public Instance methods</h3>
113
+
114
+ <div id="method-M000001" class="method-detail">
115
+ <a name="M000001"></a>
116
+
117
+ <div class="method-heading">
118
+ <a href="Request.src/M000001.html" target="Code" class="method-signature"
119
+ onclick="popupCode('Request.src/M000001.html');return false;">
120
+ <span class="method-name">user_agent_info</span><span class="method-args">()</span>
121
+ </a>
122
+ </div>
123
+
124
+ <div class="method-description">
125
+ </div>
126
+ </div>
127
+
128
+
129
+ </div>
130
+
131
+
132
+ </div>
133
+
134
+
135
+ <div id="validator-badges">
136
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
137
+ </div>
138
+
139
+ </body>
140
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>user_agent_info (ActionController::Request)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/user_agent_info.rb, line 190</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">user_agent_info</span>
15
+ <span class="ruby-constant">UserAgentInfo</span><span class="ruby-operator">::</span><span class="ruby-constant">UserAgent</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,138 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: UserAgentInfo</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">UserAgentInfo</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/user_agent_info_rb.html">
59
+ lib/user_agent_info.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+ <div id="description">
76
+ <h1><a href="UserAgentInfo.html">UserAgentInfo</a></h1>
77
+ <h2>simplify user-agent detection in Rails</h2>
78
+ <table>
79
+ <tr><td valign="top">Author:</td><td>Mehmet Celik
80
+
81
+ </td></tr>
82
+ </table>
83
+ <h2>Usage</h2>
84
+ <p>
85
+ It extends ActionController::Request and parses the requests
86
+ HTTP_USER_AGENT header so it can be queried. The supported browsers are IE,
87
+ Firefox, Chrome, Opera this translates into the methods isIE?, isFirefox?,
88
+ isChrome, isOpera? You can also supply a version like
89
+ isIE?(&#8216;6.0&#8217;) and you can query if it is worse or/and better
90
+ then a version isIE_or_worse?(&#8216;6.0&#8217;)
91
+ </p>
92
+ <h3>Example</h3>
93
+ <pre>
94
+ class UpgradeBrowserController &lt; ApplicationController
95
+ def index
96
+ @upgrade = request.user_agent_info.isIE_or_worse?('6.0')
97
+ end
98
+ end
99
+ </pre>
100
+
101
+ </div>
102
+
103
+
104
+ </div>
105
+
106
+
107
+ </div>
108
+
109
+
110
+ <!-- if includes -->
111
+
112
+ <div id="section">
113
+
114
+ <div id="class-list">
115
+ <h3 class="section-bar">Classes and Modules</h3>
116
+
117
+ Class <a href="UserAgentInfo/UserAgent.html" class="link">UserAgentInfo::UserAgent</a><br />
118
+
119
+ </div>
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ <!-- if method_list -->
128
+
129
+
130
+ </div>
131
+
132
+
133
+ <div id="validator-badges">
134
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
135
+ </div>
136
+
137
+ </body>
138
+ </html>
@@ -0,0 +1,234 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: UserAgentInfo::UserAgent</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">UserAgentInfo::UserAgent</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/user_agent_info_rb.html">
59
+ lib/user_agent_info.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000001">[]</a>&nbsp;&nbsp;
90
+ <a href="#M000004">isChrome?</a>&nbsp;&nbsp;
91
+ <a href="#M000003">isFirefox?</a>&nbsp;&nbsp;
92
+ <a href="#M000002">isIE?</a>&nbsp;&nbsp;
93
+ <a href="#M000005">isOpera?</a>&nbsp;&nbsp;
94
+ </div>
95
+ </div>
96
+
97
+ </div>
98
+
99
+
100
+ <!-- if includes -->
101
+
102
+ <div id="section">
103
+
104
+
105
+
106
+
107
+
108
+ <div id="attribute-list">
109
+ <h3 class="section-bar">Attributes</h3>
110
+
111
+ <div class="name-list">
112
+ <table>
113
+ <tr class="top-aligned-row context-row">
114
+ <td class="context-item-name">browser_info</td>
115
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
116
+ <td class="context-item-desc"></td>
117
+ </tr>
118
+ </table>
119
+ </div>
120
+ </div>
121
+
122
+
123
+
124
+ <!-- if method_list -->
125
+ <div id="methods">
126
+ <h3 class="section-bar">Public Instance methods</h3>
127
+
128
+ <div id="method-M000001" class="method-detail">
129
+ <a name="M000001"></a>
130
+
131
+ <div class="method-heading">
132
+ <a href="UserAgent.src/M000001.html" target="Code" class="method-signature"
133
+ onclick="popupCode('UserAgent.src/M000001.html');return false;">
134
+ <span class="method-name">[]</span><span class="method-args">(lookup)</span>
135
+ </a>
136
+ </div>
137
+
138
+ <div class="method-description">
139
+ <p>
140
+ query user_agent_info
141
+ </p>
142
+ <pre>
143
+ request.user_agent_info['header'] ==&gt; Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4
144
+ request.user_agent_info['platform'] ==&gt; Macintosh
145
+ request.user_agent_info['name'] ==&gt; Firefox
146
+ request.user_agent_info['name_display'] ==&gt; Mozilla Firefox
147
+ request.user_agent_info['cpuos'] ==&gt; Intel Mac OS X 10.5
148
+ request.user_agent_info['language'] ==&gt; en-US
149
+ request.user_agent_info['version'] ==&gt; 3.5
150
+ request.user_agent_info['engine'] ==&gt; Gecko/20091016
151
+ </pre>
152
+ </div>
153
+ </div>
154
+
155
+ <div id="method-M000004" class="method-detail">
156
+ <a name="M000004"></a>
157
+
158
+ <div class="method-heading">
159
+ <a href="UserAgent.src/M000004.html" target="Code" class="method-signature"
160
+ onclick="popupCode('UserAgent.src/M000004.html');return false;">
161
+ <span class="method-name">isChrome?</span><span class="method-args">(version = nil)</span>
162
+ </a>
163
+ </div>
164
+
165
+ <div class="method-description">
166
+ </div>
167
+ </div>
168
+
169
+ <div id="method-M000003" class="method-detail">
170
+ <a name="M000003"></a>
171
+
172
+ <div class="method-heading">
173
+ <a href="UserAgent.src/M000003.html" target="Code" class="method-signature"
174
+ onclick="popupCode('UserAgent.src/M000003.html');return false;">
175
+ <span class="method-name">isFirefox?</span><span class="method-args">(version = nil)</span>
176
+ </a>
177
+ </div>
178
+
179
+ <div class="method-description">
180
+ </div>
181
+ </div>
182
+
183
+ <div id="method-M000002" class="method-detail">
184
+ <a name="M000002"></a>
185
+
186
+ <div class="method-heading">
187
+ <a href="UserAgent.src/M000002.html" target="Code" class="method-signature"
188
+ onclick="popupCode('UserAgent.src/M000002.html');return false;">
189
+ <span class="method-name">isIE?</span><span class="method-args">(version = nil)</span>
190
+ </a>
191
+ </div>
192
+
193
+ <div class="method-description">
194
+ <p>
195
+ check if browser is Internet Explorer
196
+ </p>
197
+ <pre>
198
+ request.user_agent_info.isIE? ==&gt; true if browser is Internet Explorer &lt;br /&gt;
199
+ request.user_agent_info.isIE?('6.0') ==&gt; true if browser is Internet Explorer version 6.0 '=='
200
+ request.user_agent_info.isIE_or_worse?('6.0') ==&gt; true if browser is Internet Explorer version worse or equal to 6.0 '&lt;='
201
+ request.user_agent_info.isIE_and_worse?('6.0') ==&gt; true if browser is Internet Explorer version worse then 6.0 '&lt;'
202
+ request.user_agent_info.isIE_or_better?('6.0') ==&gt; true if browser is Internet Explorer version better or equal to 6.0 '&gt;='
203
+ request.user_agent_info.isIE_and_better?('6.0') ==&gt; true if browser is Internet Explorer version better then 6.0 '&gt;'
204
+ </pre>
205
+ </div>
206
+ </div>
207
+
208
+ <div id="method-M000005" class="method-detail">
209
+ <a name="M000005"></a>
210
+
211
+ <div class="method-heading">
212
+ <a href="UserAgent.src/M000005.html" target="Code" class="method-signature"
213
+ onclick="popupCode('UserAgent.src/M000005.html');return false;">
214
+ <span class="method-name">isOpera?</span><span class="method-args">(version = nil)</span>
215
+ </a>
216
+ </div>
217
+
218
+ <div class="method-description">
219
+ </div>
220
+ </div>
221
+
222
+
223
+ </div>
224
+
225
+
226
+ </div>
227
+
228
+
229
+ <div id="validator-badges">
230
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
231
+ </div>
232
+
233
+ </body>
234
+ </html>