hacker-news-api
Advanced tools
Comparing version 0.0.0 to 1.0.0
api = require('./index'); | ||
api.getUserStories('pg', function (error, data) { | ||
if (error) | ||
throw error; | ||
if (error) throw error; | ||
console.log(data); | ||
}); |
24
index.js
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)` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3948
1
60
58