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.
76 lines
2.2 KiB
76 lines
2.2 KiB
package jschan
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type LastPostTimestamp struct {
|
|
Text string `json:"text"`
|
|
Color string `json:"color"`
|
|
}
|
|
type Settings struct {
|
|
Sfw bool `json:"sfw"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
UnlistedLocal bool `json:"unlistedLocal,omitempty"`
|
|
}
|
|
type Boards struct {
|
|
ID string `json:"_id"`
|
|
URI string `json:"uri,omitempty"`
|
|
Path string `json:"path,omitempty"`
|
|
LastPostTimestamp LastPostTimestamp `json:"lastPostTimestamp"`
|
|
Tags []interface{} `json:"tags,omitempty"`
|
|
SiteName string `json:"siteName,omitempty"`
|
|
SequenceValue int `json:"sequence_value"`
|
|
Pph int `json:"pph"`
|
|
Ips int `json:"ips"`
|
|
Settings Settings `json:"settings,omitempty"`
|
|
Webring bool `json:"webring"`
|
|
Ppd int `json:"ppd,omitempty"`
|
|
}
|
|
type GetBoardsOptions struct {
|
|
Search string `json:"search"`
|
|
Sort string `json:"sort"`
|
|
SortDirection string `json:"direction"`
|
|
LocalFirst bool `json:"local_first"`
|
|
Sites []string `json:"sites"`
|
|
Page int `json:"page"`
|
|
}
|
|
|
|
|
|
type GetBoardsResponse struct {
|
|
Boards []Boards `json:"boards"`
|
|
Page int `json:"page"`
|
|
MaxPage int `json:"maxPage"`
|
|
}
|
|
|
|
func (c *Client) GetBoards(ctx context.Context, options *GetBoardsOptions) (*GetBoardsResponse, error) {
|
|
page := 1
|
|
search := ""
|
|
sort := "popularity"
|
|
direction := "desc"
|
|
local_first := false
|
|
sites := []string{}
|
|
if options != nil {
|
|
search = options.Search
|
|
sort = options.Sort
|
|
direction = options.SortDirection
|
|
local_first = options.LocalFirst
|
|
sites = options.Sites
|
|
page = options.Page
|
|
}
|
|
url := fmt.Sprintf("%s/boards.json?search=%s&page=%d&sort=%s&direction=%s&local_first=%t&sites=%s", c.BaseURL, search, page, sort, direction, local_first, sites)
|
|
// fmt.Printf("GETting %s\n", url)
|
|
req, err := http.NewRequest("GET", url, nil);
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req = req.WithContext(ctx)
|
|
res := GetBoardsResponse{}
|
|
if err := c.sendRequest(req, &res); err != nil {
|
|
return nil, err
|
|
}
|
|
return &res, nil
|
|
}
|
|
|