class Connoisseur::Result
Attributes
response[R]
Public Class Methods
new(response)
click to toggle source
Internal: Initialize a Connoisseur::Result
.
response - A Net::HTTPResponse from a comment check request.
# File lib/connoisseur/result.rb, line 7 def initialize(response) @response = response end
Public Instance Methods
discard?()
click to toggle source
Public: Determine whether the comment is egregious spam which should be discarded.
Returns a boolean indicating whether Akismet recommends discarding the comment.
# File lib/connoisseur/result.rb, line 21 def discard? response.header["X-Akismet-Pro-Tip"] == "discard" end
spam?()
click to toggle source
Public: Determine whether the comment is spam.
Returns a boolean indicating whether Akismet recognizes the comment as spam.
# File lib/connoisseur/result.rb, line 14 def spam? response.body == "true" end
validated()
click to toggle source
Internal: Validate the response from the Akismet API.
Ensures that the response has a successful status code (in the range 200…300) and that the response body is a boolean (“true” or “false”).
Returns the receiving Result
. Raises Connoisseur::Result::InvalidError
if the Akismet API provided an unexpected response.
# File lib/connoisseur/result.rb, line 32 def validated require_successful_response require_boolean_response_body self end
Private Instance Methods
require_boolean_response_body()
click to toggle source
# File lib/connoisseur/result.rb, line 47 def require_boolean_response_body unless %w( true false ).include?(response.body) if message = response.header["X-Akismet-Debug-Help"] raise InvalidError, "Expected boolean response body, got #{response.body.inspect} (#{message})" else raise InvalidError, "Expected boolean response body, got #{response.body.inspect}" end end end
require_successful_response()
click to toggle source
# File lib/connoisseur/result.rb, line 43 def require_successful_response raise InvalidError, "Expected successful response, got #{response.code}" unless response.is_a?(Net::HTTPSuccess) end