Module: Akismet

Defined in:
lib/akismet.rb,
lib/akismet/error.rb,
lib/akismet/client.rb,
lib/akismet/version.rb

Overview

Akismet provides convenience methods that instantiate a Client and invoke the Akismet API in one call. Before calling these methods, set Akismet.api_key and Akismet.app_url.

Defined Under Namespace

Classes: Client, Error

Constant Summary collapse

VERSION =

The version of the Akismet gem.

'3.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyString

The API key obtained at akismet.com. Set before calling the Akismet class methods.

Returns:

  • (String)


19
20
21
# File 'lib/akismet.rb', line 19

def api_key
  @api_key
end

.app_nameString

The name of the application making the request

Returns:

  • (String)


28
29
30
# File 'lib/akismet.rb', line 28

def app_name
  @app_name
end

.app_urlString

A URL that identifies the application making the request. Set before calling the Akismet class methods.

Returns:

  • (String)


24
25
26
# File 'lib/akismet.rb', line 24

def app_url
  @app_url
end

.app_versionString

The version of the application making the request

Returns:

  • (String)


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

def app_version
  @app_version
end

Class Method Details

.check(user_ip, user_agent, params = {}) ⇒ (Boolean, Boolean)

Checks whether a comment is spam and whether it is “blatant.”

Parameters:

  • user_ip (String)

    The comment author’s IP address

  • user_agent (String)

    The comment author’s user-agent

  • params (Hash{Symbol => Object}) (defaults to: {})

    Optional parameters. To maximize accuracy, pass as many as possible.

Options Hash (params):

  • :referrer (String)

    The value of the HTTP_REFERER header. Note that the parameter is spelled with two consecutive ‘r’s.

  • :post_url (String)

    The URL of the post, article, etc. on which the comment was made

  • :post_modified_at (DateTime)

    The date and time the post was last modified

  • :type (String)

    Suggested values include ‘comment’, ‘trackback’, and ‘pingback’

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    The date and time the comment was created

  • :author (String)

    The comment author’s name

  • :author_email (String)

    The comment author’s email address

  • :author_url (String)

    The comment author’s personal URL

  • :languages (Array<String>)

    The ISO 639-1 codes of the languages in use on the site where the comment appears

  • :test (Boolean)

    When set to true, Akismet does not use the comment to train the filter

  • :env (Hash{Symbol, String => Object})

    Environment variables such as HTTP headers related to the comment submission

Returns:

  • ((Boolean, Boolean))

    An array containing two booleans. The first indicates whether the comment is spam. The second indicates whether it is “blatant,” i.e. whether it can be deleted without review.

Raises:

  • (Akismet::Error)

    The Akismet service returned an error

  • (ArgumentError)

    An environment variable conflicts with a built-in parameter

  • (ArgumentError)

    Invalid param



35
36
37
# File 'lib/akismet.rb', line 35

def check(user_ip, user_agent, params = {})
  with_client { |client| client.check user_ip, user_agent, params }
end

.ham(user_ip, user_agent, params = {}) ⇒ void

This method returns an undefined value.

Submits a comment that has been identified as not-spam (ham).

Parameters:

  • user_ip (String)

    The comment author’s IP address

  • user_agent (String)

    The comment author’s user-agent

  • params (Hash{Symbol => Object}) (defaults to: {})

    Optional parameters. To maximize accuracy, pass as many as possible.

Options Hash (params):

  • :referrer (String)

    The value of the HTTP_REFERER header. Note that the parameter is spelled with two consecutive ‘r’s.

  • :post_url (String)

    The URL of the post, article, etc. on which the comment was made

  • :post_modified_at (DateTime)

    The date and time the post was last modified

  • :type (String)

    Suggested values include ‘comment’, ‘trackback’, and ‘pingback’

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    The date and time the comment was created

  • :author (String)

    The comment author’s name

  • :author_email (String)

    The comment author’s email address

  • :author_url (String)

    The comment author’s personal URL

  • :languages (Array<String>)

    The ISO 639-1 codes of the languages in use on the site where the comment appears

  • :test (Boolean)

    When set to true, Akismet does not use the comment to train the filter

  • :env (Hash{Symbol, String => Object})

    Environment variables such as HTTP headers related to the comment submission

