Alkemic / akismet

A GO Akismet client, made for easy use and testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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))

About

A GO Akismet client, made for easy use and testing

License:MIT License


Languages

Language:Go 100.0%