api

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeedTop  = "topstories"
	FeedNew  = "newstories"
	FeedBest = "beststories"
	FeedAsk  = "askstories"
	FeedShow = "showstories"
)

Feed types

View Source
const (
	LobstersFeedHottest = ""       // Default front page
	LobstersFeedNewest  = "newest" // /newest
	LobstersFeedRecent  = "recent" // /recent (recently active)
)

Lobste.rs feed types (correspond to URL paths)

View Source
const (
	RedditFeedHot    = "hot"
	RedditFeedNew    = "new"
	RedditFeedTop    = "top"
	RedditFeedRising = "rising"
	RedditFeedBest   = "best"
)

Reddit feed types (correspond to URL paths)

Variables

View Source
var LobstersFeedLabels = []string{"Hot", "New", "Recent"}
View Source
var RedditFeedLabels = []string{"Hot", "New", "Top", "Rising", "Best"}

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the HN API client

func NewClient

func NewClient() *Client

NewClient creates a new HN API client

func (*Client) FeedLabels

func (c *Client) FeedLabels() []string

FeedLabels returns the display labels for feeds

func (*Client) FeedNames

func (c *Client) FeedNames() []string

FeedNames returns the available feed names

func (*Client) FetchCommentTree

func (c *Client) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)

FetchCommentTree fetches the full comment tree for a story

func (*Client) FetchComments

func (c *Client) FetchComments(item *Item) ([]*Item, error)

FetchComments fetches all comments for a story recursively

func (*Client) FetchItem

func (c *Client) FetchItem(id int) (*Item, error)

FetchItem fetches a single item by ID

func (*Client) FetchItems

func (c *Client) FetchItems(ids []int) ([]*Item, error)

FetchItems fetches multiple items concurrently

func (*Client) FetchStoryIDs

func (c *Client) FetchStoryIDs(feed string) ([]int, error)

FetchStoryIDs fetches the list of story IDs for a given feed

func (*Client) Name

func (c *Client) Name() string

Name returns the display name of the source

func (*Client) StoryURL

func (c *Client) StoryURL(item *Item) string

StoryURL returns the URL for viewing a story on HN

type Comment

type Comment struct {
	*Item
	Depth    int
	Children []*Comment
}

Comment represents a comment with its depth for rendering

type Item

