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

hacker-news-api

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hacker-news-api - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

3

example.js
api = require('./index');
api.getUserStories('pg', function (error, data) {
if (error)
throw error;
if (error) throw error;
console.log(data);
});
request = require('request');
var api = {
var hn = {
// make a request to the specified endpoint
call: function (endpoint, cb) {
var query = 'https://hn.algolia.com/api/v1/' + endpoint;
var query = 'https://hn.algolia.com/hn/v1/' + endpoint;
request(query, function (error, response, body) {

@@ -18,31 +18,31 @@ if (!error && !response.statusCode == 200)

getItem: function (id, cb) {
api.call('items/' + id, cb);
hn.call('items/' + id, cb);
},
getUser: function (username, cb) {
api.call('users/' + username, cb)
hn.call('users/' + username, cb)
},
getLastStories: function (cb) {
api.call('search_by_date?tags=story', cb);
hn.call('search_by_date?tags=story', cb);
},
getLastPolls: function (cb) {
api.call('search_by_date?tags=poll', cb);
hn.call('search_by_date?tags=poll', cb);
},
getLastPosts: function (cb) {
api.call('search_by_date?tags=(story,poll)', cb);
hn.call('search_by_date?tags=(story,poll)', cb);
},
getUserStories: function (username, cb) {
api.call('search?tags=story,author_' + username, cb);
hn.call('search?tags=story,author_' + username, cb);
},
searchStories: function (search, cb) {
api.call('search?query=' + search + '&tags=story', cb);
hn.call('search?query=' + search + '&tags=story', cb);
},
searchPolls: function (search, cb) {
api.call('search?query=' + search + '&tags=poll', cb);
hn.call('search?query=' + search + '&tags=poll', cb);
},

@@ -61,6 +61,6 @@

}
api.call('search' + params, cb);
hn.call('search' + params, cb);
}
};
module.exports = api;
module.exports = hn;
{
"name": "hacker-news-api",
"version": "0.0.0",
"version": "1.0.0",
"description": "Node.js library for Algolia's Hacker News API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,5 +8,7 @@ # Node.js Hacker News API

Impossible. Don't even try it.
```sh
npm install hacker-news-api
```
## Usage
## Examples

@@ -16,5 +18,6 @@ Some methods only require a callback.

```js
api.getLastPolls(function (error, data) {
if (error)
throw error;
var hn = require('hacker-news-api');
hn.getLastPolls(function (error, data) {
if (error) throw error;
console.log(data);

@@ -27,5 +30,6 @@ });

```js
api.getUserStories('pg', function (error, data) {
if (error)
throw error;
var hn = require('hacker-news-api');
hn.getUserStories('pg', function (error, data) {
if (error) throw error;
console.log(data);

@@ -35,12 +39,25 @@ });

The `api.search(obj, cb)` method requires an object and a callback.
The `api.search` method requires an object and a callback.
```js
api.search({
var hn = require('hacker-news-api');
hn.search({
query: 'javascript',
tags: 'poll'
}, function (error, data) {
if (error)
throw error;
if (error) throw error;
console.log(data);
});
```
## Methods
* `getItem(id, cb)`
* `getUser(username, cb)`
* `getLastStories(cb)`
* `getLastPolls(cb)`
* `getLastPosts(cb)`
* `getUserStories(username, cb)`
* `searchStories(search, cb)`
* `searchPolls(search, cb)`
* `search(obj, cb)`
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