Comparing version 1.0.5 to 2.0.0
{ | ||
"name": "yc-api", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "This is a wrapper module around the Hacker News API. You can filter the news in order to show you only the stories with a minimum score.", | ||
"main": "yc-api.js", | ||
"dependencies": { | ||
"async": "^2.0.0-rc.3", | ||
"request": "^2.72.0" | ||
"axios": "^0.19.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.7.5", | ||
"babel-preset-es2015": "^6.6.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"build": "babel --presets es2015 ./src/app.js -o yc-api.js && node yc-api.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -17,0 +12,0 @@ }, |
@@ -1,49 +0,45 @@ | ||
What is it? | ||
=========== | ||
# What is it? | ||
This is a wrapper module around the [Hacker News](https://news.ycombinator.com/) API. You can filter the news in order to show you only the stories with a minimum score. | ||
Installation | ||
============ | ||
As simple as `npm install yc-api` | ||
# async/await support | ||
Tha last version of this library support async/await. | ||
Usages | ||
------ | ||
# Installation | ||
Import the module with `var yc-api = require('yc-api')`. | ||
As simple as `npm install yc-api` | ||
In the new es6 fashon `import yc-pi from yc-api`. | ||
## Usages | ||
Import the module with `const yc-api = require('yc-api')`. | ||
###get\_top\_stories\_id(cb) | ||
### get_top_stories_id() | ||
This take the top stories (IDs) from YC and return them into the callback. | ||
This take the top stories (IDs) from YC and return them. | ||
### get_story(url) | ||
Takes an _url_ as argument and return a **JSON** object containing the story. | ||
###get_story(url,cb) | ||
Takes an *url* as argument and return into the callback a **JSON** object containing the story. | ||
The returned object looks like this: | ||
{ | ||
"by" : "dhouston", | ||
"descendants" : 71, | ||
"id" : 8863, | ||
"kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ], | ||
"score" : 111, | ||
"time" : 1175714200, | ||
"title" : "My YC app: Dropbox - Throw away your USB drive", | ||
"type" : "story", | ||
"url" : "http://www.getdropbox.com/u/2/screencast.html" | ||
} | ||
{ | ||
"by" : "dhouston", | ||
"descendants" : 71, | ||
"id" : 8863, | ||
"kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ], | ||
"score" : 111, | ||
"time" : 1175714200, | ||
"title" : "My YC app: Dropbox - Throw away your USB drive", | ||
"type" : "story", | ||
"url" : "http://www.getdropbox.com/u/2/screencast.html" | ||
} | ||
### get_stories() | ||
###get_stories(cb) | ||
Return into a callback an array of **JSON** object containing the stories. | ||
Return an array of **JSON** object containing the stories. | ||
### stories_with_score(score) | ||
###stories\_with\_score(score,cb) | ||
Same as **get_stories** but return into the object only the stories with the minimum score of **score**. | ||
@@ -53,24 +49,15 @@ | ||
stories_with_score(200,function (stories){ | ||
console.log(stories); | ||
}); | ||
stories_with_score(200).then(stories => console.log(stories)); | ||
# Example | ||
Example | ||
======= | ||
var yc_api = require('yc-api'); | ||
var async = require('async'); | ||
var yc_api = require('yc-api'); | ||
var async = require('async'); | ||
var yc = new yc_api.API; | ||
var yc = new yc_api.API; | ||
yc.stories_with_score(200).then(stories => console.log(stories)); | ||
yc.stories_with_score(500, function (stories) { | ||
async.each(stories,function (story, cb) { | ||
console.log(story.title); | ||
cb(); | ||
}, function (err, res) { | ||
if (err) throw err; | ||
console.log('done'); | ||
}); | ||
}); | ||
// using async | ||
const stories = await yc.stories_with_score(200); | ||
console.log(stories) |
176
yc-api.js
"use strict"; | ||
const axios = require("axios"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.API = undefined; | ||
class API { | ||
constructor() { | ||
this.top_stories_url = | ||
"https://hacker-news.firebaseio.com/v0/topstories.json"; | ||
this.story_url = "https://hacker-news.firebaseio.com/v0/item"; | ||
} | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
// get the top stories on YC and parse them as json to a cb | ||
async get_top_stories_id() { | ||
const stories = await axios.get(this.top_stories_url); | ||
return stories.data; | ||
} | ||
var _request = require("request"); | ||
async get_story(url) { | ||
const story = await axios.get(url); | ||
return story.data; | ||
} | ||
var _request2 = _interopRequireDefault(_request); | ||
// get the top stories cycle them into the get_story function | ||
// pass trougth a cb an array of stories | ||
async get_stories() { | ||
let promises = []; | ||
const ids = await this.get_top_stories_id(); | ||
for (let id of ids) { | ||
let url = `${this.story_url}/${id}.json`; | ||
const story = this.get_story(url); | ||
promises.push(story); | ||
} | ||
var _async = require("async"); | ||
const stories = await Promise.all(promises); | ||
return stories; | ||
} | ||
var _async2 = _interopRequireDefault(_async); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var API = exports.API = function () { | ||
function API() { | ||
_classCallCheck(this, API); | ||
this.top_stories_url = 'https://hacker-news.firebaseio.com/v0/topstories.json'; | ||
this.story_url = 'https://hacker-news.firebaseio.com/v0/item'; | ||
// Get all the stories from the top one's | ||
// And filter them passing only the story with a minimun score | ||
// pass an array of story into the cb | ||
async stories_with_score(score) { | ||
let result = []; | ||
const stories = await this.get_stories(); | ||
for (let story of stories) { | ||
if (story.score >= score) result.push(story); | ||
} | ||
return result; | ||
} | ||
} | ||
// get the top stories on YC and parse them as json to a cb | ||
_createClass(API, [{ | ||
key: "get_top_stories_id", | ||
value: function get_top_stories_id(cb) { | ||
_request2.default.get(this.top_stories_url, function (err, resp, body) { | ||
if (err) throw err; | ||
cb(JSON.parse(body)); | ||
}); | ||
} | ||
// get a single story and parse them into a cb as json | ||
// Example of story | ||
// { | ||
// "by" : "dhouston", | ||
// "descendants" : 71, | ||
// "id" : 8863, | ||
// "kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ], | ||
// "score" : 111, | ||
// "time" : 1175714200, | ||
// "title" : "My YC app: Dropbox - Throw away your USB drive", | ||
// "type" : "story", | ||
// "url" : "http://www.getdropbox.com/u/2/screencast.html" | ||
// } | ||
}, { | ||
key: "get_story", | ||
value: function get_story(url, cb) { | ||
_request2.default.get(url, function (err, resp, body) { | ||
if (err) throw err; | ||
cb(JSON.parse(body)); | ||
}); | ||
} | ||
// get the top stories cycle them into the get_story function | ||
// pass trougth a cb an array of stories | ||
}, { | ||
key: "get_stories", | ||
value: function get_stories(cb) { | ||
var _this = this; | ||
var result = []; | ||
this.get_top_stories_id(function (stories_id) { | ||
_async2.default.each(stories_id, function (story_id, callback) { | ||
var url = _this.story_url + "/" + story_id + ".json"; | ||
_this.get_story(url, function (data) { | ||
result.push(data); | ||
callback(null); | ||
}); | ||
}, function (err) { | ||
if (err) throw err; | ||
cb(result); | ||
}); | ||
}); | ||
} | ||
// Get all the stories from the top one's | ||
// And filter them passing only the story with a minimun score | ||
// pass an array of story into the cb | ||
}, { | ||
key: "stories_with_score", | ||
value: function stories_with_score(score, cb) { | ||
var result = []; | ||
this.get_stories(function (stories) { | ||
_async2.default.each(stories, function (story, callback) { | ||
if (story.score >= score) { | ||
result.push(story); | ||
} | ||
callback(null); | ||
}, function (err) { | ||
if (err) throw err; | ||
cb(result); | ||
}); | ||
}); | ||
} | ||
// takes the API url of mailgun | ||
// sender email | ||
// to email | ||
// subject and body | ||
// execute a cb | ||
// example of email object: | ||
// let email = { | ||
// apikey: '', | ||
// server: '', | ||
// sender: '', | ||
// to: '', | ||
// subject: '', | ||
// body: '' | ||
// }; | ||
// send_email(email, cb) { | ||
// let msg = new mailgun.Mailgun(email.apikey); | ||
// msg.sendText(email.sender, email.to, | ||
// email.subject, | ||
// email.body, | ||
// email.server, | ||
// 'noreply@example.com', | ||
// function(err) { | ||
// if (err) { | ||
// console.log(err); | ||
// throw err; | ||
// } | ||
// cb(); | ||
// }); | ||
// } | ||
}]); | ||
return API; | ||
}(); | ||
const api = new API(); | ||
api.stories_with_score(100).then(data => console.log(data)); | ||
module.exports = API; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
1
0
3649
3
45
63
1
+ Addedaxios@^0.19.0
+ Addedaxios@0.19.2(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
- Removedasync@^2.0.0-rc.3
- Removedrequest@^2.72.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasync@2.6.4(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)