Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hackernews_ruby

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hackernews_ruby

  • 0.0.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

HackernewsRuby

Coverage Status Build Status

A wrapper for the new Hacker News API.

Installation

Add this line to your application's Gemfile:

gem 'hackernews_ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hackernews_ruby

Usage

Instantiate a client like so:

client = HackernewsRuby::Client.new

Items

Items have the following fields:

Outlined here form HN

FieldDescription
idThe item's unique id. Required.
deletedtrue if the item is deleted.
typeThe type of item. One of "job", "story", "comment", "poll", or "pollopt".
byThe username of the item's author.
timeCreation date of the item, in Unix Time.
textThe comment, Ask HN, or poll text. HTML.
deadtrue if the item is dead.
parentThe item's parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll.
kidsThe ids of the item's comments, in ranked display order.
urlThe URL of the story.
scoreThe story's score, or the votes for a pollopt.
titleThe title of the story or poll.
partsA list of related pollopts, in display order.

To get an item simply do:

client.get_item(834129)

This will get any item available on the API by ID such as stories, comments, polls and jobs.

Say you wanted the title of a story:

story = client.get_item(8863) #story_id
story.title
=> "My YC app: Dropbox - Throw away your USB drive"

Users

Users have the following fields:

Outlined here from HN

FieldDescription
idThe user's unique username. Case-sensitive. Required.
delayDelay in minutes between a comment's creation and its visibility to other users.
createdCreation date of the user, in Unix Time.
karmaThe user's karma.
aboutThe user's optional self-description. HTML.
submittedList of the user's stories, polls and comments.

Say you wanted to fetch a particular user:

user = client.get_user('jl') #userid is case sensitive
user.about
=> "This is a test"

Live Data

To fetch the top 100 stories:

stories = client.top_stories

This will return an array of ID's. To get each story after that, just use the get_item method like this:

stories = client.top_stories
stories.each do |story|
  resp = client.get_item(story)
  puts resp.title
  puts resp.score
  puts resp.url
end

To get the most updated Profiles & Itemss you can call:

updates = client.updated
updates.items
=> [1212, 1214]
updates.profiles
=> [5653, 25456]

Contributing

  1. Fork it ( https://github.com/[my-github-username]/hackernews_ruby/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

FAQs

Package last updated on 09 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc