2.0.5 • Published 8 years ago

hack-news v2.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Installation

$ npm install hack-news

Usage

####Top Stories The examples below show how to access the IDs of the top stories on Hacker News.

var hn = require('hack-news');

//Returns an array of all the article ids for the top stories on hacker news

hn.allTopStories( (error, allTheStories) => {
  if (error) {
    console.log(error);
  }
  console.log(allTheStories);
});

//Using Promises
hn.allTopStories().then(stories => {console.log(stories);});

/*Returns an array of article ids in the amount of your choice.
So if you wanted the top ten stories on Hacker News it would look like this.*/

hn.numberOfTopStories(10, (error, numberOfStories) => {
  if (error) {
    console.log(error);
  }
  console.log(numberOfStories);
});

//Using Promises
hn.numberOfTopStories(10).then(numberOfStories => {console.log(numberOfStories);});

####New Stories The examples below show how to access the IDs of the new stories on Hacker News.

var hn = require('hack-news');

//Returns an array of all the article ids for the new stories on hacker news
hn.allNewStories( (error, allTheStories) => {
  if (error) {
    console.log(error);
  }
  console.log(allTheStories);
});

//Using Promises
hn.allNewStories().then(stories => {console.log(stories);});

/*Returns an array of article ids in the amount of your choice.
So if you wanted the top ten newest stories on Hacker News it would look like this.*/
hn.numberOfNewStories(10, (error, numOfStories) => {
  if (error) {
    console.log(error);
  }
  console.log(numOfStories);
});

//Using Promises
hn.numberOfNewStories(10).then(numOfStories => {console.log(numOfStories);});

####Ask, Show and Job Stories The examples below show how to access the IDs of Ask, Show and Job stories on Hacker News.

var hn = require('hack-news');

//Returns an array of all the article ids for Ask, Show and Job stories on hacker news.
//Just place 'ask', 'show', or 'job' as the first parameter to retrieve the array you need.
hn.asjStories('ask', (error, asj) => {
  if (error) {
    console.log(error);
  }
  console.log(asj);
});

//Using Promises
hn.asjStories('show').then(asj => {console.log(asj);});

//If you wanted the Top Ten Ask, Show, Job you ca use the numbOfAskShowOrJobStories method like so.
hn.numbOfAsjStories('show', 10, (error, asj) => {
  if (error) {
    console.log(error);
  }
  console.log(asj);
});

//Using Promises
hn.numbOfAsjStories('job', 10).then(asj => {console.log(asj);});

####IDs The examples below show how to select a single story with its ID you can also use the ID method with the other methods provided.

All items have some of the following properties, with required properties in bold.

FieldDescription
idThe item's unique id.
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, story 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, poll or job.
partsA list of related pollopts, in display order.
descendantsIn the case of stories or polls, the total comment count.
var hn = require('hack-news');

//This will return a object filled with data corresponding to the ID that was used.
hn.storyWithId(002, (error, story) => {
  if (error) {
    console.log(error);
  }
  console.log(story);
});

//Used with another method
hn.numberOfNewStories(10, (error, numOfStories) => {
  var myArray = numOfStories;
  hn.storyWithId(myArray[0], (error, story) => {
    console.log(story);
  });
});

//Using Promises
hn.storyWithId(12303).then(story => {console.log(story);});

//Used with another method.
hn.numbOfAsjStories('job', 10).then(asj => {
  var myArray = asj;
  hn.storyWithId(myArray[6]).then(story => {console.log(story);});
});

####Users The examples below show how to select a single user with his or hers ID you can also use the user method with the other methods provided.

All users have some of the following properties, with required properties in bold.

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.
var hn = require('hack-news');

//This will return a object filled with data corresponding to the ID that was used.
hn.userWithId('thefox', (error, user) => {
  if (error) {
    console.log(error);
  }
  console.log(user);
});

//Used with another method
hn.storyWithId(7567, (error, story) => {
  var myUser = story.by;
  hn.userWithId(myUser, (error, user) => {
    console.log(user);
  });
});

//Using Promises
hn.userWithId('thefox').then(user => {console.log(user);});

//Used with another method.
hn.storyWithId(7875).then(story => {
  var myUser = story.by;
  hn.storyWithId(myUser).then(user => {console.log(user);});
});

####Changed items and profiles The examples below show how to access the changed or updated items and profiles on Hacker News.

var hn = require('hack-news');

//This will return a object with two properties, one for the items and another for the profiles.
hn.changedItemsAndProfiles( (error, itemsProfiles) => {
  if (error) {
    console.log(error);
  }
  console.log(itemsProfiles);
});

//Using Promises
hn.changedItemsAndProfiles().then(itemsProfiles => {console.log(itemsProfiles);});

####Max Item The examples below show how to grab the max item on hacker news.

var hn = require('hack-news');

//This will return the max item.
hn.maxItem( (error, mItem) => {
  if (error) {
    console.log(error);
  }
  console.log(mItem);
});

//Using Promises
hn.maxItem().then(mItem => {console.log(mItem);});
2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago