-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Replace wreck with built-in https (closes #126)
- Loading branch information
Showing
2 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters