Documentation
¶
Index ¶
- func CountComments(comments []*Comment) int
- func EstimateTokens(comments []*Comment) int
- func TestCredentials(clientID, clientSecret string) error
- type Client
- func (c *Client) ExpandThread(thread *Thread, noCache bool)
- func (c *Client) Fetch(path string, noCache bool) ([]byte, error)
- func (c *Client) FetchMoreChildren(linkID string, childrenIDs []string, noCache bool) ([]*Comment, error)
- func (c *Client) FetchPost(path string, formData url.Values, noCache bool) ([]byte, error)
- func (c *Client) GetSubreddit(name string, sort SortOrder, limit int, timeFilter TimeFilter, after string, ...) ([]*Post, string, error)
- func (c *Client) GetSubredditInfo(name string, noCache bool) (*SubredditInfo, error)
- func (c *Client) GetThread(permalink string, noCache bool) (*Thread, error)
- func (c *Client) GetThreadShallow(permalink string, noCache bool) (*Thread, error)
- func (c *Client) GetUser(username string, limit int, noCache bool) (*UserInfo, []*Post, []*Comment, error)
- func (c *Client) IsAuthenticated() bool
- func (c *Client) Search(query string, sub string, sort SortOrder, limit int, timeFilter TimeFilter, ...) ([]*Post, string, error)
- type Comment
- type Credentials
- type Listing
- type ListingData
- type Post
- type SearchResult
- type SortOrder
- type SubredditInfo
- type Thing
- type Thread
- type TimeFilter
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountComments ¶ added in v1.0.1
CountComments counts all non-"more" comments in a tree.
func EstimateTokens ¶ added in v1.0.1
EstimateTokens estimates token count for a comment tree (~4 chars per token).
func TestCredentials ¶ added in v1.0.1
TestCredentials verifies that client ID and secret can obtain an OAuth token.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles all Reddit API communication.
func NewClient ¶
func NewClient() *Client
NewClient creates a new Reddit API client. Automatically loads OAuth credentials if available (~/.config/lurk/credentials.json).
func (*Client) ExpandThread ¶ added in v1.0.1
ExpandThread recursively expands "more" placeholders (up to 10 passes).
func (*Client) Fetch ¶
Fetch makes a GET request to the Reddit JSON API with retry, rate limiting, and caching.
func (*Client) FetchMoreChildren ¶
func (c *Client) FetchMoreChildren(linkID string, childrenIDs []string, noCache bool) ([]*Comment, error)
FetchMoreChildren fetches collapsed comment threads using Reddit's /api/morechildren endpoint. The response format differs from normal comments: it returns contentText, parent, and author/score embedded in HTML content rather than structured JSON fields.
func (*Client) FetchPost ¶
FetchPost makes a POST request to the Reddit JSON API with retry, rate limiting, and caching.
func (*Client) GetSubreddit ¶
func (c *Client) GetSubreddit(name string, sort SortOrder, limit int, timeFilter TimeFilter, after string, noCache bool) ([]*Post, string, error)
GetSubreddit fetches posts from a subreddit with sorting and pagination. Returns the list of posts, the "after" token for the next page, and any error.
func (*Client) GetSubredditInfo ¶
func (c *Client) GetSubredditInfo(name string, noCache bool) (*SubredditInfo, error)
GetSubredditInfo fetches metadata about a subreddit.
func (*Client) GetThread ¶
GetThread fetches a Reddit thread (post + comments) by permalink. Accepts full URLs like https://www.reddit.com/r/sub/comments/id/title/ or just the path.
func (*Client) GetThreadShallow ¶ added in v1.0.1
GetThreadShallow fetches a thread without expanding collapsed comments.
func (*Client) GetUser ¶
func (c *Client) GetUser(username string, limit int, noCache bool) (*UserInfo, []*Post, []*Comment, error)
GetUser fetches a user's profile info and recent activity (posts + comments).
func (*Client) IsAuthenticated ¶ added in v1.0.1
IsAuthenticated returns true if OAuth credentials are configured.
func (*Client) Search ¶
func (c *Client) Search(query string, sub string, sort SortOrder, limit int, timeFilter TimeFilter, after string, noCache bool) ([]*Post, string, error)
Search performs a Reddit search, optionally scoped to a subreddit. Supports comma-separated subreddit names for parallel multi-sub search.
type Comment ¶
type Comment struct {
ID string
ParentID string // parent comment/post ID (used by morechildren insertion)
Author string
Body string
Score int
Created time.Time
Depth int
Stickied bool
Replies []*Comment
IsMore bool // true if this represents a "load more" placeholder
MoreIDs []string // IDs of collapsed comments
MoreCount int
}
Comment represents a parsed Reddit comment.
func TopCommentsByScore ¶ added in v1.0.1
TopCommentsByScore flattens the comment tree and returns the top N by score.
type Credentials ¶ added in v1.0.1
type Credentials struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
Credentials holds Reddit OAuth app credentials.
func LoadCredentials ¶ added in v1.0.1
func LoadCredentials() (Credentials, error)
LoadCredentials reads OAuth credentials. Priority: env vars (LURK_CLIENT_ID/LURK_CLIENT_SECRET) > config file (~/.config/lurk/credentials.json).
type Listing ¶
type Listing struct {
Kind string `json:"kind"`
Data ListingData `json:"data"`
}
Listing is the Reddit API envelope for paginated results.
func ParseListing ¶
ParseListing decodes a JSON response into a Listing.
type ListingData ¶
type Post ¶
type Post struct {
ID string
Subreddit string
Author string
Title string
SelfText string
Score int
UpvoteRatio float64
NumComments int
URL string
Permalink string
Domain string
Created time.Time
IsVideo bool
IsSelf bool
Over18 bool
Stickied bool
LinkFlairText string
CrosspostParent string
MediaURL string
}
Post represents a parsed Reddit post.
type SearchResult ¶
type SearchResult struct {
Post *Post
}
SearchResult wraps a post found via search with its source subreddit.
type SubredditInfo ¶
type SubredditInfo struct {
Name string
Title string
Description string
Subscribers int
ActiveUsers int
Created time.Time
Over18 bool
SubredditType string // public, private, restricted
}
SubredditInfo holds metadata about a subreddit.
type TimeFilter ¶
type TimeFilter string
TimeFilter for top/controversial sorting.
const ( TimeHour TimeFilter = "hour" TimeDay TimeFilter = "day" TimeWeek TimeFilter = "week" TimeMonth TimeFilter = "month" TimeYear TimeFilter = "year" TimeAll TimeFilter = "all" )