Documentation
¶
Index ¶
- Constants
- type Client
- func (c Client) Item(ctx context.Context, id int) (Item, error)
- func (c Client) MaxItem(ctx context.Context) (int, error)
- func (c Client) NewStories(ctx context.Context) (IDList, error)
- func (c Client) Update(ctx context.Context, rem Remote) (bool, error)
- func (c Client) User(ctx context.Context, id string) (User, error)
- type ID
- type IDList
- type Item
- type Remote
- type User
Constants ¶
const ( HackerNewsAPI = "https://hacker-news.firebaseio.com" APIVersion = "v0" ItemPath = APIVersion + "/item/%d" MaxItemPath = APIVersion + "/maxitem" NewStoriesPath = APIVersion + "/newstories" UserPath = APIVersion + "/user/%s" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a consistent interface to the HN API.
func DefaultClient ¶
DefaultClient creates a new HN client with charactistics that are appropriate for most users calling the HN API as follows:
- No authentication is required.
- ETags are used to determine whether an item or user has changed.
func (Client) MaxItem ¶
MaxItem returns the id of the last item created. The client never caches the maximum item id, nor does it use ETags to avoid retrieving the value from the server.
func (Client) NewStories ¶
NewStories returns a list of item ids for the 500 newest stories.
func (Client) Update ¶
Update retrieves a new version of an HN Item, User or list (passed into the method as rem) if there is one available. If ETags are disabled in the client, the remote object is retrieved from the server again and the boolean returned will alwasy indicated that the item was changed. The default operation of the client is to check the ETags. In this case, the returned boolean will indicate whether a new version of the object has been retrieved.
type IDList ¶
type IDList struct { IDs []ID // contains filtered or unexported fields }
IDList provides a type that can maintain the path to one of the HN lists along with the most recently retrieve ETag and the list of IDs itself.
func (*IDList) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler for HN id lists.
type Item ¶
type Item struct { ID int // The item's unique id. Type string // The type of item. One of "job", "story", "comment", "poll", or "pollopt". By string // The username of the item's author. Time time.Time // Creation date of the item, in Unix Time. Text string // The comment, story or poll text. HTML. Parent int // The comment's parent: either another comment or the relevant story. Poll int // The pollopt's associated poll. Kids []int // The ids of the item's comments, in ranked display order. URL string // The URL of the story. Score int // The story's score, or the votes for a pollopt. Title string // The title of the story, poll or job. HTML. Parts []int // A list of related pollopts, in display order. Descendants int // In the case of stories or polls, the total comment count. Dead bool // if the item is dead. Deleted bool // if the item is deleted. // contains filtered or unexported fields }
Item contains the attributes of an HN item.
See: https://github.com/HackerNews/API#items
func (*Item) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler for HN items.
type Remote ¶
Remote is an interface that represents a base HN object stored in the Firebase server. Path and ETag accessors and mutators are provided so that the interface's implementation can be embedded without being exported.
type User ¶
type User struct { ID string // The user's unique username. Case-sensitive. Required. Delay int // Delay in minutes between a comment's creation and its visibility to other users. Created time.Time // Creation date of the user, in Unix Time. Karma int // The user's karma. About string // The user's optional self-description. HTML. Submitted []int // List of the user's stories, polls and comments. // contains filtered or unexported fields }
User contains the attributes of an HN user.
See: https://github.com/HackerNews/API#users
func (*User) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler for HN users.