Documentation
¶
Index ¶
- Constants
- type Comment
- type HNClient
- func (h *HNClient) GetComment(id string) (*Comment, error)
- func (h *HNClient) GetItem(id string) (*Item, error)
- func (h *HNClient) GetPoll(id string) (*Poll, error)
- func (h *HNClient) GetPollOpt(id string) (*PollOpt, error)
- func (h *HNClient) GetStory(id string) (*Story, error)
- func (h *HNClient) Item(id string) (interface{}, error)deprecated
- func (h *HNClient) MaxItemID() (int, error)
- func (h *HNClient) TopStoryIDs(t TopType) ([]int, error)
- func (h *HNClient) Updates() (*Update, error)
- func (h *HNClient) User(id string) (*HNUser, error)
- type HNUser
- type Item
- type Poll
- type PollOpt
- type Story
- type TopType
- type Update
Constants ¶
const ( CommentItem = "comment" PollItem = "poll" PollOptItem = "pollopt" JobItem = "job" AskItem = "ask" StoryItem = "story" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comment ¶
type Comment struct {
By string
ID int
Kids []int
Parent int
Text string
Time int64
Timestamp time.Time
Type string
}
Comment represents a HackerNews comment on a story.
func ItemToComment ¶
ItemToComment converts an Item into a Comment.
type HNClient ¶
type HNClient struct {
// contains filtered or unexported fields
}
HNClient wraps an http client with methods to query the Hacker News firebase API.
func NewHNClient ¶
func NewHNClient() *HNClient
NewHNClient returns an HNClient with default settings.
func NewHNClientWithURL ¶
NewHNClientWithURL returns an HNClient that will send all client request to the specified URL. This client is dependent on the API schema defined here: https://github.com/HackerNews/API/blob/9a57f04559388cc657d8b47b67fe0a687519ba4f/README.md
func (*HNClient) GetComment ¶
GetComment is a helper function that gets an Item and converts it to a Comment or errors.
func (*HNClient) GetPoll ¶
GetPoll is a helper function that gets an Item and converts it to a Poll or errors.
func (*HNClient) GetPollOpt ¶
GetPollOpt is a helper function that gets an Item and converts it to a Pollopt or errors.
func (*HNClient) GetStory ¶
GetStory is a helper function that gets an Item and converts it to a Story or errors.
func (*HNClient) Item
deprecated
Deprecated: Item is deprecated. Use GetItem or a more specialized method like GetComment instead. This was deprecated because it pushed type assertion into client code. There are now helpers like GetStory and ItemToComment to avoid returning an interface{} for clients to deal with. Item issues a GET request on the /item/<id> path and creates a struct from the response body. It returns an empty interface to be asserted into one of the hnapi types Story, Comment, Poll, PollOpt or an error.
func (*HNClient) MaxItemID ¶
MaxItemID issues a GET request to the /maxitem path and returns the current largest item id. This can be used to request information for all items by walking backwards.
func (*HNClient) TopStoryIDs ¶
TopStoryIDs issues a GET request to the /<TopType> path where TopType is one of the defined enum values. The API will return up to ~500 results for the Top and New categories.
type Item ¶
type Item struct {
ID int
Deleted bool
Type string
By string
Time int64
Timestamp time.Time // Not directly available in the API.
Text string
Dead bool
Parent int
Poll int
Kids []int
URL string
Score int
Title string
Parts []int
Descendants int
}
Item represents a HackerNews API item. Its properties are a superset of Story, Comment, Poll, and Pollopt types.
type Poll ¶
type Poll struct {
By string
Descendants int
ID int
Kids []int
Parts []int
Score int
Text string
Time int64
Timestamp time.Time
Title string
Type string
}
Poll represents a HackerNews poll. It contains a Parts field that describes the related poll options.
func ItemToPoll ¶
ItemToPoll converts an Item into a Poll.
type PollOpt ¶
type PollOpt struct {
By string
ID int
Poll int
Score int
Text string
Time int64
Timestamp time.Time
Type string
}
PollOpt represents the poll options from a given poll.
func ItemToPollOpt ¶
ItemToPollOpt converts an Item into a PollOpt.
type Story ¶
type Story struct {
By string
Descendants int
ID int
Kids []int
Score int
Time int64
Timestamp time.Time
Title string
Type string
URL string
}
Story represents a HackerNews submitted story.
func ItemToStory ¶
ItemToStory converts an Item into a Story.
type TopType ¶
type TopType string
TopType is a type alias used to represent an enum.
const ( // Top is for the top ~500 stories. Top TopType = "topstories" // New is for the new stories. New TopType = "newstories" // Best is for the highest ranking stories. Best TopType = "beststories" // Show is for stories categorized as 'Show'. Show TopType = "showstories" // Job is for stories categorized as 'Jobs'. Job TopType = "jobstories" )