master
Thomas Lynch 2 years ago
parent 97b3a747af
commit 515d671827
  1. 42
      app/boardlist.go
  2. 24
      app/jschan.go

@ -12,9 +12,9 @@ type LastPostTimestamp struct {
Color string `json:"color"` Color string `json:"color"`
} }
type Settings struct { type Settings struct {
Sfw bool `json:"sfw"` Sfw bool `json:"sfw"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
UnlistedLocal bool `json:"unlistedLocal,omitempty"` UnlistedLocal bool `json:"unlistedLocal,omitempty"`
} }
type Boards struct { type Boards struct {
@ -32,18 +32,18 @@ type Boards struct {
Ppd int `json:"ppd,omitempty"` Ppd int `json:"ppd,omitempty"`
} }
type GetBoardsResponse struct { type GetBoardsResponse struct {
Boards []Boards `json:"boards"` Boards []Boards `json:"boards"`
Page int `json:"page"` Page int `json:"page"`
MaxPage int `json:"maxPage"` MaxPage int `json:"maxPage"`
} }
type GetBoardsPublicOptions struct { type GetBoardsPublicOptions struct {
Search string `json:"search"` Search string `json:"search"`
Sort string `json:"sort"` Sort string `json:"sort"`
SortDirection string `json:"direction"` SortDirection string `json:"direction"`
Page int `json:"page"` Page int `json:"page"`
LocalFirst bool `json:"local_first"` LocalFirst bool `json:"local_first"`
Sites []string `json:"sites"` Sites []string `json:"sites"`
} }
func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOptions) (*GetBoardsResponse, error) { func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOptions) (*GetBoardsResponse, error) {
@ -77,7 +77,7 @@ func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOp
url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode()) url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode())
req, err := http.NewRequest("GET", url, nil); req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -94,13 +94,13 @@ func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOp
} }
type GetBoardsGlobalmanageOptions struct { type GetBoardsGlobalmanageOptions struct {
Search string `json:"search"` Search string `json:"search"`
Sort string `json:"sort"` Sort string `json:"sort"`
SortDirection string `json:"direction"` SortDirection string `json:"direction"`
Page int `json:"page"` Page int `json:"page"`
FilterUnlisted bool `json:"filter_unlisted"` FilterUnlisted bool `json:"filter_unlisted"`
FilterSfw bool `json:"filter_sfw"` FilterSfw bool `json:"filter_sfw"`
FilterAbandoned bool `json:"filter_abandoned"` FilterAbandoned bool `json:"filter_abandoned"`
} }
func (c *Client) GetBoardsGlobalmanage(ctx context.Context, options *GetBoardsGlobalmanageOptions) (*GetBoardsResponse, error) { func (c *Client) GetBoardsGlobalmanage(ctx context.Context, options *GetBoardsGlobalmanageOptions) (*GetBoardsResponse, error) {
@ -139,7 +139,7 @@ func (c *Client) GetBoardsGlobalmanage(ctx context.Context, options *GetBoardsGl
url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode()) url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode())
req, err := http.NewRequest("GET", url, nil); req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
return nil, err return nil, err

@ -1,25 +1,25 @@
package jschan package jschan
import ( import (
"net/http"
"time"
"fmt"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"net/http"
"time"
) )
type Client struct { type Client struct {
BaseURL string BaseURL string
SessionCookie string SessionCookie string
CsrfToken string CsrfToken string
HTTPClient *http.Client HTTPClient *http.Client
} }
func NewClient(baseURL string) *Client { func NewClient(baseURL string) *Client {
return &Client{ return &Client{
BaseURL: baseURL, BaseURL: baseURL,
SessionCookie: "", SessionCookie: "",
CsrfToken: "", CsrfToken: "",
HTTPClient: &http.Client{ HTTPClient: &http.Client{
Timeout: time.Minute, Timeout: time.Minute,
}, },
@ -27,8 +27,8 @@ func NewClient(baseURL string) *Client {
} }
type DynamicResponse struct { type DynamicResponse struct {
Title string `json:"title"` Title string `json:"title"`
Message string `json:"message"` Message string `json:"message"`
Redirect string `json:"redirect,omitempty"` Redirect string `json:"redirect,omitempty"`
} }
@ -40,7 +40,7 @@ func (c *Client) sendRequest(req *http.Request, v interface{}) error {
} }
if c.CsrfToken != "" { if c.CsrfToken != "" {
// TODO // TODO
} }
res, err := c.HTTPClient.Do(req) res, err := c.HTTPClient.Do(req)
if err != nil { if err != nil {
@ -60,6 +60,6 @@ func (c *Client) sendRequest(req *http.Request, v interface{}) error {
if err = json.NewDecoder(res.Body).Decode(&fullResponse); err != nil { if err = json.NewDecoder(res.Body).Decode(&fullResponse); err != nil {
return err return err
} }
return nil return nil
} }

Loading…
Cancel
Save