JamieFlournoy-user_agent 1.0.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/History.txt +3 -0
- data/Manifest.txt +6 -0
- data/README.txt +60 -0
- data/Rakefile +15 -0
- data/lib/user_agent.rb +8 -0
- data/test/test_user_agent.rb +24 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= UserAgent
|
2
|
+
|
3
|
+
http://github.com/jamieflournoy/UserAgent
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Determine whether the HTTP user agent talking to your code is a web spider.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
All you can do at this point is call UserAgent.is_spider? and pass it the user agent.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
If you're using Rails, require the gem in config/environment.rb like this:
|
16
|
+
|
17
|
+
config.gem 'jamieflournoy-UserAgent', :lib => 'user_agent'
|
18
|
+
|
19
|
+
and create an initializer at config/initializers/user_agent.rb and paste this into it:
|
20
|
+
|
21
|
+
class ApplicationController < ActionController::Base
|
22
|
+
session :off, :if => proc { |request| UserAgent.is_spider?(request.user_agent) }
|
23
|
+
end
|
24
|
+
|
25
|
+
Otherwise just ask UserAgent.is_spider? and pass it the user agent string.
|
26
|
+
|
27
|
+
== REQUIREMENTS:
|
28
|
+
|
29
|
+
To run the tests you will need Shoulda.
|
30
|
+
|
31
|
+
sudo gem install shoulda
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
sudo gem install jamieflournoy-UserAgent
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) 2009
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.spec 'user_agent' do
|
7
|
+
developer('Jamie Flournoy', 'jamie@pervasivecode.com')
|
8
|
+
end
|
9
|
+
|
10
|
+
# vim: syntax=ruby
|
11
|
+
|
12
|
+
# From http://blog.behindlogic.com/2008/10/auto-generate-your-manifest-and-gemspec.html
|
13
|
+
task :cultivate do
|
14
|
+
system "rake debug_gem | grep -v \"(in \" > `basename \\`pwd\\``.gemspec"
|
15
|
+
end
|
data/lib/user_agent.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "user_agent"
|
3
|
+
|
4
|
+
class TestUserAgent < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@agent_strings = {
|
7
|
+
:googlebot => "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
8
|
+
:msnbot => "msnbot/1.1 (+http://search.msn.com/msnbot.htm)",
|
9
|
+
:firefox => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.12) Gecko/2009070609 Firefox/3.0.12",
|
10
|
+
:opera => "Opera/8.00 (Windows NT 5.1; U; en)"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_is_spider_true
|
15
|
+
assert UserAgent.is_spider?( @agent_strings[:googlebot] )
|
16
|
+
assert UserAgent.is_spider?( @agent_strings[:msnbot] )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_is_spider_false
|
20
|
+
assert ! UserAgent.is_spider?( @agent_strings[:firefox] )
|
21
|
+
assert ! UserAgent.is_spider?( @agent_strings[:opera] )
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: JamieFlournoy-user_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Flournoy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.2
|
24
|
+
version:
|
25
|
+
description: Determine whether the HTTP user agent talking to your code is a web spider.
|
26
|
+
email:
|
27
|
+
- jamie@pervasivecode.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- lib/user_agent.rb
|
42
|
+
- test/test_user_agent.rb
|
43
|
+
has_rdoc: false
|
44
|
+
homepage: http://github.com/jamieflournoy/UserAgent
|
45
|
+
licenses:
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: user_agent
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Determine whether the HTTP user agent talking to your code is a web spider.
|
71
|
+
test_files:
|
72
|
+
- test/test_user_agent.rb
|