Class: Akismetor

Inherits:
Object
  • Object
show all
Defined in:
lib/akismetor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Akismetor

Returns a new instance of Akismetor.



54
55
56
# File 'lib/akismetor.rb', line 54

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



26
27
28
# File 'lib/akismetor.rb', line 26

def attributes
  @attributes
end

Class Method Details

.spam?(attributes) ⇒ Boolean

Does a comment-check on Akismet with the submitted hash. Returns true or false depending on response.

Returns:

  • (Boolean)


38
39
40
# File 'lib/akismetor.rb', line 38

def self.spam?(attributes)
  self.new(attributes).execute('comment-check') != "false"
end

.submit_ham(attributes) ⇒ Object

Does a submit-ham on Akismet with the submitted hash. Use this for a false positive, when Akismet incorrectly rejects a normal comment.



50
51
52
# File 'lib/akismetor.rb', line 50

def self.submit_ham(attributes)
  self.new(attributes).execute('submit-ham')
end

.submit_spam(attributes) ⇒ Object

Does a submit-spam on Akismet with the submitted hash. Use this when Akismet incorrectly approves a spam comment.



44
45
46
# File 'lib/akismetor.rb', line 44

def self.submit_spam(attributes)
  self.new(attributes).execute('submit-spam')
end

.valid_key?(attributes) ⇒ Boolean

Does a key-check on Akismet so you know you can actually use a specific key. Returns “valid” or “invalid” depending on response.

Returns:

  • (Boolean)


32
33
34
# File 'lib/akismetor.rb', line 32

def self.valid_key?(attributes)
  self.new(attributes).execute('verify-key')
end

Instance Method Details

#execute(command) ⇒ Object



58
59
60
61
62
# File 'lib/akismetor.rb', line 58

def execute(command)
  host = "#{@attributes[:key]}." if attributes[:key] && command != 'verify-key'
  http = Net::HTTP.new("#{host}rest.akismet.com", 80)
  http.post("/1.1/#{command}", attributes_for_post, http_headers).body
end