-
Notifications
You must be signed in to change notification settings - Fork 5
/
coin-clients.js
42 lines (34 loc) · 1.09 KB
/
coin-clients.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var _ = require('lodash');
var async = _.extend(require('async'), require('async-ext')); //async.mapValues comes from async-ext
var unirest = require('unirest');
module.exports = function (client_infos) {
this.client_infos = client_infos;
this.callClients = function (clients, method, params, callback) {
// Returns new object with only info from selected clients
// If null is passed, object has info from all clients
var clients = clients ? populate(clients, client_infos) : client_infos;
async.mapValues(
clients,
function (value, key, cb) {
var req = unirest.post('http://' + value.user + ':' + value.pass + '@' + value.host + ':' + value.port)
.send({
method: method,
params: params,
id: Date.now()
});
console.log(req.options.body)
req.end(function(response){
cb(null, response.body);
});
},
callback);
};
};
function populate(array, object) {
var ret = {};
array.forEach(function (value) {
ret[value] = object[value];
});
return ret;
}