akismet

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 9 Imported by: 0

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

func NewAkismet(key, blogUrl string, optFns ...OptFn) (*akismetClient, error)

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.

func (*Comment) Validate

func (c *Comment) Validate() error

Validate checks if user ip and user agent are present, and if present validates create/update dates.

type OptFn

type OptFn func(c *akismetClient)

func WithHttpClient

func WithHttpClient(httpClient *http.Client) OptFn

WithHttpClient is client functional option to set custom httpClient.

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL