browser_details 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzNjYTU4NzkzMzIyMGY5NGZmNmYyNzI0YjQyZGY0MzQ3MTUxMDdjMg==
5
+ data.tar.gz: !binary |-
6
+ ZDkxYjMxZGIxMDU2YjQ3YzlkYjg5ZjM2ZTAxYzU5MGQ5ODg5NGE5Yw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWNhY2Y4ZWYyZGEwYzcwOTJkZDQ4ZDY0Y2FhOTZlYWYxZmRkNmUzMjJlYzk5
10
+ NjM5ZDExNmE0YjgwMzg1MTczZGI5MDRiZTA0NDJjZjBiMjcwODc4NTJiZGU3
11
+ MDM3NTBiODlmZDU5MTQ5ZmMwNTg4M2ViZmNlYjViZmM0Y2I1YWE=
12
+ data.tar.gz: !binary |-
13
+ MWEwZGYzZGZkZDViNjU4OWE4ZmE4ZWY1N2M0MDAxOTRkMTk0MTAzYWNhMzRl
14
+ MjYxMGYwYmY4ZDUyYjU4NmJiMzk0ZjgxZDMwYjk5MzNjOTc0NWI2Zjk5YmFm
15
+ MzJlZTk3MTYwODM3Yzc1ODhjMTM2YjZiNDJkMGMyMGE2NGVlN2E=
data/README.md CHANGED
@@ -1,9 +1,19 @@
1
1
  # Browser Details
2
2
 
3
- Browser Details is a Rack Middleware that logs information about the browser
4
- used to make a request.
3
+ Have you ever had the conversation:
4
+
5
+ > **Your site doesn't work.**
6
+ > What browser are you using and do you have Javascript enabled?
7
+ >
8
+ > **What's a browser?**
9
+ > :unamused:
10
+
11
+ Browser Details makes that problem disappear by capturing a user's browser
12
+ details in your logs. You will get the exact browser version they are using and
13
+ their OS dumped into your logs, and when possible you'll get whether they have
14
+ JS enabled too. All entirely unobtrustively.
5
15
 
6
- When possible this includes whether the browser has Javascript enabled or not.
16
+ You may never need to speak to a user ever again!
7
17
 
8
18
  ### Before
9
19
 
@@ -17,14 +27,20 @@ When possible this includes whether the browser has Javascript enabled or not.
17
27
  ### After
18
28
 
19
29
  Started GET "/" for 127.0.0.1 at 2012-12-26 21:25:14 +0000
20
- Chrome 23.0.1271.95 (Macintosh)
30
+ Chrome 23.0.1271.95 (Macintosh, Intel Mac OS X 10_7_5)
21
31
  Processing by HomeController#index as HTML
22
32
  ...
23
33
  Started POST "/posts" for 127.0.0.1 at 2012-12-26 21:25:19 +0000
24
- Chrome 23.0.1271.95 (Macintosh), JS enabled
34
+ Chrome 23.0.1271.95 (Macintosh, Intel Mac OS X 10_7_5), JS enabled
25
35
  Processing by PostsController#create as HTML
26
36
  ...
27
37
 
38
+ ### How?
39
+
40
+ Browser Details is a Rack Middleware that logs information about the browser
41
+ used to make a request. When possible this includes whether the browser has
42
+ Javascript enabled or not.
43
+
28
44
  ## Installation
29
45
 
30
46
  Add this line to your application's Gemfile:
@@ -68,6 +84,14 @@ The Javascript detection is currently reliant on Rails. If you would like your
68
84
  application to be able to detect whether Javascript is enabled too, please
69
85
  create an issue, or even better open a pull request.
70
86
 
87
+ ### Custom usage
88
+
89
+ If you want to use the message elsewhere, you can request the message directly:
90
+
91
+ ```ruby
92
+ details = BrowserDetails.message(request)
93
+ ```
94
+
71
95
  ## Contributing
72
96
 
73
97
  1. Fork it
@@ -6,7 +6,6 @@ require "useragent"
6
6
  # Public: Middleware for logging the browser details of each request.
7
7
  #
8
8
  class BrowserDetails
9
-
10
9
  # Set up the log_message method.
11
10
  if defined?(Hatchet)
12
11
  # If Hatchet is defined include it and define a method for its logger.
@@ -49,6 +48,24 @@ class BrowserDetails
49
48
  #
50
49
  def call(env)
51
50
  request = Rack::Request.new(env)
51
+ message = self.class.message(request)
52
+
53
+ # Log a message if any details were gathered.
54
+ unless message.empty?
55
+ log_message(env, message)
56
+ end
57
+
58
+ # Delegate to the application we are wrapping.
59
+ @app.call(env)
60
+ end
61
+
62
+ # Public: Creates a browser details message for a request.
63
+ #
64
+ # request - The Rack::Request to extract brower details from.
65
+ #
66
+ # Returns a String of browser details for the request.
67
+ #
68
+ def self.message(request)
52
69
  message = []
53
70
 
54
71
  # Add the user agent details to the message if present.
@@ -68,23 +85,18 @@ class BrowserDetails
68
85
  # AJAX request - JS probably enabled.
69
86
  message << 'JS enabled'
70
87
  elsif request['utf8']
71
- # Have a utf8 element - check if changed by JS.
88
+ # Have a utf8 parameter - check if changed by JS.
72
89
  message << if request['utf8'] == '✓'
90
+ # Value unchanged - JS was not executed and therefore disabled.
73
91
  'JS disabled'
74
92
  else
93
+ # Value changed - JS was executed and therefore enabled.
75
94
  'JS enabled'
76
95
  end
77
96
  end
78
97
 
79
- # Log a message if any details were gathered.
80
- unless message.empty?
81
- log_message(env, message.join(', '))
82
- end
83
-
84
- # Delegate to the application we are wrapping.
85
- @app.call(env)
98
+ message.join(', ')
86
99
  end
87
-
88
100
  end
89
101
 
90
102
  # Require the Railtie if Rails is present.
@@ -1,5 +1,5 @@
1
1
  class BrowserDetails
2
2
 
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_details
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Garry Shutler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-27 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: useragent
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -43,28 +40,26 @@ files:
43
40
  - README.md
44
41
  homepage: https://github.com/gshutler/browser_details
45
42
  licenses: []
43
+ metadata: {}
46
44
  post_install_message:
47
45
  rdoc_options: []
48
46
  require_paths:
49
47
  - lib
50
48
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
49
  requirements:
53
50
  - - ! '>='
54
51
  - !ruby/object:Gem::Version
55
52
  version: '0'
56
53
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
54
  requirements:
59
55
  - - ! '>='
60
56
  - !ruby/object:Gem::Version
61
57
  version: '0'
62
58
  requirements: []
63
59
  rubyforge_project:
64
- rubygems_version: 1.8.24
60
+ rubygems_version: 2.1.11
65
61
  signing_key:
66
- specification_version: 3
62
+ specification_version: 4
67
63
  summary: Browser Details is a Rack Middleware that logs information about the browser
68
64
  used to make a request
69
65
  test_files: []
70
- has_rdoc: