Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "hacka-news", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "npm module for loading and organizing content from the official Hacker News API.", | ||
@@ -10,3 +10,3 @@ "main": "src/hacka-news.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -34,4 +34,8 @@ "repository": { | ||
"engines": { | ||
"node" : ">=4.0.0" | ||
"node": ">=4.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.4.5", | ||
"should": "^8.3.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# hacka-news | ||
# hacka-news [![Build Status](https://travis-ci.org/Coteh/hacka-news.svg?branch=master)](https://travis-ci.org/Coteh/hacka-news) | ||
----------------- | ||
@@ -11,7 +11,20 @@ A node module that utilizes the [Hacker News](https://news.ycombinator.com/) [official API](https://github.com/HackerNews/API) and powers [my command line app (of similar name)](https://github.com/Coteh/hacka-news-cli). | ||
## Installation | ||
Run *git clone hacka-news* to clone this repository, then run *npm install* to install all the dependencies. | ||
Clone the repository with: | ||
`git clone https://github.com/Coteh/hacka-news` | ||
Then to install all the dependencies, run: | ||
`npm install` | ||
## Testing | ||
Currently, the tests are set up using the [mocha](http://mochajs.org/) testing framework, and assertions done using [should](https://www.npmjs.com/package/should). | ||
To run the tests, make sure you have mocha installed globally using: | ||
`npm install -g mocha` | ||
Then run the tests using: | ||
`mocha` | ||
## Issues | ||
- Error comments are unorganized | ||
- No unit/integration testing | ||
- No integration testing | ||
@@ -18,0 +31,0 @@ ## Future Additions |
var request = require('request'); | ||
var hackaTime = require('./hacka-time'); | ||
var HACKA_URL = "https://news.ycombinator.com/"; | ||
var MAX_LIST_STORIES = 500; //The official HN API only stores up to 500 top/new stories | ||
const MAX_LIST_STORIES = 500; //The official HN API only provides 500 top/new stories | ||
const MAX_POSTINGS_STORIES = 200; //The official HN API only provides 200 ask/show/job stories | ||
var hackaAPIURL = "https://hacker-news.firebaseio.com/v0/"; | ||
var amtOfFeedStories = 10; | ||
var jsonObject = null; | ||
var getAmountOfFeedStories = function(){ | ||
return amtOfFeedStories; | ||
}; | ||
var getURL = function(id){ | ||
@@ -22,3 +19,8 @@ return HACKA_URL + "item?id=" + id; | ||
var requestFeedStoryIDs = function(storyType, callback){ | ||
var pruneResults = function(ids, limit){ | ||
var prunedIDs = ids.slice(0, limit); | ||
return prunedIDs; | ||
} | ||
var requestFeedStoryIDs = function(storyType, limit, callback){ | ||
request(hackaAPIURL + storyType + "stories.json?print=pretty", function(error, response, body) { | ||
@@ -30,2 +32,6 @@ if (error){ | ||
ids = JSON.parse(body); | ||
var maxLimit = (storyType == "top" || storyType == "new") ? MAX_LIST_STORIES : MAX_POSTINGS_STORIES; | ||
if (limit < maxLimit) { | ||
ids = pruneResults(ids, limit); | ||
} | ||
callback(ids); | ||
@@ -37,3 +43,3 @@ }); | ||
request(hackaAPIURL + "item/" + id + ".json?print=pretty", function (error, response, body) { | ||
if (error){ | ||
if (error || body === "null\n"){ | ||
console.log("ERROR: Couldn't load story."); | ||
@@ -46,5 +52,9 @@ return; | ||
var parseStory = function(jsonStr){ | ||
return JSON.parse(jsonStr); | ||
} | ||
var requestStoryParsed = function(id, callback){ | ||
requestStory(id, function(hnJsonStr){ | ||
var parsedStory = JSON.parse(hnJsonStr); | ||
var parsedStory = parseStory(hnJsonStr); | ||
injectStoryExtras(parsedStory, callback); | ||
@@ -127,3 +137,3 @@ // callback(parsedStory); | ||
} | ||
requestFeedStoryIDs("top", function(ids){ | ||
requestFeedStoryIDs("top", 1, function(ids){ | ||
if (ids == null){ | ||
@@ -144,3 +154,2 @@ console.log("ERROR: Top stories did not load."); | ||
module.exports = { | ||
getAmountOfFeedStories, | ||
getURL, | ||
@@ -150,3 +159,7 @@ setAPIURL, | ||
requestStory, | ||
parseStory, | ||
requestStoryParsed, | ||
injectStoryExtras, | ||
requestRootParent, | ||
requestPollOptions, | ||
requestGroup, | ||
@@ -156,1 +169,3 @@ fetchTopID, | ||
}; | ||
module.exports.time = hackaTime; |
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
26927
18
451
0
33
2
1
2