Class: MongoidTraffic::Logger::Bots
- Inherits:
-
Object
- Object
- MongoidTraffic::Logger::Bots
- Defined in:
- lib/mongoid_traffic/logger/bots.rb
Constant Summary collapse
- DATA_URL =
'http://www.user-agents.org/allagents.xml'.freeze
- FILE_PATH =
File.join(File.dirname(__dir__), '..', '..', 'vendor', 'mongoid_traffic', 'allagents.xml')
Class Method Summary collapse
Class Method Details
.is_a_bot?(referer) ⇒ Boolean
24 25 26 27 |
# File 'lib/mongoid_traffic/logger/bots.rb', line 24 def is_a_bot?(referer) return false unless referer.present? list.include?(referer) end |
.list ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mongoid_traffic/logger/bots.rb', line 12 def list @list ||= begin response = File.open(FILE_PATH).read doc = Nokogiri::XML(response) doc.xpath('//user-agent').inject([]) do |res, agent| type = agent.xpath('Type').text res << agent.xpath('String').text.gsub('<', '<') if %w(R S).include?(type) res end end end |