Skip to content

Commit

Permalink
Update: Replace wreck with built-in https (closes #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 7, 2017
1 parent 276361e commit ea74721
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
47 changes: 44 additions & 3 deletions lib/shared/getBlacklist.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
'use strict';

var wreck = require('wreck');
var https = require('https');

var concat = require('concat-stream');

var url = 'https://gulpjs.com/plugins/blackList.json';

function collect(stream, cb) {
stream.on('error', cb);
stream.pipe(concat(onSuccess));

function onSuccess(result) {
cb(null, result);
}
}

function parse(str, cb) {
try {
cb(null, JSON.parse(str));
} catch (err) {
cb(new Error('Invalid Blacklist JSON.'));
}
}

// TODO: Test this impl
function getBlacklist(cb) {
wreck.get(url, { json: true }, function(err, res, blacklist) {
https.get(url, onRequest);

function onRequest(res) {
if (res.statusCode !== 200) {
// TODO: Test different status codes
return cb(new Error('Request failed. Status Code: ' + res.statusCode));
}

res.setEncoding('utf8');

collect(res, onCollect);
}

function onCollect(err, result) {
if (err) {
return cb(err);
}

parse(result, onParse);
}

function onParse(err, blacklist) {
if (err) {
return cb(err);
}

cb(null, blacklist);
});
}
}

module.exports = getBlacklist;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"archy": "^1.0.0",
"array-sort": "^1.0.0",
"chalk": "^1.1.0",
"concat-stream": "^1.6.0",
"copy-props": "^2.0.1",
"fancy-log": "^1.1.0",
"gulplog": "^1.0.0",
Expand All @@ -47,7 +48,6 @@
"replace-homedir": "^1.0.0",
"semver-greatest-satisfied-range": "^1.0.0",
"v8flags": "^3.0.1",
"wreck": "^6.3.0",
"yargs": "^7.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit ea74721

Please sign in to comment.