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"`
}
type Settings struct {
Sfw bool `json:"sfw"`
Name string `json:"name"`
Description string `json:"description"`
Sfw bool `json:"sfw"`
Name string `json:"name"`
Description string `json:"description"`
UnlistedLocal bool `json:"unlistedLocal,omitempty"`
}
type Boards struct {
@ -32,18 +32,18 @@ type Boards struct {
Ppd int `json:"ppd,omitempty"`
}
type GetBoardsResponse struct {
Boards []Boards `json:"boards"`
Page int `json:"page"`
MaxPage int `json:"maxPage"`
Boards []Boards `json:"boards"`
Page int `json:"page"`
MaxPage int `json:"maxPage"`
}
type GetBoardsPublicOptions struct {
Search string `json:"search"`
Sort string `json:"sort"`
SortDirection string `json:"direction"`
Page int `json:"page"`
LocalFirst bool `json:"local_first"`
Sites []string `json:"sites"`
Search string `json:"search"`
Sort string `json:"sort"`
SortDirection string `json:"direction"`
Page int `json:"page"`
LocalFirst bool `json:"local_first"`
Sites []string `json:"sites"`
}
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())
req, err := http.NewRequest("GET", url, nil);
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
@ -94,13 +94,13 @@ func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOp
}
type GetBoardsGlobalmanageOptions struct {
Search string `json:"search"`
Sort string `json:"sort"`
SortDirection string `json:"direction"`
Page int `json:"page"`
FilterUnlisted bool `json:"filter_unlisted"`
FilterSfw bool `json:"filter_sfw"`
FilterAbandoned bool `json:"filter_abandoned"`
Search string `json:"search"`
Sort string `json:"sort"`
SortDirection string `json:"direction"`
Page int `json:"page"`
FilterUnlisted bool `json:"filter_unlisted"`
FilterSfw bool `json:"filter_sfw"`
FilterAbandoned bool `json:"filter_abandoned"`
}
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())
req, err := http.NewRequest("GET", url, nil);
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err

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

Loading…
Cancel
Save