agent_orange 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -5
- data/Rakefile +11 -0
- data/agent_orange.gemspec +4 -1
- data/lib/agent_orange/version.rb +1 -1
- data/spec/spec_helper.rb +16 -0
- data/spec/user_agent_matcher.rb +16 -0
- data/spec/user_agent_spec.rb +85 -0
- metadata +54 -8
data/README.rdoc
CHANGED
@@ -14,12 +14,16 @@ device, or is a bot (such as Google). It was composed by using techniques gather
|
|
14
14
|
several other libraries/gems in an effort to be consistent and cover as many types
|
15
15
|
of agents as possible.
|
16
16
|
|
17
|
-
== Status
|
17
|
+
== Project Status
|
18
18
|
|
19
|
-
===
|
19
|
+
=== Stable, but needs improvement.
|
20
20
|
|
21
|
-
This library
|
22
|
-
|
21
|
+
This library does detect the requesting user (device, platform, os, framework, and browser with versions)
|
22
|
+
and now has some rpsec tests. While it is stable and no large restructuring is planned, it can use
|
23
|
+
some optimizations and improvements to the detection algorithms. The techniques currently in place
|
24
|
+
are rather simple, and not perfect (for example, it is currently confused if it sees both Chrome and
|
25
|
+
Safari in user agent string, and doesn't pick based on order of appearance). If you'd like to help,
|
26
|
+
please contact me.
|
23
27
|
|
24
28
|
== Installation
|
25
29
|
|
@@ -146,9 +150,16 @@ AgentOrange::Version
|
|
146
150
|
|
147
151
|
== Maintainer
|
148
152
|
|
149
|
-
* Kevin Elliott - http://kevinelliott.net
|
153
|
+
* Kevin Elliott - http://kevinelliott.net - http://github.com/kevinelliott
|
150
154
|
* WeLike - http://www.welikeinc.com - http://github.com/welike
|
151
155
|
|
156
|
+
== Contributors
|
157
|
+
|
158
|
+
A warm thank you to all contributors to the project, who have put effort and time into making this gem more useful.
|
159
|
+
|
160
|
+
* David Rice (davidjrice) - RSpec tests and bug fixes.
|
161
|
+
* Joshua Siler (eatenbyagrue) - Bot detection, initial test, and bug fixes.
|
162
|
+
|
152
163
|
== License
|
153
164
|
|
154
165
|
(The MIT License)
|
data/Rakefile
CHANGED
@@ -1,3 +1,14 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
Dir.glob('./lib/tasks/*.rake').each { |r| import r }
|
3
3
|
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
desc "Run all specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
# t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
10
|
+
# Put spec opts in a file named .rspec in root
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
14
|
+
end
|
data/agent_orange.gemspec
CHANGED
@@ -14,8 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "agent_orange"
|
16
16
|
|
17
|
-
s.
|
17
|
+
s.add_development_dependency "rake"
|
18
|
+
s.add_development_dependency "rspec"
|
19
|
+
s.add_development_dependency "bundler"
|
18
20
|
|
21
|
+
s.files = `git ls-files`.split("\n")
|
19
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
24
|
s.require_paths = ["lib"]
|
data/lib/agent_orange/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module AgentOrange
|
2
|
-
VERSION = "0.1.
|
2
|
+
VERSION = "0.1.2" # This is for the gem and does not conflict with the rest of the functionality
|
3
3
|
|
4
4
|
class Version
|
5
5
|
attr_accessor :major, :minor, :patch_level, :build_number
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require File.join(File.dirname(__FILE__), "user_agent_matcher")
|
12
|
+
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'agent_orange'
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe AgentOrange::UserAgent do
|
4
|
+
|
5
|
+
describe "Safari" do
|
6
|
+
detect "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" do |ua|
|
7
|
+
ua.device.type.should == :computer
|
8
|
+
ua.device.name.should == "Computer"
|
9
|
+
ua.device.version.should == nil
|
10
|
+
|
11
|
+
ua.device.operating_system.name.should == "Mac OS X"
|
12
|
+
ua.device.operating_system.version.to_s.should == "10.6.8"
|
13
|
+
|
14
|
+
ua.device.platform.name.should == "Macintosh"
|
15
|
+
ua.device.platform.version.should == nil
|
16
|
+
|
17
|
+
ua.device.engine.name.should == "AppleWebKit"
|
18
|
+
ua.device.engine.version.to_s.should == "533.21.1"
|
19
|
+
|
20
|
+
ua.device.engine.browser.name.should == "Safari"
|
21
|
+
ua.device.engine.browser.version.to_s.should == "533.21.1"
|
22
|
+
end
|
23
|
+
|
24
|
+
detect "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.5 (KHTML, like Gecko) Chrome/16.0.891.1 Safari/535.5" do |ua|
|
25
|
+
ua.device.type.should == :computer
|
26
|
+
ua.device.name.should == "Computer"
|
27
|
+
ua.device.version.should == nil
|
28
|
+
|
29
|
+
ua.device.operating_system.name.should == "Mac OS X"
|
30
|
+
ua.device.operating_system.version.to_s.should == "10.7.1"
|
31
|
+
|
32
|
+
ua.device.platform.name.should == "Macintosh"
|
33
|
+
ua.device.platform.version.should == nil
|
34
|
+
|
35
|
+
ua.device.engine.name.should == "AppleWebKit"
|
36
|
+
ua.device.engine.version.to_s.should == "535.5"
|
37
|
+
|
38
|
+
ua.device.engine.browser.name.should == "Safari"
|
39
|
+
ua.device.engine.browser.version.to_s.should == "535.5"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Firefox" do
|
44
|
+
detect "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0" do |ua|
|
45
|
+
ua.device.type.should == :computer
|
46
|
+
ua.device.name.should == "Computer"
|
47
|
+
ua.device.version.should == nil
|
48
|
+
|
49
|
+
ua.device.operating_system.name.should == "Linux"
|
50
|
+
ua.device.operating_system.version.to_s.should == "i686"
|
51
|
+
|
52
|
+
ua.device.platform.name.should == "PC"
|
53
|
+
ua.device.platform.version.should == nil
|
54
|
+
|
55
|
+
ua.device.engine.name.should == "Gecko"
|
56
|
+
ua.device.engine.version.to_s.should == "20100101"
|
57
|
+
|
58
|
+
# TODO should be Chrome.
|
59
|
+
ua.device.engine.browser.name.should == "Firefox"
|
60
|
+
ua.device.engine.browser.version.to_s.should == "6.0"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "Chrome" do
|
65
|
+
detect "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2" do |ua|
|
66
|
+
ua.device.type.should == :computer
|
67
|
+
ua.device.name.should == "Computer"
|
68
|
+
ua.device.version.should == nil
|
69
|
+
|
70
|
+
ua.device.operating_system.name.should == "Windows"
|
71
|
+
ua.device.operating_system.version.to_s.should == "5.1"
|
72
|
+
|
73
|
+
ua.device.platform.name.should == "PC"
|
74
|
+
ua.device.platform.version.should == nil
|
75
|
+
|
76
|
+
ua.device.engine.name.should == "AppleWebKit"
|
77
|
+
ua.device.engine.version.to_s.should == "535.2"
|
78
|
+
|
79
|
+
# TODO should be Chrome.
|
80
|
+
ua.device.engine.browser.name.should == "Safari"
|
81
|
+
ua.device.engine.browser.version.to_s.should == "535.2"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agent_orange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kevin Elliott
|
@@ -15,9 +15,50 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
19
|
-
dependencies:
|
20
|
-
|
18
|
+
date: 2011-10-25 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
21
62
|
description: Parse and process User Agents like a secret one
|
22
63
|
email:
|
23
64
|
- kevin@welikeinc.com
|
@@ -45,6 +86,9 @@ files:
|
|
45
86
|
- lib/agent_orange/version.rb
|
46
87
|
- lib/tasks/allagents.xml
|
47
88
|
- lib/tasks/bot_agent_test.rake
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/user_agent_matcher.rb
|
91
|
+
- spec/user_agent_spec.rb
|
48
92
|
homepage: http://github.com/kevinelliott/agent_orange
|
49
93
|
licenses: []
|
50
94
|
|
@@ -78,5 +122,7 @@ rubygems_version: 1.8.5
|
|
78
122
|
signing_key:
|
79
123
|
specification_version: 3
|
80
124
|
summary: Parse and process User Agents like a secret one
|
81
|
-
test_files:
|
82
|
-
|
125
|
+
test_files:
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/user_agent_matcher.rb
|
128
|
+
- spec/user_agent_spec.rb
|