diff --git a/lib/project-honeypot.rb b/lib/project-honeypot.rb index 175d943..aa862a1 100644 --- a/lib/project-honeypot.rb +++ b/lib/project-honeypot.rb @@ -6,7 +6,7 @@ require "project_honeypot/rack/forbidden" module ProjectHoneypot class << self - attr_accessor :api_key + attr_accessor :api_key, :score, :last_activity def api_key raise "ProjectHoneypot really needs its api_key set to work" unless @api_key diff --git a/lib/project_honeypot/url.rb b/lib/project_honeypot/url.rb index 9dee9e3..ce45d34 100644 --- a/lib/project_honeypot/url.rb +++ b/lib/project_honeypot/url.rb @@ -7,8 +7,16 @@ module ProjectHoneypot process_score(honeypot_response) end - def safe? - @safe + def safe?(hash = {}) + score = hash[:score] || ProjectHoneypot.score + last_activity = hash[:last_activity] || ProjectHoneypot.last_activity + + @safe || + !( + last_activity.nil? && score.nil? || + !score.nil? && self.score > score || + !last_activity.nil? && self.last_activity > last_activity + ) end def comment_spammer?