Streaming Hacker News API client
Elixir
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
.editorconfig
.formatter.exs
.gitattributes
.gitignore
.travis.yml
license
mix.exs
mix.lock
readme.md

readme.md

exhn

Streaming Hacker News API client

Build Status

Install

In your mix.exs:

def application do
  [applications: [:exhn]]
end

defp deps do
  [
    {:exhn, "~> 1.1.4"}
  ]
end

Then run mix deps.get.

Usage

For information about the endpoints themselves please refer to the Hacker News API docs.

Static endpoints

Static endpoints are available under ExHN.

ExHN.item(id)

Gets the item with the specified id.

ExHN.items(enum)

Returns a Stream of items from a given enum of id numbers. This can be a List or a Range.

ExHN.user(name)

Gets the item with the specified name.

Live endpoints

Live endpoints are available under ExHN.Live. These return an infinite Stream of data. The following endpoints are available:

  • ExHN.max_item
  • ExHN.updates
  • ExHN.new_stories
  • ExHN.top_stories
  • ExHN.best_stories
  • ExHN.ask_stories
  • ExHN.show_stories
  • ExHN.job_stories

ExHN.Live.get_items(stream)

A helper function that gets the actual data inside the above endpoints since they return a list of ids:

iex> ExHN.Live.updates |> ExHN.Live.get_items |> Enum.take(1)
iex> [%{"by" => "username", "text" => "I'm a comment!"}]

License

MIT © Juan Soto