class DodgyStalker::Engines::StopForumSpam
Public Class Methods
new(attributes)
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 5 def initialize(attributes) @attributes = attributes end
Public Instance Methods
on_blacklist?()
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 9 def on_blacklist? confidence_for(:username) > 0.75 || confidence_for(:email) > 0.75 end
Private Instance Methods
attributes()
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 36 def attributes @attributes.select {|k,v| [:username, :email].include?(k)} end
confidence_for(key)
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 15 def confidence_for(key) response[key.to_s]['confidence'].to_f rescue #if anything goes wrong do not crash 0.0 end
query_stopforumspam()
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 21 def query_stopforumspam Typhoeus.get(url) end
response()
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 25 def response @response ||= JSON.parse(query_stopforumspam.body) end
url()
click to toggle source
# File lib/dodgy_stalker/engines/stop_forum_spam.rb, line 29 def url base = 'http://www.stopforumspam.com/api' uri = Addressable::URI.parse(base) uri.query_values = attributes.merge({f: 'json'}) uri.to_s end