-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
65 lines (55 loc) · 2.07 KB
/
example_test.go
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
package gokismet_test
import (
"fmt"
"time"
"github.com/deepilla/gokismet"
)
func ExampleChecker_Check() {
// This example defines content as a map of key-value pairs
// (see the Akismet docs for a list of valid keys). Gokismet
// also provides a Comment type that generates this map for you.
values := map[string]string{
"user_ip": "127.0.0.1",
"user_agent": "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6",
"permalink": "http://your-website.com/posts/feliz-cinco-de-mayo/",
"comment_post_modified_gmt": "2016-05-05T10:30:00Z",
"comment_author": "A. Commenter",
"comment_author_email": "[email protected]",
"comment_content": "I love Cinco de Mayo!",
// etc...
}
ch := gokismet.NewChecker("YOUR-API-KEY", "http://your-website.com")
status, err := ch.Check(values)
switch status {
case gokismet.StatusHam:
fmt.Println("This is legit content")
case gokismet.StatusProbableSpam, gokismet.StatusDefiniteSpam:
fmt.Println("This is spam")
case gokismet.StatusUnknown:
fmt.Println("Something went wrong:", err)
}
}
func ExampleChecker_Check_comment() {
// This example uses the Comment type to define content.
// You can also use a map of key-value pairs.
comment := gokismet.Comment{
UserIP: "127.0.0.1",
UserAgent: "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6",
Page: "http://your-website.com/posts/feliz-cinco-de-mayo/",
PageTimestamp: time.Date(2016, time.May, 5, 10, 30, 0, 0, time.UTC),
Author: "A. Commenter",
AuthorEmail: "[email protected]",
Content: "I love Cinco de Mayo!",
// etc...
}
ch := gokismet.NewChecker("YOUR-API-KEY", "http://your-website.com")
status, err := ch.Check(comment.Values())
switch status {
case gokismet.StatusHam:
fmt.Println("This is legit content")
case gokismet.StatusProbableSpam, gokismet.StatusDefiniteSpam:
fmt.Println("This is spam")
case gokismet.StatusUnknown:
fmt.Println("Something went wrong:", err)
}
}