type Item struct {
	ID          int    `json:"id"`
	Type        string `json:"type"`
	By          string `json:"by"`
	Time        int64  `json:"time"`
	Text        string `json:"text"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Score       int    `json:"score"`
	Kids        []int  `json:"kids"`
	Parent      int    `json:"parent"`
	Descendants int    `json:"descendants"`
	Deleted     bool   `json:"deleted"`
	Dead        bool   `json:"dead"`
}

Item represents a HN item (story, comment, job, poll)

func (*Item) Domain

func (i *Item) Domain() string

Domain extracts the domain from the URL

func (*Item) TimeAgo

func (i *Item) TimeAgo() string

TimeAgo returns a human-readable time ago string

type LobstersClient

type LobstersClient struct {
	// contains filtered or unexported fields
}

LobstersClient scrapes lobste.rs

func NewLobstersClient

func NewLobstersClient() *LobstersClient

NewLobstersClient creates a new Lobste.rs scraping client

func (*LobstersClient) FeedLabels

func (c *LobstersClient) FeedLabels() []string

FeedLabels returns the display labels for feeds

func (*LobstersClient) FeedNames

func (c *LobstersClient) FeedNames() []string

FeedNames returns the available feed names

func (*LobstersClient) FetchCommentTree

func (c *LobstersClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)

FetchCommentTree fetches comments for a story

func (*LobstersClient) FetchItem

func (c *LobstersClient) FetchItem(id int) (*Item, error)

FetchItem fetches a cached item by pseudo-ID

func (*LobstersClient) FetchItems

func (c *LobstersClient) FetchItems(ids []int) ([]*Item, error)

FetchItems fetches multiple cached items by pseudo-ID

func (*LobstersClient) FetchStoryIDs

func (c *LobstersClient) FetchStoryIDs(feed string) ([]int, error)

FetchStoryIDs fetches story "IDs" for a feed Since lobste.rs doesn't have numeric IDs, we fetch stories and cache them returning sequential pseudo-IDs

func (*LobstersClient) Name

func (c *LobstersClient) Name() string

Name returns the display name of the source

func (*LobstersClient) StoryURL

func (c *LobstersClient) StoryURL(item *Item) string

StoryURL returns the URL for viewing a story on Lobste.rs

type RedditClient added in v0.5.0

type RedditClient struct {
	// contains filtered or unexported fields
}

RedditClient fetches data from Reddit's JSON API

func NewRedditClient added in v0.5.0

func NewRedditClient(subreddit string) *RedditClient

NewRedditClient creates a new Reddit API client for a subreddit

func (*RedditClient) FeedLabels added in v0.5.0

func (c *RedditClient) FeedLabels() []string

FeedLabels returns the display labels for feeds

func (*RedditClient) FeedNames added in v0.5.0

func (c *RedditClient) FeedNames() []string

FeedNames returns the available feed names

func (*RedditClient) FetchCommentTree added in v0.5.0

func (c *RedditClient) FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)

FetchCommentTree fetches comments for a story

func (*RedditClient) FetchItem added in v0.5.0

func (c *RedditClient) FetchItem(id int) (*Item, error)

FetchItem fetches a cached item by pseudo-ID

func (*RedditClient) FetchItems added in v0.5.0

func (c *RedditClient) FetchItems(ids []int) ([]*Item, error)

FetchItems fetches multiple cached items by pseudo-ID

func (*RedditClient) FetchStoryIDs added in v0.5.0

func (c *RedditClient) FetchStoryIDs(feed string) ([]int, error)

FetchStoryIDs fetches story "IDs" for a feed

func (*RedditClient) Name added in v0.5.0

func (c *RedditClient) Name() string

Name returns the display name of the source

func (*RedditClient) StoryURL added in v0.5.0

func (c *RedditClient) StoryURL(item *Item) string

StoryURL returns the URL for viewing a story on Reddit

type Source

type Source interface {
	// Name returns the display name of the source
	Name() string

	// FeedNames returns the available feed names for this source
	FeedNames() []string

	// FeedLabels returns the display labels for feeds (for UI tabs)
	FeedLabels() []string

	// FetchStoryIDs fetches the list of story IDs for a given feed
	// For sources without IDs (like Lobste.rs), this returns page-based pseudo-IDs
	FetchStoryIDs(feed string) ([]int, error)

	// FetchItem fetches a single item by ID
	FetchItem(id int) (*Item, error)

	// FetchItems fetches multiple items by ID
	FetchItems(ids []int) ([]*Item, error)

	// FetchCommentTree fetches the comment tree for a story
	FetchCommentTree(item *Item, maxDepth int) ([]*Comment, error)

	// StoryURL returns the URL for viewing a story on the source's website
	StoryURL(item *Item) string
}

Source represents a news source (HN, Lobste.rs, etc.)

type UpdateInfo added in v0.7.0

type UpdateInfo struct {
	CurrentVersion string
	LatestVersion  string
	UpdateURL      string
}

UpdateInfo contains information about an available update

func CheckForUpdate added in v0.7.0

func CheckForUpdate(currentVersion string) *UpdateInfo

CheckForUpdate checks if a newer version is available It uses a cached result if checked within the last 24 hours

func (*UpdateInfo) FormatUpdateMessage added in v0.7.0

func (u *UpdateInfo) FormatUpdateMessage() string

FormatUpdateMessage returns a formatted message for the status bar

func (*UpdateInfo) HasUpdate added in v0.7.0

func (u *UpdateInfo) HasUpdate() bool

HasUpdate returns true if a newer version is available

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL