You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
4.0 KiB
155 lines
4.0 KiB
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"jschan/app"
|
|
"jschan/app/models"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
|
|
jschanClient := jschan.NewClient("http://dev-jschan")
|
|
ctx := context.Background()
|
|
|
|
loginOptions := &jschan.PostLoginOptions{
|
|
//Credentials for a private dev jschan
|
|
Username: "admin",
|
|
Password: "gN2gtLUWZCaMm5t16ALq0J7LwEg=",
|
|
Twofactor: "",
|
|
}
|
|
err := jschanClient.Login(ctx, loginOptions)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
if jschanClient.SessionCookie != "" {
|
|
fmt.Printf("Logged in as user %s\n", loginOptions.Username)
|
|
if _, err := jschanClient.GetCSRFToken(ctx); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
|
|
overboardOptions := &jschan.GetOverboardOptions{
|
|
IncludeDefault: true,
|
|
}
|
|
res, err := jschanClient.GetOverboardCatalog(ctx, overboardOptions)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched overboard catalog with %d threads\n", len(res.Threads))
|
|
|
|
getCatalogOptions := &jschan.GetCatalogOptions{
|
|
Board: "test",
|
|
}
|
|
res2, err2 := jschanClient.GetCatalog(ctx, getCatalogOptions)
|
|
if err2 != nil {
|
|
fmt.Println(err2)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched board %s catalog with %d threads\n", getCatalogOptions.Board, len(res2))
|
|
|
|
getThreadOptions := &jschan.GetThreadOptions{
|
|
Board: "test",
|
|
ThreadId: 19,
|
|
}
|
|
res3, err3 := jschanClient.GetThread(ctx, getThreadOptions)
|
|
if err3 != nil {
|
|
fmt.Println(err3)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ thread %d with %d replies\n", getThreadOptions.Board, getThreadOptions.ThreadId, len(res3.Replies))
|
|
|
|
getLogsListOptions := &jschan.GetLogsListOptions{
|
|
Board: "test",
|
|
}
|
|
res4, err4 := jschanClient.GetLogsList(ctx, getLogsListOptions)
|
|
if err4 != nil {
|
|
fmt.Println(err4)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ logs with %d entries\n", getLogsListOptions.Board, len(res4))
|
|
|
|
getLogsOptions := &jschan.GetLogsOptions{
|
|
Board: "test",
|
|
Date: models.LogDate{
|
|
Year: res4[0].Date.Year,
|
|
Month: res4[0].Date.Month,
|
|
Day: res4[0].Date.Day,
|
|
},
|
|
}
|
|
res5, err5 := jschanClient.GetLogs(ctx, getLogsOptions)
|
|
if err5 != nil {
|
|
fmt.Println(err5)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ logs for date %s with %d entries\n", getLogsOptions.Board, getLogsOptions.Date.String(), len(res5))
|
|
|
|
getSettingsOptions := &jschan.GetSettingsOptions{
|
|
Board: "test",
|
|
}
|
|
res6, err6 := jschanClient.GetSettings(ctx, getSettingsOptions)
|
|
if err6 != nil {
|
|
fmt.Println(err6)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ settings. Custompages are: [\"%s\"]\n", getLogsOptions.Board, strings.Join(res6.CustomPages, `", "`))
|
|
|
|
getCustomPageOptions := &jschan.GetCustomPageOptions{
|
|
Board: "test",
|
|
CustomPage: res6.CustomPages[0],
|
|
}
|
|
res7, err7 := jschanClient.GetCustomPage(ctx, getCustomPageOptions)
|
|
if err7 != nil {
|
|
fmt.Println(err7)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched /%s/ custompage \"%s\" published on: %s\n", getCustomPageOptions.Board, getCustomPageOptions.CustomPage, res7.Date.String())
|
|
|
|
getBannersOptions := &jschan.GetBannersOptions{
|
|
Board: "test",
|
|
}
|
|
res8, err8 := jschanClient.GetBanners(ctx, getBannersOptions)
|
|
if err8 != nil {
|
|
fmt.Println(err8)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched banners for /%s/: [\"%s\"]\n", getCustomPageOptions.Board, strings.Join(res8, `", "`))
|
|
|
|
res9, err9 := jschanClient.GetWebring(ctx)
|
|
if err9 != nil {
|
|
fmt.Println(err9)
|
|
//return
|
|
}
|
|
if res9 != nil {
|
|
fmt.Printf("Fetched webring, following: [\"%s\"]\n", strings.Join(res9.Following, `", "`))
|
|
}
|
|
|
|
makePostOptions := &jschan.MakePostOptions{
|
|
Board: "test",
|
|
Thread: 19,
|
|
Name: "Test",
|
|
Message: ">test",
|
|
Email: "sage",
|
|
PostPassword: "123",
|
|
// Files: []string{"./image.png", "./image.png"},
|
|
}
|
|
err10 := jschanClient.MakePost(ctx, makePostOptions)
|
|
if err10 != nil {
|
|
fmt.Println(err10)
|
|
return
|
|
}
|
|
|
|
getManageRecentOptions := &jschan.GetManageRecentOptions{
|
|
Board: "test",
|
|
}
|
|
res11, err11 := jschanClient.GetManageRecent(ctx, getManageRecentOptions)
|
|
if err11 != nil {
|
|
fmt.Println(err11)
|
|
return
|
|
}
|
|
fmt.Printf("Fetched %d manage recent posts for /%s/\n", len(res11), getManageRecentOptions.Board)
|
|
|
|
return
|
|
}
|
|
|