browser 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8da651ebe15cf30e9eccffd7e45c2b2659785776
4
- data.tar.gz: 08e9184e851b07fff6b2ff4efda0a820e042df50
3
+ metadata.gz: a8f4650e2d1a3d6e81011637c57feea62b92444b
4
+ data.tar.gz: 6383b04357145bfd6acf774c235b1af3b71d4399
5
5
  SHA512:
6
- metadata.gz: 1af5f14bd4c40f26773c2aecebf58802e3cc4f037481bfec8240c5cb54c52673a23249909d7280d13a1a7a0094942f2384ccf4e1e8a835c703bf6b9d5149dd22
7
- data.tar.gz: b910d7e7b92cbc5456747369c27a1f955a1d33329b61caa2f50590aca90f20c80f13d75f6f8bab56b5e595b5ebaebe3437639f7dc8df0870090f33e67daad50b
6
+ metadata.gz: 69effb2ac78f0bd154b38aa43a479dc5f42e29fce57bf702fe8521981122cca202e4fa35692a3f6e1b2e359906387cc086ee9b4a8102d2d0cf67819fdf9a718e
7
+ data.tar.gz: b2c1172bc85607ceb885006a842837ac68d2e54c5443ab9885bcc17cd2c77a3aa779836d57f4037f9f72a1c561add97ce3221c25843af5362ed6f498de48e374
data/README.md CHANGED
@@ -18,7 +18,7 @@ require "rubygems"
18
18
  require "browser"
19
19
 
20
20
  browser = Browser.new(:ua => "some string", :accept_language => "en-us")
21
- browser.name # readable browser name
21
+ browser.name # readable browser name
22
22
  browser.version
23
23
  browser.safari?
24
24
  browser.opera?
@@ -29,20 +29,21 @@ browser.tablet?
29
29
  browser.console?
30
30
  browser.firefox?
31
31
  browser.ie?
32
- browser.ie6? # this goes up to 11
33
- browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
34
- browser.platform # return :mac, :windows, :linux or :other
32
+ browser.ie6? # this goes up to 11
33
+ browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
34
+ browser.platform # return :mac, :windows, :linux or :other
35
35
  browser.mac?
36
36
  browser.windows?
37
37
  browser.windows_x64?
38
38
  browser.linux?
39
39
  browser.blackberry?
40
40
  browser.bot?
41
- browser.meta # an array with several attributes
42
- browser.to_s # the meta info joined by space
41
+ browser.search_engine?
42
+ browser.meta # an array with several attributes
43
+ browser.to_s # the meta info joined by space
43
44
  ```
44
45
 
45
- See the [tests](https://github.com/fnando/browser/blob/master/test/browser_test.rb) and [implementation](https://github.com/fnando/browser/blob/master/lib/browser.rb) for more examples.
46
+ See the [tests](https://github.com/fnando/browser/blob/master/test/browser_spec.rb) and [implementation](https://github.com/fnando/browser/blob/master/lib/browser.rb) for more examples.
46
47
 
47
48
  ### What defines a modern browser?
48
49
 
@@ -78,6 +79,14 @@ This adds a helper method called `browser`, that inspects your current user agen
78
79
  <% end %>
79
80
  ```
80
81
 
82
+ ### Bots
83
+
84
+ Browser used to detect empty user agents as bots, but this behaviour has changed. If you want to bring this detection back, you can activate it through the following call:
85
+
86
+ ```ruby
87
+ Browser::Bots.detect_empty_ua!
88
+ ```
89
+
81
90
  ### Middleware
82
91
 
83
92
  You can use the `Browser::Middleware` to redirect user agents.
@@ -100,6 +109,7 @@ Notice that you can have multiple conditionals.
100
109
 