Raises:

  • (Akismet::Error)

    The Akismet service returned an error

  • (ArgumentError)

    An environment variable conflicts with a built-in parameter

  • (ArgumentError)

    Invalid param



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

def ham(user_ip, user_agent, params = {})
  with_client { |client| client.ham user_ip, user_agent, params }
end

.open {|client| ... } ⇒ Object

Initializes a client, opens it, yields it to the given block, and closes it when the block returns. Allows you to perform several operations over a single TCP connection.

Yield Parameters:

Returns:

  • (Object)

    The return value of the block

See Also:

  • #open


55
56
57
# File 'lib/akismet.rb', line 55

def open(&block)
  with_client(&block)
end

.spam(user_ip, user_agent, params = {}) ⇒ void

This method returns an undefined value.

Submits a comment that has been identified as spam.

Parameters:

  • user_ip (String)

    The comment author’s IP address

  • user_agent (String)

    The comment author’s user-agent

  • params (Hash{Symbol => Object}) (defaults to: {})

    Optional parameters. To maximize accuracy, pass as many as possible.

Options Hash (params):

  • :referrer (String)

    The value of the HTTP_REFERER header. Note that the parameter is spelled with two consecutive ‘r’s.

  • :post_url (String)

    The URL of the post, article, etc. on which the comment was made

  • :post_modified_at (DateTime)

    The date and time the post was last modified

  • :type (String)

    Suggested values include ‘comment’, ‘trackback’, and ‘pingback’

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    The date and time the comment was created

  • :author (String)

    The comment author’s name

  • :author_email (String)

    The comment author’s email address

  • :author_url (String)

    The comment author’s personal URL

  • :languages (Array<String>)

    The ISO 639-1 codes of the languages in use on the site where the comment appears

  • :test (Boolean)

    When set to true, Akismet does not use the comment to train the filter

  • :env (Hash{Symbol, String => Object})

    Environment variables such as HTTP headers related to the comment submission

Raises:

  • (Akismet::Error)

    The Akismet service returned an error

  • (ArgumentError)

    An environment variable conflicts with a built-in parameter

  • (ArgumentError)

    Invalid param



45
46
47
# File 'lib/akismet.rb', line 45

def spam(user_ip, user_agent, params = {})
  with_client { |client| client.spam user_ip, user_agent, params }
end

.spam?(user_ip, user_agent, params = {}) ⇒ Boolean

Checks whether a comment is spam.

Parameters:

  • user_ip (String)

    The comment author’s IP address

  • user_agent (String)

    The comment author’s user-agent

  • params (Hash{Symbol => Object}) (defaults to: {})

    Optional parameters. To maximize accuracy, pass as many as possible.

Options Hash (params):

  • :referrer (String)

    The value of the HTTP_REFERER header. Note that the parameter is spelled with two consecutive ‘r’s.

  • :post_url (String)

    The URL of the post, article, etc. on which the comment was made

  • :post_modified_at (DateTime)

    The date and time the post was last modified

  • :type (String)

    Suggested values include ‘comment’, ‘trackback’, and ‘pingback’

  • :text (String)

    The text of the comment

  • :created_at (DateTime)

    The date and time the comment was created

  • :author (String)

    The comment author’s name

  • :author_email (String)

    The comment author’s email address

  • :author_url (String)

    The comment author’s personal URL

  • :languages (Array<String>)

    The ISO 639-1 codes of the languages in use on the site where the comment appears

  • :test (Boolean)

    When set to true, Akismet does not use the comment to train the filter

  • :env (Hash{Symbol, String => Object})

    Environment variables such as HTTP headers related to the comment submission

Returns:

  • (Boolean)

Raises:

  • (Akismet::Error)

    The Akismet service returned an error

  • (ArgumentError)

    An environment variable conflicts with a built-in parameter

  • (ArgumentError)

    Invalid param



40
41
42
# File 'lib/akismet.rb', line 40

def spam?(user_ip, user_agent, params = {})
  with_client { |client| client.spam? user_ip, user_agent, params }
end