commit 07cc116463b85409e95e225929992a73a59b5b2e
parent 612738049ef9d092560a198a09ad8a6fac008d0e
Author: Paco Esteban <paco@e1e0.net>
Date: Fri, 31 Jul 2020 16:48:12 +0200
implement `ls` which lists feeds by category id
Diffstat:
2 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/cmd/ttrss-cli/main.go b/cmd/ttrss-cli/main.go
@@ -38,8 +38,23 @@ func main() {
Name: "list",
Aliases: []string{"ls"},
Usage: "list feeds",
+ Flags: []cli.Flag{
+ &cli.IntFlag{
+ Name: "c",
+ Aliases: []string{"cat", "category"},
+ Value: -3,
+ Usage: "Category id",
+ },
+ },
Action: func(c *cli.Context) error {
- ttrssCli.List(42)
+ feeds, err := ttrssCli.List(c.Int("c"))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ for _, feed := range feeds {
+ fmt.Printf("%s \n", feed.Title)
+ }
return nil
},
},
diff --git a/pkg/ttrss/ttrss.go b/pkg/ttrss/ttrss.go
@@ -50,8 +50,15 @@ type Client struct {
httpClient *http.Client
}
-type Item struct {
- Name string
+type Feed struct {
+ Id int `json:"id"`
+ Title string `json:"title"`
+ FeedUrl string `json:"feed_url"`
+ Unread int `json:"unread"`
+ HasIcon bool `json:"has_icon"`
+ CatId int `json:"cat_id"`
+ LastUpdated int64 `json:"last_updated"`
+ OrderId int `json:"order_id"`
}
type Category struct {
@@ -192,13 +199,28 @@ func (c *Client) Categories() ([]Category, error) {
}
// List feeds in a category
-func (c *Client) List(category int) ([]Item, error) {
+func (c *Client) List(category int) ([]Feed, error) {
if err := c.login(); err != nil {
return nil, err
}
- var items []Item
- return items, nil
+ var feeds []Feed
+ feedMap := map[string]interface{}{
+ "op": "getFeeds",
+ "unread_only": "false",
+ "cat_id": category,
+ }
+ resp, err := c.apiCall(feedMap)
+ if err != nil {
+ return feeds, err
+ }
+
+ if err = json.Unmarshal(resp.Content, &feeds); err != nil {
+ err = fmt.Errorf("api error JSON unmarshall feeds: %v", err)
+ return feeds, err
+ }
+
+ return feeds, nil
}
// Subscribe to feed