Module: BotVerification
- Defined in:
- lib/bot_verification.rb,
lib/bot_verification/railtie.rb,
lib/bot_verification/service.rb,
lib/bot_verification/version.rb,
lib/bot_verification/refresh_job.rb,
lib/bot_verification/bot_patterns.rb,
lib/bot_verification/configuration.rb,
lib/bot_verification/ip_range_model.rb,
lib/bot_verification/ip_range_fetcher.rb,
lib/bot_verification/controller_concern.rb,
lib/generators/bot_verification/install_generator.rb
Defined Under Namespace
Modules: BotPatterns, ControllerConcern, Generators, IpRangeModel Classes: Configuration, ConfigurationError, Error, IpRange, IpRangeFetcher, Railtie, RefreshJob, Service
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
-
.detect_bot(user_agent) ⇒ Object
Detect bot type from user agent.
-
.ip_range_model ⇒ Object
Get the IP range model class.
-
.refresh_ip_ranges!(bot_type = nil) ⇒ Object
Refresh IP ranges from official sources.
- .reset_configuration! ⇒ Object
-
.table_exists? ⇒ Boolean
Check if the IP ranges table exists.
-
.verify(ip, user_agent, mode: :search_engines) ⇒ Object
Convenience method to access the service.
-
.verify_ip(ip, bot_type) ⇒ Object
Check if an IP belongs to a known bot.
Class Attribute Details
.configuration ⇒ Object
30 31 32 |
# File 'lib/bot_verification.rb', line 30 def configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
34 35 36 |
# File 'lib/bot_verification.rb', line 34 def configure yield(configuration) end |
.detect_bot(user_agent) ⇒ Object
Detect bot type from user agent
53 54 55 |
# File 'lib/bot_verification.rb', line 53 def detect_bot(user_agent) Service.detect_bot_type(user_agent) end |
.ip_range_model ⇒ Object
Get the IP range model class
63 64 65 |
# File 'lib/bot_verification.rb', line 63 def ip_range_model configuration.ip_range_model_class end |
.refresh_ip_ranges!(bot_type = nil) ⇒ Object
Refresh IP ranges from official sources
58 59 60 |
# File 'lib/bot_verification.rb', line 58 def refresh_ip_ranges!(bot_type = nil) IpRangeFetcher.refresh!(bot_type) end |
.reset_configuration! ⇒ Object
38 39 40 |
# File 'lib/bot_verification.rb', line 38 def reset_configuration! @configuration = Configuration.new end |
.table_exists? ⇒ Boolean
Check if the IP ranges table exists
68 69 70 71 72 |
# File 'lib/bot_verification.rb', line 68 def table_exists? return false unless ActiveRecord::Base.connected? ActiveRecord::Base.connection.table_exists?(configuration.table_name) end |
.verify(ip, user_agent, mode: :search_engines) ⇒ Object
Convenience method to access the service
43 44 45 |
# File 'lib/bot_verification.rb', line 43 def verify(ip, user_agent, mode: :search_engines) Service.verified_good_bot?(ip, user_agent, mode: mode) end |
.verify_ip(ip, bot_type) ⇒ Object
Check if an IP belongs to a known bot
48 49 50 |
# File 'lib/bot_verification.rb', line 48 def verify_ip(ip, bot_type) Service.verified_bot_ip?(ip, bot_type) end |