Class: Akismet
- Inherits:
-
Object
- Object
- Akismet
- Defined in:
- lib/akismet.rb
Constant Summary collapse
- HOST =
'rest.akismet.com'
- PORT =
80
- TIMEOUT_THRESHOLD =
10
- VALID_RESPONSES =
Set.new(['false', ''])
- NORMAL_RESPONSES =
VALID_RESPONSES.dup << 'true'
- STANDARD_HEADERS =
{ 'User-Agent' => "Akismet Checker", 'Content-Type' => 'application/x-www-form-urlencoded' }
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#normal_responses ⇒ Object
Returns the value of attribute normal_responses.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
-
#standard_headers ⇒ Object
Returns the value of attribute standard_headers.
-
#valid_responses ⇒ Object
Returns the value of attribute valid_responses.
Class Method Summary collapse
-
.url(action) ⇒ Object
Returns the URL for an Akismet request.
Instance Method Summary collapse
- #check_comment(options = {}) ⇒ Object
-
#initialize(options) ⇒ Akismet
constructor
Create a new instance of the Akismet class.
- #invalid_options? ⇒ Boolean
-
#mark_as_ham(options = {}) ⇒ Object
This call is intended for the marking of false positives, things that were incorrectly marked as spam.
-
#mark_as_spam(options = {}) ⇒ Object
This call is for submitting comments that weren’t marked as spam but should have been (i.e. false negatives).
- #spam?(options = {}) ⇒ Boolean
-
#verified? ⇒ Boolean
Returns
true
if the API key has been verified,false
otherwise.
Constructor Details
#initialize(options) ⇒ Akismet
Create a new instance of the Akismet class
Arguments
Arguments are provided in the form of a Hash with the following keys (as Symbols) available:
api_key
-
your Akismet API key
blog
-
the blog associated with your api key
The following keys are available and are entirely optional. They are available incase communication with Akismet’s servers requires a proxy port and/or host:
-
proxy_port
-
proxy_host
34 35 36 37 |
# File 'lib/akismet.rb', line 34 def initialize() @options = self.verified_key = false end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/akismet.rb', line 7 def host @host end |
#normal_responses ⇒ Object
Returns the value of attribute normal_responses.
7 8 9 |
# File 'lib/akismet.rb', line 7 def normal_responses @normal_responses end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/akismet.rb', line 7 def @options end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/akismet.rb', line 7 def port @port end |
#standard_headers ⇒ Object
Returns the value of attribute standard_headers.
7 8 9 |
# File 'lib/akismet.rb', line 7 def standard_headers @standard_headers end |
#valid_responses ⇒ Object
Returns the value of attribute valid_responses.
7 8 9 |
# File 'lib/akismet.rb', line 7 def valid_responses @valid_responses end |
Class Method Details
.url(action) ⇒ Object
Returns the URL for an Akismet request
Arguments
action
<~to_s>-
a valid Akismet function name
Returns
String
84 85 86 |
# File 'lib/akismet.rb', line 84 def self.url(action) "/1.1/#{action}" end |
Instance Method Details
#check_comment(options = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/akismet.rb', line 48 def check_comment(={}) return false if = ('comment-check', ) {:spam => !VALID_RESPONSES.include?(), :message => } end |
#invalid_options? ⇒ Boolean
44 45 46 |
# File 'lib/akismet.rb', line 44 def false end |
#mark_as_ham(options = {}) ⇒ Object
This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as check_comment
and mark_as_spam
.
72 73 74 75 |
# File 'lib/akismet.rb', line 72 def mark_as_ham(={}) return false if {:message => ('submit-ham', )} end |
#mark_as_spam(options = {}) ⇒ Object
This call is for submitting comments that weren’t marked as spam but should have been (i.e. false negatives). It takes identical arguments as check_comment
.
64 65 66 67 |
# File 'lib/akismet.rb', line 64 def mark_as_spam(={}) return false if {:message => ('submit-spam', )} end |
#spam?(options = {}) ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/akismet.rb', line 54 def spam?( = {}) if resp = check_comment() return resp[:spam] end false end |
#verified? ⇒ Boolean
Returns true
if the API key has been verified, false
otherwise
40 41 42 |
# File 'lib/akismet.rb', line 40 def verified? (@verified_key ||= verify_api_key) != :false end |