101
110
  ```ruby
102
111
  Rails.configuration.middleware.use Browser::Middleware do
112
+ next if browser.search_engine?
103
113
  redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
104
114
  redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
105
115
  end
data/bots.yml CHANGED
@@ -11,20 +11,23 @@ Baiduspider: "Chinese search engine"
11
11
  bingbot: "Microsoft bing bot"
12
12
  bitlybot: "bit.ly bot"
13
13
  bot@linkfluence.net: "Linkfluence bot"
14
+ BuiBui-CheckBot: "email: buibui[at]dadapro[dot]com"
14
15
  Butterfly: "Topsy Labs"
15
16
  buzztalk: "buzztalk"
16
17
  check_http: "Nagios monitor"
17
18
  CMRadar/0.1: "CMRadar/0.1"
18
19
  ColdFusion: "ColdFusion http library"
19
- Crowsnest: "crowsnest.tv news portal bot"
20
20
  Crowsnest: "Crowsnest"
21
+ Crowsnest: "crowsnest.tv news portal bot"
21
22
  curl: "curl unix CLI http client"
22
23
  developers.google.com/+/web/snippet/: "Google Plus"
23
24
  DigitalPersona Fingerprint Software: "HP Fingerprint scanner"
25
+ DotBot: "Dot Bot"
24
26
  Embedly: "Embedly"
25
27
  EOAAgent: "EOAAgent"
26
28
  EventMachine HttpClient: "Ruby http library"
27
29
  EvriNid: "Evri bot"
30
+ Exabot: "Exalead's bot"
28
31
  ExaleadCloudView: "ExaleadCloudView"
29
32
  facebookexternalhit: "facebook bot"
30
33
  FeedBurner: "RSS bot"
@@ -50,29 +53,33 @@ Insieve Bot: "Insieve Bot"
50
53
  InsieveBot: "InsieveBot"
51
54
  Instapaper: "Instapaper"
52
55
  jack: "jack"
53
- Jakarta Commons: "Jakarta Commons HttpClient"
54
56
  Jakarta Commons-HttpClient: "Jakarta Commons-HttpClient"
57
+ Jakarta Commons: "Jakarta Commons HttpClient"
55
58
  Java: "Generic Java http library"
56
59
  Jetslide: "Jetslide"
57
60
  JS-Kit: "URL resolver"
58
- Kimengi: "nineconnections.com bot"
59
61
  Kimengi/nineconnections.com: "Kimengi/nineconnections.com"
62
+ Kimengi: "nineconnections.com bot"
60
63
  knows.is: "knows.is"
61
64
  kraken: "kraken"
62
65
  Laconica: "Laconica"
63
66
  libwww-perl: "Perl client-server library loved by script kids"
67
+ linkdexbot: "Linkdex Bot"
64
68
  LinkedInBot: "LinkedIn"
65
69
  LinksCrawler: "LinksCrawler"
66
- Livelapbot: "Livelapbot"
67
70
  Lipperhey: "Lipperhey"
71
+ Livelapbot: "Livelapbot"
72
+ LoadTimeBot: "Load Time Bot"
68
73
  LongURL: "URL expander service"
69
74
  Lumibot: "Lumibot"
70
75
  lwp-trivial: "Another Perl library loved by script kids"
76
+ Mail.RU_Bot: "Mail.ru Bot"
71
77
  Mediapartners-Google: "Google Adsense bot"
72
- MetaURI: "URI meta information extractor bot"
73
78
  MetaURI: "MetaURI"
79
+ MetaURI: "URI meta information extractor bot"
74
80
  MFE_expand: "Mcafee spider"
75
81
  MJ12bot: "Majestic-12 spider"
82
+ MojeekBot: "Mojeek UK search crawler"
76
83
  msnbot: "Microsoft bot"
77
84
  Netvibes: "Personalized dashboard bot"
78
85
  NewRelicPinger: "NewRelic monitor"
@@ -96,9 +103,11 @@ QuickLook: "QuickLook"
96
103
  Readability: "Readability"
97
104
  RebelMouse: "RebelMouse"
98
105
  redditbot: "Reddit Bot"
106
+ Riddler: "Riddler Bot"
99
107
  rogerbot: "SeoMoz spider"
100
- Ruby: "Ruby"
101
108
  Ruby/1.9.3: "Ruby/1.9.3"
109
+ Ruby: "Ruby"
110
+ Scrapy: "Scrapy"
102
111
  SemrushBot: "SEO analysis bot"
103
112
  ShortLinkTranslate: "Link shortener"
104
113
  ShowyouBot: "Showyou iOS app spider"
@@ -107,6 +116,7 @@ SiteUptime: "Site monitoring services"
107
116
  Slurp: "Yahoo spider"
108
117
  Sogou: "Chinese search engine"
109
118
  spider: "generic web spider"
119
+ Spinn3r: "Spinn3r aggregator"
110
120
  Test Certificate Info: "C http library?"
111
121
  trendictionbot: "trendiction search"
112
122
  TweetmemeBot: "TweetMeMe Crawler"
@@ -123,7 +133,10 @@ vkShare: "VKontake Sharer"
123
133
  Webscout: "Webscout"
124
134
  Wget: "wget unix CLI http client"
125
135
  WordPress: "WordPress spider"
136
+ Xenu Link Sleuth: "Xenu Link Sleuth"
126
137
  YandexBot: "Yandex spider"
138
+ YandexDirect: "Yandex Direct spider"
139
+ YandexMetrika: "Yandex Metrika spider"
127
140
  YOURLS: "YOURLS"
128
141
  zelist.ro: "feed parser"
129
142
  ZIBB: "ZIBB spider"
@@ -1,5 +1,6 @@
1
1
  require "set"
2
2
  require "yaml"
3
+ require "pathname"
3
4
 
4
5
  require "browser/middleware"
5
6
  require "browser/middleware/context"
@@ -1,9 +1,19 @@
1
1
  class Browser
2
2
  module Bots
3
- BOTS = YAML.load_file(File.expand_path("../../../../bots.yml", __FILE__))
3
+ root = Pathname.new(File.expand_path("../../../..", __FILE__))
4
+ BOTS = YAML.load_file(root.join("bots.yml"))
5
+ SEARCH_ENGINES = YAML.load_file(root.join("search_engines.yml"))
6
+
7
+ def self.detect_empty_ua!
8
+ Browser::Bots::BOTS[''] = 'Generic bot'
9
+ end
4
10
 
5
11
  def bot?
6
- ua.empty? || BOTS.any? {|key, _| ua.include?(key) }
12
+ BOTS.any? {|key, _| ua.include?(key) }
13
+ end
14
+
15
+ def search_engine?
16
+ SEARCH_ENGINES.any? {|key, _| ua.include?(key) }
7
17
  end
8
18
  end
9
19
  end
@@ -1,7 +1,7 @@
1
1
  class Browser
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
@@ -0,0 +1,6 @@
1
+ Baidu: "Chinese search engine"
2
+ bingbot: "Microsoft bing bot"
3
+ Googlebot: "Google spider"
4
+ Slurp: "Yahoo spider"
5
+ DuckDuckBot: "Duck Duck Go"
6
+ Ask Jeeves: "Ask Jeeves"
@@ -814,21 +814,36 @@ describe Browser do
814
814
  end
815
815
 
816
816
  it "detects bots" do
817
- @browser.ua = $ua["GOOGLE_BOT"]
818
- assert @browser.bot?
817
+ %w[
818
+ DOT_BOT
819
+ FACEBOOK_BOT
820
+ GOOGLE_BOT
821
+ LINKDEXBOT
822
+ LOAD_TIME_BOT
823
+ MAIL_RU
824
+ MSN_BOT
825
+ SCRAPY
826
+ YANDEX_DIRECT
827
+ YANDEX_METRIKA
828
+ ].each do |key|
829
+ @browser.ua = $ua[key]
830
+ assert @browser.bot?, "#{$ua[key]} should be a bot"
831
+ end
819
832
 
820
- @browser.ua = $ua["MSN_BOT"]
821
- assert @browser.bot?
833
+ @browser.ua = $ua["CHROME"]
834
+ assert ! @browser.bot?
835
+ end
822
836
 
823
- @browser.ua = $ua["FACEBOOK_BOT"]
824
- assert @browser.bot?
837
+ it "doesn't consider empty UA as bot" do
838
+ @browser.ua = ''
839
+ assert ! @browser.bot?
840
+ end
825
841
 
826
- # Many bots actually report empty ua strings.
842
+ it "allows setting empty string as bots" do
843
+ Browser::Bots.detect_empty_ua!
827
844
  @browser.ua = ''
828
845
  assert @browser.bot?
829
-
830
- @browser.ua = $ua["CHROME"]
831
- assert ! @browser.bot?
846
+ Browser::Bots::BOTS.delete('')
832
847
  end
833
848
 
834
849
  it "detects chrome os" do
@@ -840,4 +855,18 @@ describe Browser do
840
855
  @browser.ua = $ua["SMART_TV"]
841
856
  assert @browser.tv?
842
857
  end
858
+
859
+ it "detects as search engines" do
860
+ %w[
861
+ ASK
862
+ BAIDU
863
+ BINGBOT
864
+ DUCKDUCKGO
865
+ GOOGLE_BOT
866
+ YAHOO_SLURP
867
+ ].each do |key|
868
+ @browser.ua = $ua[key]
869
+ assert @browser.search_engine?, "#{$ua[key]} should be a search engine"
870
+ end
871
+ end
843
872
  end
@@ -65,3 +65,15 @@ GOOGLE_BOT: "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.
65
65
  MSN_BOT: "msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)"
66
66
  FACEBOOK_BOT: "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
67
67
  SMART_TV: "Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV) AppleWebKit/531.2+ (KHTML, like Gecko) WebBrowser/1.0 SmartTV Safari/531.2+"
68
+ DOT_BOT: "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)"
69
+ LINKDEXBOT: "Mozilla/5.0 (compatible; linkdexbot/2.0; +http://www.linkdex.com/bots/)"
70
+ LOAD_TIME_BOT: "Mozilla/5.0 (compatible; LoadTimeBot/0.9; +http://www.loadtime.net/bot.html)"
71
+ MAIL_RU: "Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)"
72
+ SCRAPY: "Scrapy/0.18.4 (+http://scrapy.org)"
73
+ YANDEX_DIRECT: "Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots)"
74
+ YANDEX_METRIKA: "Mozilla/5.0 (compatible; YandexMetrika/3.0; +http://yandex.com/bots)"
75
+ BAIDU: "Baiduspider+(+http://www.baidu.com/search/spider.htm)"
76
+ YAHOO_SLURP: "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
77
+ ASK: "Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)"
78
+ BINGBOT: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
79
+ DUCKDUCKGO: "DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,6 +124,7 @@ files:
124
124
  - lib/browser/middleware/context/url_methods.rb
125
125
  - lib/browser/rails.rb
126
126
  - lib/browser/version.rb
127
+ - search_engines.yml
127
128
  - test/browser_spec.rb
128
129
  - test/middleware_spec.rb
129
130
  - test/sample_app.rb