Skip to content

Commit

Permalink
Version 2
Browse files Browse the repository at this point in the history
Added
-----

* Built-in cache with file-path and max-age
* Automatically refresh from source (external repository)

Removed
-------

* Rake-tasks
* A very large copy of external UA-bots list
* `rack` as dependency

Changed
-------

* `voight_kampff/rack_request` isn't required by default
* Default path for cache is now in `./tmp` directory instead of `./config`

Development
-----------

* [EditorConfig](https://editorconfig.org/) added
* [RuboCop](https://github.com/rubocop-hq/rubocop) added and offenses fixed
* Drop support for Ruby <= 2.2 (they even will not get security patches)
* Ignore built gems for git
  • Loading branch information
AlexWayfer committed Aug 31, 2018
1 parent ece9e6b commit f1ceb89
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 2,436 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Gemfile.lock
*.rbc
coverage
doc
*.gem
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AllCops:
TargetRubyVersion: 2.3

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Metrics/BlockLength:
Exclude:
- spec/**/*

Metrics/LineLength:
Exclude:
- spec/support/*
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: ruby
rvm:
- 2.2.5
- 2.3.1
- 2.3
- 2.4
- 2.5
script: bundle exec rspec
before_install:
# fixes Travis CI error: NoMethodError: undefined method `spec' for nil:NilClass
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,38 @@ Installation
Configuration
-------------

A JSON file is used to match [user agent strings](http://simplyfast.info/browser) to a list of known bots.
By default, this gem download [updatable list of known bots](https://github.com/monperrus/crawler-user-agents) and cache it into the `./tmp` directory.

If you'd like to use an [updated list](https://github.com/monperrus/crawler-user-agents) or make your own customizations, run `rake voight_kampff:import_user_agents`. This will download a `crawler-user-agents.json` file into the `./config` directory.
You can disable file cache with `VoightKampff::Test.cache_path = nil`.

Default TTL of cache is 24 hours. You can change it with `VoightKampff::Test.max_age = number_of_seconds`.

__Note:__ The pattern entries in the JSON file are evaluated as [regular expressions](http://en.wikipedia.org/wiki/Regular_expression).

Usage
-----
There are three ways to use Voight-Kampff

1. Through Rack::Request such as in your [Ruby on Rails](http://rubyonrails.org) controllers:
`request.bot?`
1. Through `Rack::Request` in your app such as [Ruby on Rails](http://rubyonrails.org):
```ruby
require 'voight_kampff/rack_request'

request.bot?
```

2. Through the `VoightKampff` module:
2. Through the `VoightKampff` module:
`VoightKampff.bot? 'your user agent string'`

3. Through a `VoightKampff::Test` instance:
3. Through a `VoightKampff::Test` instance:
`VoightKampff::Test.new('your user agent string').bot?`

All of the above examples accept `human?` and `bot?` methods. All of these methods will return `true` or `false`.
All of the above examples accept `human?` and `bot?` methods.
All of these methods will return `true` or `false`.

Upgrading to version 1.0
------------------------

Version 1.0 uses a new source for a list of bot user agent strings since the old source was no longer maintained. This new source, unfortuately, does not include as much detail. Therefore the following methods have been deprecated:
Version 1.0 uses a new source for a list of bot user agent strings since the old source was no longer maintained. This new source, unfortunately, does not include as much detail. Therefore the following methods have been deprecated:
- `#browser?`
- `#checker?`
- `#downloader?`
Expand All @@ -49,14 +56,21 @@ In general the `#bot?` command tends to include all of these and I'm sure it's u

Also, the gem no longer extends `ActionDispatch::Request` instead it extends `Rack::Request` which `ActionDispatch::Request` inherits from. This allows the same functionality for Rails while opening the gem up to other rack-based projects.

Upgrading to version 2.0
------------------------

Version 2.0 uses a built-in cache instead of `rake` tasks.

Also, you have to explicitly require `voight_kampff/rack_request` for `Rack::Request` patching.

FAQ
---
__Q:__ __What's with the name?__
__Q:__ __What's with the name?__
__A:__ It's the [machine in Blade Runner](http://en.wikipedia.org/wiki/Blade_Runner#Voight-Kampff_machine) that is used to test whether someone is a human or a replicant.

__Q:__ __I've found a bot that isn't being matched__
__Q:__ __I've found a bot that isn't being matched__
__A:__ The list is being pulled from [github.com/monperrus/crawler-user-agents](https://github.com/monperrus/crawler-user-agents).
If you'd like to have entries added to the list, please create a pull request with that project. Once that pull request is merged, feel free to create an issue here and I'll release a new gem version with the updated list. In the meantime you can always run `rake voight_kampff:import_user_agents` on your project to get that updated list.
If you'd like to have entries added to the list, please create a pull request with that project. Once that pull request is merged, you'll be get the new version at the next cache update. In the meantime you can always manually flush the cache in your project to get that updated list.

__Q:__ __Why don't you use the user agent list from ______________
If you know of a better source for a list of bot user agent strings, please create an issue and let me know. I'm open to switching to a better source or supporting multiple sources. There are others out there but I like the openness of monperrus' list.
Expand All @@ -67,7 +81,7 @@ Thanks to [github.com/monperrus/crawler-user-agents](https://github.com/monperru

Contributing
------------
PR without tests will not get merged, Make sure you write tests for api and rails app.
PR without tests will not get merged, Make sure you write tests for API and Rails app.
Feel free to ask for help, if you do not know how to write a determined test.

Running Tests?
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler'

Expand Down
Loading

0 comments on commit f1ceb89

Please sign in to comment.