1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
%w{
version
error
client
}.each do |file|
require "akismet/#{file}"
end
# {Akismet} provides convenience methods that instantiate a {Akismet::Client}
# and invoke the Akismet API in one call. Before calling these methods, set
# {api_key} and {app_url}.
#
module Akismet
class << self
# The API key obtained at akismet.com. Set before calling the {Akismet}
# class methods.
# @return [String]
attr_accessor :api_key
# A URL that identifies the application making the request. Set before
# calling the {Akismet} class methods.
# @return [String]
attr_accessor :app_url
# The name of the application making the request
# @return [String]
attr_accessor :app_name
# The version of the application making the request
# @return [String]
attr_accessor :app_version
# (see Client#check)
def check(user_ip, user_agent, params = {})
with_client { |client| client.check user_ip, user_agent, params }
end
# (see Client#spam?)
def spam?(user_ip, user_agent, params = {})
with_client { |client| client.spam? user_ip, user_agent, params }
end
# (see Client#spam)
def spam(user_ip, user_agent, params = {})
with_client { |client| client.spam user_ip, user_agent, params }
end
# (see Client#ham)
def ham(user_ip, user_agent, params = {})
with_client { |client| client.ham user_ip, user_agent, params }
end
# (see Client.open)
def open(&block)
with_client(&block)
end
private
def with_client(&block)
raise "Set Akismet.api_key" unless api_key
raise "Set Akismet.app_url" unless app_url
Akismet::Client.open api_key, app_url, app_name: app_name, app_version: app_version, &block
end
end
end
|