Class: Connoisseur::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Connoisseur.api_key, user_agent: Connoisseur.user_agent) ⇒ Client

Public: Initialize a Connoisseur client.

key - Your Akismet API key, obtained from akismet.com. The default

is Connoisseur.api_key.

user_agent - The String value the client should provide in the User-Agent header when issuing

HTTP requests to the Akismet API. The default is Connoisseur.user_agent.

14
15
16
17
18
# File 'lib/connoisseur/client.rb', line 14

def initialize(key: Connoisseur.api_key, user_agent: Connoisseur.user_agent)
  @key, @user_agent = key, user_agent

  require_usable_key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key


6
7
8
# File 'lib/connoisseur/client.rb', line 6

def key
  @key
end

#user_agentObject (readonly)

Returns the value of attribute user_agent


6
7
8
# File 'lib/connoisseur/client.rb', line 6

def user_agent
  @user_agent
end

Instance Method Details

#check(comment) ⇒ Object

Internal: Determine whether a comment is spam or ham.

comment - A Hash of POST parameters describing the comment.

Returns a Connoisseur::Result. Raises Connoisseur::Result::Invalid if the Akismet API provides an unexpected response.


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

def check(comment)
  validated_result_from post("comment-check", body: comment)
end

#comment(&block) ⇒ Object

Public: Build a comment.

Yields a Connoisseur::Comment::Definition which can be used to declare the comment's attributes.

Examples

client.comment do |c|
  c.blog url: "https://example.com"
  c.post url: "https://example.com/posts/hello-world"
  c.author name: "Jane Smith"
  c.content "Nice post!"
end
# => #<Connoisseur::Comment ...>

Returns a Connoisseur::Comment.


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

def comment(&block)
  Connoisseur::Comment.define self, &block
end

#ham!(comment) ⇒ Object

Internal: Inform Akismet that a comment should have been marked ham.

comment - A Hash of POST parameters describing the comment.

Returns nothing.


73
74
75
# File 'lib/connoisseur/client.rb', line 73

def ham!(comment)
  post "submit-ham", body: comment
end

#spam!(comment) ⇒ Object

Internal: Inform Akismet that a comment should have been marked spam.

comment - A Hash of POST parameters describing the comment.

Returns nothing.


64
65
66
# File 'lib/connoisseur/client.rb', line 64

def spam!(comment)
  post "submit-spam", body: comment
end

#verify_key_for(blog:) ⇒ Object

Public: Verify the client's Akismet API key.

blog - The URL of the blog associated with the key.

Returns true or false indicating whether the key is valid for the given blog.


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

def verify_key_for(blog:)
  post_without_subdomain("verify-key", body: { key: key, blog: blog }).body == "valid"
end