aboutsummaryrefslogtreecommitdiff
path: root/miniflux/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'miniflux/client.go')
-rw-r--r--miniflux/client.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/miniflux/client.go b/miniflux/client.go
index ae23fe3..d430852 100644
--- a/miniflux/client.go
+++ b/miniflux/client.go
@@ -82,6 +82,18 @@ type Feed struct {
Title string `json:"title"`
}
+// FeedInfo is one subscription as returned by GET /v1/feeds (the pruning-
+// audit view; richer than the per-entry Feed subset above).
+type FeedInfo struct {
+ ID int64 `json:"id"`
+ Title string `json:"title"`
+ SiteURL string `json:"site_url"`
+ Disabled bool `json:"disabled"`
+ Category struct {
+ Title string `json:"title"`
+ } `json:"category"`
+}
+
// Entry is the subset of a Miniflux entry fluxrec needs. JSON field names
// match the Miniflux API verbatim so decoding is a straight mirror.
type Entry struct {
@@ -103,6 +115,7 @@ type Entry struct {
type Filters struct {
Starred *bool // only starred entries when true
Status string // "read" | "unread"; "" = any
+ FeedID int64 // restrict to one feed (feeds-lane volume probes)
ChangedAfter int64 // unix timestamp; incremental export cursor
PublishedAfter int64 // unix timestamp; only entries published after this
AfterEntryID int64 // serve-lane poll cursor
@@ -137,10 +150,28 @@ func (c *Client) RawEntries(f Filters) ([]byte, error) {
return c.fetchEntries(f)
}
+// Feeds calls GET /v1/feeds, returning every subscription (the audit lane:
+// one call, no paging).
+func (c *Client) Feeds() ([]FeedInfo, error) {
+ body, err := c.getJSON(c.baseURL + "/v1/feeds")
+ if err != nil {
+ return nil, err
+ }
+ var feeds []FeedInfo
+ if err := json.Unmarshal(body, &feeds); err != nil {
+ return nil, fmt.Errorf("decoding /v1/feeds response: %w", err)
+ }
+ return feeds, nil
+}
+
// fetchEntries issues the GET and returns the body on HTTP 200.
func (c *Client) fetchEntries(f Filters) ([]byte, error) {
- u := entriesURL(c.baseURL, f)
+ return c.getJSON(entriesURL(c.baseURL, f))
+}
+// getJSON GETs u with the auth header and returns the body on HTTP 200;
+// any other status becomes an error naming the status and a response sniff.
+func (c *Client) getJSON(u string) ([]byte, error) {
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, fmt.Errorf("building request: %w", err)
@@ -174,6 +205,9 @@ func entriesURL(base string, f Filters) string {
if f.Status != "" {
q.Set("status", f.Status)
}
+ if f.FeedID > 0 {
+ q.Set("feed_id", strconv.FormatInt(f.FeedID, 10))
+ }
if f.ChangedAfter > 0 {
q.Set("changed_after", strconv.FormatInt(f.ChangedAfter, 10))
}