useragent_parser 0.1.1 → 0.2.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/config/regexes.yaml +72 -2
- data/lib/useragent_parser/parsers/referrer_parser.rb +34 -0
- data/lib/useragent_parser/user_agent.rb +104 -0
- data/lib/useragent_parser/version.rb +1 -1
- data/lib/useragent_parser.rb +39 -2
- data/spec/fixtures/pgts_browser_list.yaml +18 -18
- data/spec/fixtures/test_referrers.yaml +40 -0
- data/spec/fixtures/test_user_agent_parser.yaml +7 -7
- data/spec/fixtures/test_user_agent_parser_email.yaml +2189 -0
- data/spec/parsers/referrer_parser_spec.rb +12 -0
- data/spec/parsers/useragent_parser_spec.rb +14 -0
- data/spec/user_agent_spec.rb +106 -0
- data/spec/useragent_parser_spec.rb +3 -3
- metadata +9 -2
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe UseragentParser::ReferrerParser do
|
6
|
+
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/test_referrers.yaml")['test_cases'].each do |testcase|
|
7
|
+
it "should correctly parse the referrer string '#{testcase['referrer_string']}'" do
|
8
|
+
result = UseragentParser.parse_referrer(testcase['referrer_string'])
|
9
|
+
result['family'].should == testcase['family']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -17,6 +17,20 @@ describe UseragentParser::UserAgentParser do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/test_user_agent_parser_email.yaml")['test_cases'].each do |testcase|
|
21
|
+
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
22
|
+
if testcase['js_ua']
|
23
|
+
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '"))
|
24
|
+
js_ua = [ js_ua['js_user_agent_string'], js_ua['js_user_agent_family'], js_ua['js_user_agent_v1'], js_ua['js_user_agent_v2'], js_ua['js_user_agent_v3'] ]
|
25
|
+
end
|
26
|
+
result = UseragentParser.parse_user_agent(testcase['user_agent_string'], *js_ua)
|
27
|
+
result['family'].should == testcase['family']
|
28
|
+
result['major'].should == testcase['major']
|
29
|
+
result['minor'].should == testcase['minor']
|
30
|
+
result['patch'].should == testcase['patch']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
20
34
|
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/firefox_user_agent_strings.yaml")['test_cases'].each do |testcase|
|
21
35
|
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
22
36
|
js_ua = {}
|
data/spec/user_agent_spec.rb
CHANGED
@@ -58,6 +58,112 @@ describe UseragentParser::UserAgent do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
describe "for email client" do
|
62
|
+
it "should detect Mozilla Thunderbird" do
|
63
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; de; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9').email.should == 'Thunderbird'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should detect Windows Live Mail" do
|
67
|
+
UseragentParser.parse_with_referrer('Outlook-Express/7.0 (MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618; TmstmpExt)').email.should == 'Windows Live Mail'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should detect Eudora" do
|
71
|
+
UseragentParser.parse_with_referrer('Eudora/6.2.3b9 (MacOS)').email.should == 'Eudora'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should detect T-Online eMail" do
|
75
|
+
UseragentParser.parse_with_referrer('Kopernikus T-Online eMail 3.x').email.should == 'T-Online eMail'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should detect old Apple Mail" do
|
79
|
+
UseragentParser.parse_with_referrer('Mail/1082 CFNetwork/454.11.5 Darwin/10.5.0 (i386) (MacBookPro6%2C2)').email.should == 'Apple Mail'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should detect newer Apple Mail" do
|
83
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; de-de) AppleWebKit/533.18.1 (KHTML, like Gecko)').email.should == 'Apple Mail'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should detect Lotus Notes" do
|
87
|
+
UseragentParser.parse_with_referrer('Mozilla/4.0 (compatible; Lotus-Notes/6.0; Macintosh PPC)').email.should == 'Lotus Notes'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should detect Microsoft Outlook" do
|
91
|
+
UseragentParser.parse_with_referrer('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; ms-office; MSOffice 14)').email.should == 'Microsoft Outlook'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should detect Sparrow" do
|
95
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Sparrow/1164').email.should == 'Sparrow'
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "Outlook" do
|
99
|
+
it "should should recognize Outlook 2000/2003/Express" do
|
100
|
+
UseragentParser.parse_with_referrer('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)').email_version.should == 'Outlook 2000/2003/Express'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not mistake IE7 as Outlook" do
|
104
|
+
# TODO
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should should recognize Outlook 2007" do
|
108
|
+
UseragentParser.parse_with_referrer('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MSOffice 12)').email_version.should == 'Outlook 2007'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should should recognize Outlook 2010" do
|
112
|
+
UseragentParser.parse_with_referrer('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; InfoPath.3; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; ms-office; MSOffice 14)').email_version.should == 'Outlook 2010'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "Apple Mail" do
|
117
|
+
it "should recognize Version 2" do
|
118
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; de-de) AppleWebKit/533.19.4 (KHTML, like Gecko)').email_version.should == 'Apple Mail 2'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should recognize Version 3" do
|
122
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_8; de-de) AppleWebKit/533.18.1 (KHTML, like Gecko)').email_version.should == 'Apple Mail 3'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should recognize Version 4" do
|
126
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; de-de) AppleWebKit/533.19.4 (KHTML, like Gecko)').email_version.should == 'Apple Mail 4'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should recognize Version 5" do
|
130
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko)').email_version.should == 'Apple Mail 5'
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should recognize Version 6" do
|
134
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/536.25 (KHTML, like Gecko)').email_version.should == 'Apple Mail 6'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not mistake Safari for Apple Mail" do
|
138
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/536.25 (KHTML, like Gecko)', 'something').email_version.should be_nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "Apple Mobile Mail" do
|
143
|
+
it "should recognize an iPad" do
|
144
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; de-de) AppleWebKit/531.21.10 (KHTML, like Gecko)').email_version.should == 'iPad'
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should recognize an iPod" do
|
148
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPod; U; CPU iPhone OS 4_0 like Mac OS X; de-de) AppleWebKit/532.9 (KHTML, like Gecko)').email_version.should == 'iPod'
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should recognize an iPhone" do
|
152
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; de-de) AppleWebKit/532.9 (KHTML, like Gecko)').email_version.should == 'iPhone'
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should not mistake Mobile Safari for Apple Mail" do
|
156
|
+
# TODO
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "AOL" do
|
161
|
+
it "should recognize the Webmail interface" do
|
162
|
+
UseragentParser.parse_with_referrer('Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.13) Gecko/20101203 AskTbFXTV5/3.9.1.14019 Firefox/3.6.13', 'http://mail.aol.com/33222-111/aol-1/de-de/Lite/MsgRead.aspx?folder=Spam&uid=1.28305313&seq=0&searchIn=none&searchQuery=&start=0&sort=received').email_version.should == 'AOL Webmail'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
61
167
|
describe "for operating system details" do
|
62
168
|
it "should report the os family" do
|
63
169
|
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_family.should == 'Windows NT'
|
@@ -6,7 +6,7 @@ describe UseragentParser do
|
|
6
6
|
let(:user_agent_string) { 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; fr; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5,gzip(gfe),gzip(gfe)' }
|
7
7
|
|
8
8
|
describe "should return user agent information" do
|
9
|
-
subject { UseragentParser.
|
9
|
+
subject { UseragentParser.parse_browser(user_agent_string)['user_agent'] }
|
10
10
|
|
11
11
|
its(['family']) { should == 'Firefox' }
|
12
12
|
its(['major']) { should == '3' }
|
@@ -15,7 +15,7 @@ describe UseragentParser do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "should return the operating system information" do
|
18
|
-
subject { UseragentParser.
|
18
|
+
subject { UseragentParser.parse_browser(user_agent_string)['os'] }
|
19
19
|
|
20
20
|
its(['family']) { should == 'Mac OS X' }
|
21
21
|
its(['major']) { should == '10' }
|
@@ -25,7 +25,7 @@ describe UseragentParser do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "should return the device information" do
|
28
|
-
subject { UseragentParser.
|
28
|
+
subject { UseragentParser.parse_browser(user_agent_string)['device'] }
|
29
29
|
|
30
30
|
its(['family']) { should be_nil }
|
31
31
|
its(['is_spider']) { should be_false }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: useragent_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/useragent_parser.rb
|
78
78
|
- lib/useragent_parser/parsers/device_parser.rb
|
79
79
|
- lib/useragent_parser/parsers/os_parser.rb
|
80
|
+
- lib/useragent_parser/parsers/referrer_parser.rb
|
80
81
|
- lib/useragent_parser/parsers/user_agent_parser.rb
|
81
82
|
- lib/useragent_parser/user_agent.rb
|
82
83
|
- lib/useragent_parser/version.rb
|
@@ -84,10 +85,13 @@ files:
|
|
84
85
|
- spec/fixtures/firefox_user_agent_strings.yaml
|
85
86
|
- spec/fixtures/pgts_browser_list.yaml
|
86
87
|
- spec/fixtures/test_device.yaml
|
88
|
+
- spec/fixtures/test_referrers.yaml
|
87
89
|
- spec/fixtures/test_user_agent_parser.yaml
|
90
|
+
- spec/fixtures/test_user_agent_parser_email.yaml
|
88
91
|
- spec/fixtures/test_user_agent_parser_os.yaml
|
89
92
|
- spec/parsers/device_parser_spec.rb
|
90
93
|
- spec/parsers/os_parser_spec.rb
|
94
|
+
- spec/parsers/referrer_parser_spec.rb
|
91
95
|
- spec/parsers/useragent_parser_spec.rb
|
92
96
|
- spec/spec_helper.rb
|
93
97
|
- spec/user_agent_spec.rb
|
@@ -122,10 +126,13 @@ test_files:
|
|
122
126
|
- spec/fixtures/firefox_user_agent_strings.yaml
|
123
127
|
- spec/fixtures/pgts_browser_list.yaml
|
124
128
|
- spec/fixtures/test_device.yaml
|
129
|
+
- spec/fixtures/test_referrers.yaml
|
125
130
|
- spec/fixtures/test_user_agent_parser.yaml
|
131
|
+
- spec/fixtures/test_user_agent_parser_email.yaml
|
126
132
|
- spec/fixtures/test_user_agent_parser_os.yaml
|
127
133
|
- spec/parsers/device_parser_spec.rb
|
128
134
|
- spec/parsers/os_parser_spec.rb
|
135
|
+
- spec/parsers/referrer_parser_spec.rb
|
129
136
|
- spec/parsers/useragent_parser_spec.rb
|
130
137
|
- spec/spec_helper.rb
|
131
138
|
- spec/user_agent_spec.rb
|