Documentation
¶
Overview ¶
Package lemmy is the library behind the lemmy command line: the HTTP client, request shaping, and the typed data models for the Lemmy federated forum API at lemmy.world.
The Lemmy REST API is open for public read-only data: no API key, no auth required. This package wraps the v3 API with a rate-limited client that the kit operations consume.
Index ¶
- Constants
- type Client
- func (c *Client) GetSite(ctx context.Context) (*Site, error)
- func (c *Client) ListComments(ctx context.Context, postID, limit int) ([]Comment, error)
- func (c *Client) ListCommunities(ctx context.Context, sort, listType string, limit int) ([]Community, error)
- func (c *Client) ListPosts(ctx context.Context, sort, listType string, limit int) ([]Post, error)
- func (c *Client) Search(ctx context.Context, query, searchType, sort string, limit int) (*wireSearchResp, error)
- type Comment
- type Community
- type Config
- type Domain
- type Post
- type Site
Constants ¶
const DefaultUserAgent = "lemmy-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to lemmy.world honestly.
const Host = "lemmy.world"
Host is the default Lemmy instance this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a rate-limited HTTP client for the Lemmy v3 API.
func (*Client) ListComments ¶
ListComments fetches comments on a post.
func (*Client) ListCommunities ¶
func (c *Client) ListCommunities(ctx context.Context, sort, listType string, limit int) ([]Community, error)
ListCommunities fetches communities from the Lemmy API. sort: Active, Hot, New, TopDay, TopMonth, TopYear, TopAll (default: Active) listType: All, Local (default: All)
func (*Client) ListPosts ¶
ListPosts fetches posts from the Lemmy API. sort: Active, Hot, New, TopDay, TopWeek, TopMonth (default: Active) listType: All, Local, Subscribed (default: All)
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, query, searchType, sort string, limit int) (*wireSearchResp, error)
Search searches for posts, communities, or comments. searchType: Posts, Communities, Comments, Users (default: Posts) sort: Active, Hot, New, TopAll (default: TopAll)
type Comment ¶
type Comment struct {
ID int `json:"id" kit:"id"`
Content string `json:"content"`
Author string `json:"author"`
Score int `json:"score"`
Published string `json:"published"`
PostID int `json:"post_id"`
}
Comment is a single Lemmy comment record.
type Community ¶
type Community struct {
ID int `json:"id" kit:"id"`
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
ActorID string `json:"actor_id"`
Subscribers int `json:"subscribers"`
Posts int `json:"posts"`
Comments int `json:"comments"`
Published string `json:"published"`
}
Community is a single Lemmy community record.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds constructor parameters for Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for lemmy.world.
type Domain ¶
type Domain struct{}
Domain is the Lemmy driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme and the identity the single-site binary inherits.
type Post ¶
type Post struct {
ID int `json:"id" kit:"id"`
Title string `json:"title"`
URL string `json:"url"`
Body string `json:"body"`
Community string `json:"community"`
Author string `json:"author"`
Score int `json:"score"`
Comments int `json:"comments"`
Published string `json:"published"`
NSFW bool `json:"nsfw"`
PostURL string `json:"post_url"`
}
Post is a single Lemmy post record.
type Site ¶
type Site struct {
Name string `json:"name" kit:"id"`
Description string `json:"description"`
Version string `json:"version"`
Users int `json:"users"`
Posts int `json:"posts"`
Comments int `json:"comments"`
Communities int `json:"communities"`
}
Site is instance-level statistics for a Lemmy instance.