Documentation
¶
Overview ¶
Package hackernews is the library behind the hackernews command: the HTTP client, pacing, and the typed data models for the Hacker News Firebase API.
The official Firebase endpoint at hacker-news.firebaseio.com is open: no API key, no auth, no rate limits beyond basic politeness. This package wraps it with a sequential, rate-limited client that the kit operations consume.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AskStories(ctx context.Context, limit int) ([]Item, error)
- func (c *Client) BestStories(ctx context.Context, limit int) ([]Item, error)
- func (c *Client) GetItem(ctx context.Context, id int) (*Item, error)
- func (c *Client) GetUser(ctx context.Context, id string) (*User, error)
- func (c *Client) JobStories(ctx context.Context, limit int) ([]Item, error)
- func (c *Client) NewStories(ctx context.Context, limit int) ([]Item, error)
- func (c *Client) ShowStories(ctx context.Context, limit int) ([]Item, error)
- func (c *Client) TopStories(ctx context.Context, limit int) ([]Item, error)
- type Config
- type Domain
- type Item
- type User
Constants ¶
const (
DefaultUserAgent = "hackernews/dev (+https://github.com/tamnd/hackernews-cli)"
)
const Host = "hacker-news.firebaseio.com"
Host is the Firebase base hostname for the Hacker News API.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the Firebase API returns null for an id or user.
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 HN Firebase API.
func (*Client) AskStories ¶ added in v0.2.0
AskStories fetches the Ask HN stories list and resolves up to limit items.
func (*Client) BestStories ¶ added in v0.2.0
BestStories fetches the best stories list and resolves up to limit items.
func (*Client) JobStories ¶ added in v0.2.0
JobStories fetches the job stories list and resolves up to limit items.
func (*Client) NewStories ¶ added in v0.2.0
NewStories fetches the new stories list and resolves up to limit items.
func (*Client) ShowStories ¶ added in v0.2.0
ShowStories fetches the Show HN stories list and resolves up to limit items.
type Config ¶
Config holds constructor parameters for Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for the Firebase API.
type Domain ¶ added in v0.2.0
type Domain struct{}
Domain is the Hacker News driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶ added in v0.2.0
Classify turns any accepted input into the canonical (uriType, id). Numeric input → ("item", id); username-like → ("user", input); otherwise error.
func (Domain) Info ¶ added in v0.2.0
func (Domain) Info() kit.DomainInfo
Info describes the scheme and the identity the single-site binary inherits.
type Item ¶ added in v0.2.0
type Item struct {
ID int `kit:"id" json:"id"`
Type string `json:"type"`
By string `json:"by"`
Time int64 `json:"time"`
Title string `json:"title"`
URL string `json:"url"`
Score int `json:"score"`
Descendants int `json:"descendants"`
Kids []int `json:"kids"`
Text string `json:"text"`
Dead bool `json:"dead"`
Deleted bool `json:"deleted"`
}
Item is one record from the Firebase item endpoint. It covers stories, comments, Ask HN, Show HN, jobs, and polls.