The Wayback Machine - https://web.archive.org/web/20200921052030/https://github.com/lukakerr/hkn
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

hkn

GoDoc

A go module for interacting with Hacker News.

Features

A ticked checkbox indicates the feature currently exists in master.

An item refers to either a story, comment, ask, job, poll or poll part

  • Get a single item
  • Get multiple items
  • Get largest item id
  • Get top 500 new, top and best stories (or a number >= 0, <= 500)
  • Get top 200 ask, show and job stories (or a number >= 0, <= 200)
  • Get changed items and profiles
  • Get a user
  • Get a user's submissions
  • Get a user's comments
  • Get a user's hidden items
  • Get a user's upvoted items
  • Get a user's favorited items
  • Login a user
  • Upvote an item
  • Unvote a comment
  • Downvote a comment
  • Create a story
  • Create a poll
  • Create a comment
  • Flag an item
  • Hide an item
  • Favorite an item
  • Edit an item
  • Delete an item
  • Search
    • Full text
    • By tag
    • By created at date
    • By points
    • By number of comments
    • By page number
    • Sorted by relevance, then points, then number of comments
    • Sorted by most recent

Usage

First get hkn:

$ go get github.com/lukakerr/hkn

Import into your project:

import "github.com/lukakerr/hkn"

// or

import (
        "github.com/lukakerr/hkn"
)

Methods

Examples of all methods on the client can be found in example/main.go.

First create a client:

client := hkn.NewClient()

Various methods can then be then called on the client:

Get a single item by id

// Returns (Item, error)
item, err := client.GetItem(8869)

Get multiple items by ids

// Returns ([]Item, error)
items, err := client.GetItems([]int{8869, 8908, 8881, 10403, 9125})

Get max item id

// Returns (int, error)
id, err := client.GetMaxItemID()

Get the latest item and profile updates

// Returns (Updates, error)
updates, err := client.GetUpdates()

Get top stories given a number

// Returns ([]int, error)
stories, err := client.GetTopStories(20)

Get new stories given a number

// Returns ([]int, error)
stories, err := client.GetNewStories(20)

Get best stories given a number

// Returns ([]int, error)
stories, err := client.GetBestStories(20)

Get latest ask stories given a number

// Returns ([]int, error)
stories, err := client.GetLatestAskStories(20)

Get latest show stories given a number

// Returns ([]int, error)
stories, err := client.GetLatestShowStories(20)

Get latest job stories given a number

// Returns ([]int, error)
stories, err := client.GetLatestJobStories(20)

Get a user by id

// Returns (User, error)
user, err := client.GetUser("jl")

Login a user with a username and password

// The cookie returned is used for actions that require a user to be logged in
// Returns (*http.Cookie, error)
cookie, err := client.Login("username", "password")

Upvote an item

A cookie is required to upvote, get this from logging in

// Returns (bool, error)
upvoted, err := client.Upvote(8869, cookie)

Unvote a comment

A cookie is required to unvote, get this from logging in

// Returns (bool, error)
unvoted, err := client.Unvote(8869, cookie)

Create a comment

A cookie is required to create a comment, get this from logging in

// Returns (bool, error)
content := "Really cool."
commented, err := client.Comment(8869, content, cookie)

Create a story with a title and URL

A cookie is required to create a story, get this from logging in

// Returns (bool, error)
title := "A title."
URL := "https://a.url.com"
created, err := client.CreateStoryWithURL(title, URL, cookie)

Create a story with a title and text

A cookie is required to create a story, get this from logging in

// Returns (bool, error)
title := "A title."
text := "Some text."
created, err := client.CreateStoryWithText(title, text, cookie)

Running

To run the example locally:

$ go run example/main.go

Testing

$ go test

About

A go module for interacting with Hacker News

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.