browser_details 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/lib/browser_details.rb +68 -0
- data/lib/browser_details/assets/browser_details.js +5 -0
- data/lib/browser_details/railtie.rb +13 -0
- data/lib/browser_details/version.rb +3 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Garry Shutler
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Browser Details
|
2
|
+
|
3
|
+
Browser Details is a Rack Middleware that logs information about the browser
|
4
|
+
used to make a request.
|
5
|
+
|
6
|
+
When possible this includes whether the browser has Javascript enabled or not.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'browser_details'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install browser_details
|
21
|
+
|
22
|
+
### Rails
|
23
|
+
|
24
|
+
The middleware will be installed automatically by the Railtie.
|
25
|
+
|
26
|
+
To enable Browser Details to report whether the browser has Javascript enabled
|
27
|
+
for form submissions you must add the following line to your
|
28
|
+
`app/assets/javascripts/application.js`:
|
29
|
+
|
30
|
+
//= require browser_details
|
31
|
+
|
32
|
+
Browser Details requires jQuery to be present as it works by checking if the
|
33
|
+
`utf8` form element has been changed to a large tick from a small tick by the
|
34
|
+
Browser Details Javascript.
|
35
|
+
|
36
|
+
If this script is not added then all browsers will report that Javascript is
|
37
|
+
disabled.
|
38
|
+
|
39
|
+
### Other Rack applications
|
40
|
+
|
41
|
+
To use the Browser Details middleware you must add the line:
|
42
|
+
|
43
|
+
use BrowserDetails
|
44
|
+
|
45
|
+
Wherever it may be appropriate for your application.
|
46
|
+
|
47
|
+
The Javascript detection is currently reliant on Rails. If you would like your
|
48
|
+
application to be able to detect whether Javascript is enabled too, please
|
49
|
+
create an issue, or even better open a pull request.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "browser_details/version"
|
4
|
+
require "useragent"
|
5
|
+
|
6
|
+
class BrowserDetails
|
7
|
+
|
8
|
+
if defined?(Hatchet)
|
9
|
+
include Hatchet
|
10
|
+
|
11
|
+
LOGGER = :hatchet
|
12
|
+
elsif defined?(Rails)
|
13
|
+
LOGGER = :rails
|
14
|
+
else
|
15
|
+
LOGGER = :rack
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(app)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
message = []
|
24
|
+
|
25
|
+
if env['HTTP_USER_AGENT']
|
26
|
+
agent = UserAgent.parse(env['HTTP_USER_AGENT'])
|
27
|
+
|
28
|
+
agent_details = [agent.browser]
|
29
|
+
agent_details << 'Mobile' if agent.mobile?
|
30
|
+
agent_details << agent.version
|
31
|
+
agent_details << "(#{agent.platform})"
|
32
|
+
|
33
|
+
message << agent_details.join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
request = Rack::Request.new(env)
|
37
|
+
|
38
|
+
if request['utf8']
|
39
|
+
message << if request['utf8'] == '✓'
|
40
|
+
'JS disabled'
|
41
|
+
else
|
42
|
+
'JS enabled'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
unless message.empty?
|
47
|
+
log_message(env, message.join(', '))
|
48
|
+
end
|
49
|
+
|
50
|
+
@app.call(env)
|
51
|
+
end
|
52
|
+
|
53
|
+
def log_message(env, message)
|
54
|
+
case LOGGER
|
55
|
+
when :hatchet
|
56
|
+
log.info(message)
|
57
|
+
when :rails
|
58
|
+
Rails.logger.info(message)
|
59
|
+
when :rack
|
60
|
+
if env['rack.logger']
|
61
|
+
env['rack.logger'].info(message)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
require 'browser_details/railtie' if defined?(Rails)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class BrowserDetails
|
2
|
+
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "browser_details.insert_middleware" do |app|
|
5
|
+
app.config.middleware.use BrowserDetails
|
6
|
+
end
|
7
|
+
|
8
|
+
config.before_configuration do |app|
|
9
|
+
app.config.assets.paths << File.join(File.dirname(__FILE__), 'assets')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: browser_details
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Garry Shutler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: useragent
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.4'
|
30
|
+
description: ! "\n Browser Details is a Rack Middleware that logs information about
|
31
|
+
the browser\n used to make a request\n "
|
32
|
+
email:
|
33
|
+
- garry@robustsoftware.co.uk
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- lib/browser_details/assets/browser_details.js
|
39
|
+
- lib/browser_details/railtie.rb
|
40
|
+
- lib/browser_details/version.rb
|
41
|
+
- lib/browser_details.rb
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
homepage: https://github.com/gshutler/browser_details
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.24
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Browser Details is a Rack Middleware that logs information about the browser
|
68
|
+
used to make a request
|
69
|
+
test_files: []
|
70
|
+
has_rdoc:
|