View Source Akismet (Akismet v0.1.0)

Easily check comments with Akismet from Elixir.

Note: You need to provide AKISMET_KEY as an environment variable.

Examples

Export your Akismet key...

export AKISMET_KEY='myakismetkey123'

Then use this library from Elixir:

{:ok, akismet} = Akismet.init("https://example.com")
result0 = Akismet.check_comment(akismet, user_ip, [comment_content: content, comment_author_email: email, ...])
result1 = Akismet.submit_spam(akismet, user_ip, [comment_content: content, comment_author_email: email, ...])
result2 = Akismet.submit_ham(akismet, user_ip, [comment_content: content, comment_author_email: email, ...])
{:ok, %{limit: limit, usage: usage, percentage: pct, throttled: throttled}} = Akismet.usage_limit(akismet)

(You should probably handle errors, these are just quick examples.)

Summary

Functions

Initializes the client. This verifies the API key, set in the environment variable AKISMET_KEY.

Get usage limit.

Functions

Link to this function

check_comment(base, user_ip, params)

View Source

Check a comment.

Arguments:

  • the struct returned by init/1,
  • the IP of the commenter,
  • and extra parameters in the format [user_agent: value, comment_type: value], etc.

Returns

  • :spam,
  • :discard_spam: Akismet says the comment is "blatant spam" and does not need to be stored,
  • :ham,
  • {:akismet_error, "debug help"}: Akismet returned an error and the second element is the help/debugging message, if it exists.
  • or :error: could not access the Akismet endpoint.

Initializes the client. This verifies the API key, set in the environment variable AKISMET_KEY.

Returns

  • {:ok, Akismet}: API key is valid and successfully verified,
  • :key_not_set: the environment variable AKISMET_KEY is not set,
  • :invalid_key: your API key is not valid,
  • or :error: couldn't access the Akismet endpoint.
Link to this function

submit_ham(base, user_ip, params)

View Source

Submit ham.

Arguments:

  • the struct returned by init/1,
  • the IP of the commenter,
  • and extra parameters in the format [user_agent: value, comment_type: value], etc.

Returns

  • :success: submitted spam successfully,
  • :failed: failed to submit spam,
  • or :error: could not access the Akismet endpoint.
Link to this function

submit_spam(base, user_ip, params)

View Source

Submit spam.

Arguments:

  • the struct returned by init/1,
  • the IP of the commenter,
  • and extra parameters in the format [user_agent: value, comment_type: value], etc.

Returns

  • :success: submitted spam successfully,
  • :failed: failed to submit spam,
  • or :error: could not access the Akismet endpoint.

Get usage limit.

Arguments:

  • the struct returned by init/1,

Returns: