Documentation ¶
Overview ¶
Package hn implements a really basic Hacker News client
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
Cache Hacker News stories
func NewDefaultCache ¶
func NewDefaultCache() *Cache
NewDefaultCache instanciates a new cache with default expiration duration
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an API client used to interact with the Hacker News API
func (*Client) TopItems ¶
TopItems returns the ids of roughly 450 top items in decreasing order. These should map directly to the top 450 things you would see on HN if you visited their site and kept going to the next page.
TopItems does not filter out job listings or anything else, as the type of each item is unknown without further API calls.
type Item ¶
type Item struct { By string `json:"by"` Descendants int `json:"descendants"` ID int `json:"id"` Kids []int `json:"kids"` Score int `json:"score"` Time int `json:"time"` Title string `json:"title"` Type string `json:"type"` // Only one of these should exist Text string `json:"text"` URL string `json:"url"` // specific attribute Host string }
Item represents a single item returned by the HN API. This can have a type of "story", "comment", or "job" (and probably more values), and one of the URL or Text fields will be set, but not both.
For the purpose of this exercise, we only care about items where the type is "story", and the URL is set.