Module: Antispam::Checker

Defined in:
lib/antispam/checker.rb

Class Method Summary collapse

Class Method Details

.check(options = {}) ⇒ Object

Checks content for spam check(options) Usage: check(“No spam here”, providers: { defendium: ‘MY_API_KEY’})



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/antispam/checker.rb', line 6

def self.check(options = {})
  # Default provider. 'YOUR_KEY' works temporarily, giving a warning but also giving results
  # eventually add something to tell users to add their own keys
  # or choose their preferred provider, when more provider options are added.
  options[:providers] ||= {defendium: 'YOUR_KEY'}
  Rails.logger.info "Content was nil for spamcheck." if options[:content].nil? && options[:verbose]
  return if options[:content].nil?
  Rails.logger.info "Spamcheckers should be a hash" if (!(options[:providers].is_a? Hash)) && options[:verbose]
  results = []
  options[:providers].each do |spamchecker_name, spamchecker_api_key|
    results.append spamchecker(spamchecker_name).check(options[:content], spamchecker_api_key, options[:verbose])
    # if spamchecker_name == :defendium
    #   results.append Antispam::Spamcheckers::Defendium.check(options[:content], spamchecker_api_key, options[:verbose])
    # end
  end
  result = Antispam::SpamcheckResult.new(results)
  return result
end

.spamchecker(provider) ⇒ Object



24
25
26
27
28
# File 'lib/antispam/checker.rb', line 24

def self.spamchecker(provider)
  class_name = provider.to_s.camelize
  raise Antispam::NoSuchSpamcheckerError unless Antispam::Spamcheckers.const_defined? class_name
  Antispam::Spamcheckers.const_get class_name
end