Replace 'got' module with 'nets'. Resolves GH-802

This commit is contained in:
Andrew Sliwinski 2017-11-20 17:04:17 -05:00
parent 140570d195
commit a8c629dc9b
4 changed files with 27 additions and 3 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
.DS_Store
# NPM
package-lock.json
/node_modules
npm-*

View file

@ -36,7 +36,6 @@
"eslint-config-scratch": "^4.0.0",
"expose-loader": "0.7.3",
"gh-pages": "^1.1.0",
"got": "5.7.1",
"highlightjs": "^9.8.0",
"htmlparser2": "3.9.2",
"immutable": "3.8.1",
@ -44,6 +43,7 @@
"json": "^9.0.4",
"lodash.defaultsdeep": "4.6.0",
"minilog": "3.1.0",
"nets": "3.2.0",
"promise": "7.1.1",
"scratch-audio": "latest",
"scratch-blocks": "latest",

View file

@ -1,4 +1,4 @@
const got = require('got');
const nets = require('nets');
const io = require('socket.io-client/dist/socket.io');
const querystring = require('querystring');
@ -312,7 +312,17 @@ class DeviceManager {
};
if (deviceSpec) queryObject.spec = deviceSpec;
const url = `${this._serverURL}/${encodeURIComponent(deviceType)}/list?${querystring.stringify(queryObject)}`;
return got(url).then(response => JSON.parse(response.body));
return new Promise((resolve, reject) => {
nets({
method: 'GET',
url: url,
json: {}
}, (err, res, body) => {
if (err) return reject(err);
if (res.statusCode !== 200) reject(body);
resolve(body);
});
});
}
/**

View file

@ -19,3 +19,16 @@ test('default connected', t => {
t.strictEqual(deviceManager.isConnected, true);
t.end();
});
test('list', t => {
const deviceManager = new DeviceManager();
deviceManager
.list('test', 'test', null)
.catch(err => {
t.true((typeof err === 'undefined') || (typeof err === 'object'));
})
.then(body => {
t.true((typeof body === 'undefined') || (typeof body === 'object'));
t.end();
});
});