{"id":18006318,"url":"https://github.com/lukakerr/hkn","last_synced_at":"2025-03-26T11:34:30.432Z","repository":{"id":57552324,"uuid":"167881305","full_name":"lukakerr/hkn","owner":"lukakerr","description":"A go module for interacting with Hacker News","archived":false,"fork":false,"pushed_at":"2019-02-18T00:43:58.000Z","size":48,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T18:13:33.872Z","etag":null,"topics":["api","go","go-module","golang","hacker-news"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/lukakerr/hkn","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukakerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-28T01:42:05.000Z","updated_at":"2022-10-07T05:49:11.000Z","dependencies_parsed_at":"2022-09-26T18:50:38.176Z","dependency_job_id":null,"html_url":"https://github.com/lukakerr/hkn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukakerr%2Fhkn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukakerr%2Fhkn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukakerr%2Fhkn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukakerr%2Fhkn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukakerr","download_url":"https://codeload.github.com/lukakerr/hkn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245644892,"owners_count":20649279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","go","go-module","golang","hacker-news"],"created_at":"2024-10-30T01:07:55.913Z","updated_at":"2025-03-26T11:34:26.743Z","avatar_url":"https://github.com/lukakerr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hkn\n\n\u003ca href=\"https://goreportcard.com/report/github.com/lukakerr/hkn\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/lukakerr/hkn\"\u003e\u003c/a\u003e\n[![GoDoc](https://godoc.org/github.com/lukakerr/hkn?status.svg)](https://godoc.org/github.com/lukakerr/hkn)\n\nA go module for interacting with Hacker News.\n\n### Features\n\nA ticked checkbox indicates the feature currently exists in `master`.\n\nAn item refers to either a story, comment, ask, job, poll or poll part\n\n- [x] Get a single item\n- [x] Get multiple items\n- [x] Get largest item id\n- [x] Get top 500 new, top and best stories (or a number \u003e= 0, \u003c= 500)\n- [x] Get top 200 ask, show and job stories (or a number \u003e= 0, \u003c= 200)\n- [x] Get changed items and profiles\n- [x] Get a user\n- [ ] Get a user's submissions\n- [ ] Get a user's comments\n- [ ] Get a user's hidden items\n- [ ] Get a user's upvoted items\n- [ ] Get a user's favorited items\n- [x] Login a user\n- [x] Upvote an item\n- [x] Unvote a comment\n- [ ] Downvote a comment\n- [x] Create a story\n- [ ] Create a poll\n- [x] Create a comment\n- [ ] Flag an item\n- [ ] Hide an item\n- [ ] Favorite an item\n- [ ] Edit an item\n- [ ] Delete an item\n- [ ] Search\n  - [ ] Full text\n  - [ ] By tag\n  - [ ] By created at date\n  - [ ] By points\n  - [ ] By number of comments\n  - [ ] By page number\n  - [ ] Sorted by relevance, then points, then number of comments\n  - [ ] Sorted by most recent\n\n### Usage\n\nFirst get `hkn`:\n\n```bash\n$ go get github.com/lukakerr/hkn\n```\n\nImport into your project:\n\n```go\nimport \"github.com/lukakerr/hkn\"\n\n// or\n\nimport (\n        \"github.com/lukakerr/hkn\"\n)\n```\n\n#### Methods\n\nExamples of all methods on the client can be found in [example/main.go](./example/main.go).\n\nFirst create a client:\n\n```go\nclient := hkn.NewClient()\n```\n\nVarious methods can then be then called on the client:\n\n**Get a single item by id**\n\n```go\n// Returns (Item, error)\nitem, err := client.GetItem(8869)\n```\n\n**Get multiple items by ids**\n\n```go\n// Returns ([]Item, error)\nitems, err := client.GetItems([]int{8869, 8908, 8881, 10403, 9125})\n```\n\n**Get max item id**\n\n```go\n// Returns (int, error)\nid, err := client.GetMaxItemID()\n```\n\n**Get the latest item and profile updates**\n\n```go\n// Returns (Updates, error)\nupdates, err := client.GetUpdates()\n```\n\n**Get top stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetTopStories(20)\n```\n\n**Get new stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetNewStories(20)\n```\n\n**Get best stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetBestStories(20)\n```\n\n**Get latest ask stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetLatestAskStories(20)\n```\n\n**Get latest show stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetLatestShowStories(20)\n```\n\n**Get latest job stories given a number**\n\n```go\n// Returns ([]int, error)\nstories, err := client.GetLatestJobStories(20)\n```\n\n**Get a user by id**\n\n```go\n// Returns (User, error)\nuser, err := client.GetUser(\"jl\")\n```\n\n**Login a user with a username and password**\n\n```go\n// The cookie returned is used for actions that require a user to be logged in\n// Returns (*http.Cookie, error)\ncookie, err := client.Login(\"username\", \"password\")\n```\n\n**Upvote an item**\n\n\u003e A cookie is required to upvote, get this from logging in\n\n```go\n// Returns (bool, error)\nupvoted, err := client.Upvote(8869, cookie)\n```\n\n**Unvote a comment**\n\n\u003e A cookie is required to unvote, get this from logging in\n\n```go\n// Returns (bool, error)\nunvoted, err := client.Unvote(8869, cookie)\n```\n\n**Create a comment**\n\n\u003e A cookie is required to create a comment, get this from logging in\n\n```go\n// Returns (bool, error)\ncontent := \"Really cool.\"\ncommented, err := client.Comment(8869, content, cookie)\n```\n\n**Create a story with a title and URL**\n\n\u003e A cookie is required to create a story, get this from logging in\n\n```go\n// Returns (bool, error)\ntitle := \"A title.\"\nURL := \"https://a.url.com\"\ncreated, err := client.CreateStoryWithURL(title, URL, cookie)\n```\n\n**Create a story with a title and text**\n\n\u003e A cookie is required to create a story, get this from logging in\n\n```go\n// Returns (bool, error)\ntitle := \"A title.\"\ntext := \"Some text.\"\ncreated, err := client.CreateStoryWithText(title, text, cookie)\n```\n\n### Running\n\nTo run the example locally:\n\n```bash\n$ go run example/main.go\n```\n\n### Testing\n\n```bash\n$ go test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukakerr%2Fhkn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukakerr%2Fhkn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukakerr%2Fhkn/lists"}