Catalogs, threads, parse json array response of threads (For catalog), ahndle scuffed time format for bumped/date/edited
parent
c86ef11ff4
commit
5418bc6479
5 changed files with 112 additions and 14 deletions
@ -0,0 +1,36 @@ |
|||||||
|
package jschan |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"jschan/app/models" |
||||||
|
"net/http" |
||||||
|
) |
||||||
|
|
||||||
|
type GetCatalogOptions struct { |
||||||
|
Board string |
||||||
|
} |
||||||
|
|
||||||
|
type CatalogResponse []models.Post |
||||||
|
|
||||||
|
func (c *Client) GetCatalog(ctx context.Context, options *GetCatalogOptions) (CatalogResponse, error) { |
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/%s/catalog.json", c.BaseURL, options.Board) |
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
req = req.WithContext(ctx) |
||||||
|
|
||||||
|
res := CatalogResponse{} |
||||||
|
if err := c.sendRequest(req, &res, nil); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
return res, nil |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
//TODO: GetIndex, GetLogs, etc
|
@ -0,0 +1,37 @@ |
|||||||
|
package jschan |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"jschan/app/models" |
||||||
|
"net/http" |
||||||
|
) |
||||||
|
|
||||||
|
type GetThreadOptions struct { |
||||||
|
Board string |
||||||
|
ThreadId int |
||||||
|
} |
||||||
|
|
||||||
|
type GetThreadResponse struct { |
||||||
|
*models.Post |
||||||
|
} |
||||||
|
|
||||||
|
func (c *Client) GetThread(ctx context.Context, options *GetThreadOptions) (*GetThreadResponse, error) { |
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/%s/thread/%d.json", c.BaseURL, options.Board, options.ThreadId) |
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
req = req.WithContext(ctx) |
||||||
|
|
||||||
|
res := GetThreadResponse{} |
||||||
|
if err := c.sendRequest(req, &res, nil); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
return &res, nil |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue