Skip to content

crystal-libs/hn.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hn.cr

GitHub release Docs

Hacker News API wrapper written in Crystal

All functions return JSON

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      hn:
        github: crystal-libs/hn.cr
  2. Run shards install

Usage

Require the module, set user agent:

require "hn"

user_agent = "[description]:[version] by @[username]"
hn = HN::HackerNews.new(user_agent)

Get an item:

hn.item("1")
#{"by" => "pg", "descendants" => 15, "id" => 1, "kids" => [15, 234509, 487171, 454426, 454424, 454410, 82729], "score" => 57, "time" => 1160418111, "title" => "Y Combinator", "type" => "story", "url" => "http://ycombinator.com"}

Get a user:

hn.user("test")
#{"about" => "", "created" => 1175289467, "delay" => 0, "id" => "test", "karma" => 1, "submitted" => [1043201, 1029445, 1026445, 586568, 418362, 418361, 11780]}

Get the max item:

hn.max_item
#29832636

Get stories:

The function takes a required kind argument. It must be one of the following:

  • "new"
  • "top"
  • "best"
  • "ask"
  • "show"
  • "job"
hn.get_stories(kind="ask")
#[29830770, 29826725, 29830214, 29825080, 29825844, ...]

Get changed items:

hn.changed_items
#[29831564, 29832264, 29832633, 29832087, 29825303, ...]

Get changed profiles:

hn.changed_profiles
#["throwawayboise", "givemeethekeys", "jorts", "vasco", "podge", ...]

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/crystal-libs/hn.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • gxfr - creator and maintainer