Module: Antispam::Checker
- Defined in:
- lib/antispam/checker.rb
Class Method Summary collapse
-
.check(options = {}) ⇒ Object
Checks content for spam check(options) Usage: check(“No spam here”, providers: { defendium: ‘MY_API_KEY’}).
- .spamchecker(provider) ⇒ Object
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( = {}) # 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. [:providers] ||= {defendium: 'YOUR_KEY'} Rails.logger.info "Content was nil for spamcheck." if [:content].nil? && [:verbose] return if [:content].nil? Rails.logger.info "Spamcheckers should be a hash" if (!([:providers].is_a? Hash)) && [:verbose] results = [] [:providers].each do |spamchecker_name, spamchecker_api_key| results.append spamchecker(spamchecker_name).check([:content], spamchecker_api_key, [: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 |