Documentation ¶
Overview ¶
Package hkn is a go module for interacting with Hacker News.
To get started simply import the package, create a client and call methods on the client:
import ( "fmt" "github.com/lukakerr/hkn" ) func main() { client := hkn.NewClient() // For example, to get an item by id item, err := client.GetItem(8869) if err != nil { fmt.Println(err) return } fmt.Printf("%+v\n", item) }
Index ¶
- Variables
- type Client
- func (c *Client) Comment(id int, content string, cookie *http.Cookie) (bool, error)
- func (c *Client) CreateStoryWithText(title string, text string, cookie *http.Cookie) (bool, error)
- func (c *Client) CreateStoryWithURL(title string, url string, cookie *http.Cookie) (bool, error)
- func (c *Client) GetBestStories(number int) ([]int, error)
- func (c *Client) GetItem(id int) (Item, error)
- func (c *Client) GetItems(ids []int) (Items, error)
- func (c *Client) GetLatestAskStories(number int) ([]int, error)
- func (c *Client) GetLatestJobStories(number int) ([]int, error)
- func (c *Client) GetLatestShowStories(number int) ([]int, error)
- func (c *Client) GetMaxItemID() (int, error)
- func (c *Client) GetNewStories(number int) ([]int, error)
- func (c *Client) GetTopStories(number int) ([]int, error)
- func (c *Client) GetUpdates() (Updates, error)
- func (c *Client) GetUser(id string) (User, error)
- func (c *Client) Login(username string, password string) (*http.Cookie, error)
- func (c *Client) Unvote(id int, cookie *http.Cookie) (bool, error)
- func (c *Client) Upvote(id int, cookie *http.Cookie) (bool, error)
- type Item
- type Items
- type Updates
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFetching represents an error fetching a resource ErrFetching = errors.New("fetching resource failed") // ErrEmptyContent represents an error that content provided is empty ErrEmptyContent = errors.New("content is empty") // ErrEmptyTitle represents an error that a title provided is empty ErrEmptyTitle = errors.New("title is empty") // ErrInvalidAuth represents an error authenticating ErrInvalidAuth = errors.New("invalid username or password") // ErrFetchingActionURL represents an error fetching an action URL ErrFetchingActionURL = errors.New("fetching action URL failed") // ErrInvalidNumber represents an error that a number provided is invalid ErrInvalidNumber = errors.New("invalid number") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client represents the hkn client
func (*Client) Comment ¶
Comment creates a comment on an item given an id, content and cookie, and returns whether the comment was successful
func (*Client) CreateStoryWithText ¶
CreateStoryWithText creates a story with a mandatory title and optional text body
func (*Client) CreateStoryWithURL ¶
CreateStoryWithURL creates a story with a mandatory title and optional url
func (*Client) GetBestStories ¶
GetBestStories returns best stories given a number
func (*Client) GetLatestAskStories ¶
GetLatestAskStories returns latest ask stories given a number
func (*Client) GetLatestJobStories ¶
GetLatestJobStories returns latest job stories given a number
func (*Client) GetLatestShowStories ¶
GetLatestShowStories returns latest show stories given a number
func (*Client) GetMaxItemID ¶
GetMaxItemID returns the most recent item id
func (*Client) GetNewStories ¶
GetNewStories returns new stories given a number
func (*Client) GetTopStories ¶
GetTopStories returns top stories given a number
func (*Client) GetUpdates ¶
GetUpdates returns the latest item and profile updates
func (*Client) Login ¶
Login a user given a username and password and get back an authentication cookie
type Item ¶
type Item struct { ID int `json:"id"` Deleted bool `json:"deleted"` Type string `json:"type"` By string `json:"by"` Time int32 `json:"time"` Text string `json:"text"` Dead bool `json:"dead"` Parent int `json:"parent"` Poll int `json:"poll"` Kids []int `json:"kids"` URL string `json:"url"` Score int `json:"score"` Title string `json:"title"` Parts []int `json:"parts"` Descendants int `json:"descendants"` }
Item represents a Hacker News item