README
¶
akismet
A GO Akismet client, made for easy use and testing
Installation
$ go get github.com/Alkemic/akismet
Usage
Validate you key:
akismetClient, _ := akismet.NewClient("akismet-key", "http://some-blog.com")
ctx := context.Background()
validated, err := akismetClient.Valid(ctx)
if err != nil {
// handle error
}
Check if comment is a SPAM:
akismetClient, _ := akismet.NewClient("akismet-key", "http://some-blog.com")
ctx := context.Background()
isSpam, err := akismetClient.Check(ctx, &akismet.Comment{
Type: "comment",
Author: "John Doe",
UserIP: "1.2.3.4",
})
if err != nil {
// handle error
}
Submit SPAM:
akismetClient, _ := akismet.NewClient("akismet-key", "http://some-blog.com")
ctx := context.Background()
err := akismetClient.SubmitSpam(ctx, &akismet.Comment{
Type: "comment",
Author: "John Doe",
UserIP: "1.2.3.4",
})
if err != nil {
// handle error
}
Submit HAM (aka false positive):
akismetClient, _ := akismet.NewClient("akismet-key", "http://some-blog.com")
ctx := context.Background()
err := akismetClient.SubmitHam(ctx, &akismet.Comment{
Type: "comment",
Author: "John Doe",
UserIP: "1.2.3.4",
})
if err != nil {
// handle error
}
Advanced usage
You can use your own http.Client
instance with calls to API, just use WithHttpClient
functional option:
customHttpClient := &http.Client{
// your options here
}
akismet.NewClient("akismet-key", "http://some-blog.com", WithHttpClient(customHttpClient))
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUnusualResponse indicates that we got response that we were not expecting, i.e.: comment check can return // true or false, but also some error information. ErrUnusualResponse = stderr.New("got unusual response") // ErrAPIKeyRequired indicates that API key was not provided. ErrAPIKeyRequired = stderr.New("API key is required") // ErrAPIKeyRequired indicates that blog url was not provided. ErrBlogURLRequired = stderr.New("blog url is required") // ErrBlogURLIncorrect indicates that provided blog url is not valid, i.e. missing scheme. ErrBlogURLIncorrect = stderr.New("incorrect blog url") )
View Source
var ErrNonOKStatusCode = errors.New("akismet API returned non 200 status code")
Functions ¶
func NewAkismet ¶
NewAkismet returns new instance of Akismet client with optional error.
Types ¶
type Comment ¶
type Comment struct { UserIP string UserAgent string Referrer string Permalink string Type string Author string AuthorEmail string AuthorURL string Content string Language string Charset string UserRole string Created string Modified string IsTest string RecheckReason string }
Comment struct represents all information that will be send to endpoint.
Click to show internal directories.
Click to hide internal directories.