Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Added explicit timeout to request calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluard committed Jun 4, 2017
1 parent 2def058 commit dc3739f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
3 changes: 0 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env node
const cli = require("commander");
const child = require('child_process');
const watchman = require('fb-watchman');
const fs = require('fs');
const path = require('path');
const request = require('request');
const chalk = require('chalk');
const mdns = require('mdns');

Expand Down
55 changes: 20 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,58 @@ var StatusDev = function(options) {
this.url = "http://" + options.ip + ":5561";
};

StatusDev.prototype.addContact = function(contactData, cb) {
request({
url: this.url + "/add-dapp",
function requestOptions(url, body) {
return {
url: url,
method: "POST",
timeout: 3000,
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
body: body};
}

StatusDev.prototype.addContact = function(contactData, cb) {
request(requestOptions(this.url + "/add-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};

StatusDev.prototype.removeContact = function(contactData, cb) {
request({
url: this.url + "/remove-dapp",
method: "POST",
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
request(requestOptions(this.url + "/remove-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};

StatusDev.prototype.refreshContact = function(contactData, cb) {
request({
url: this.url + "/dapp-changed",
method: "POST",
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
request(requestOptions(this.url + "/dapp-changed", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};

StatusDev.prototype.switchNode = function(rpcUrl, cb) {
request({
url: this.url + "/switch-node",
method: "POST",
json: true,
body: {encoded: fromAscii(JSON.stringify({"url": rpcUrl}))}
}, function (error, response, body) {
request(requestOptions(this.url + "/switch-node", {encoded: fromAscii(JSON.stringify({"url": rpcUrl}))})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};

StatusDev.prototype.listDApps = function(cb) {
request({
url: this.url + "/list",
json: true,
method: "POST",
body: {}
}, function (error, response, body) {
request(requestOptions(this.url + "/list", {})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};

StatusDev.prototype.getLog = function(identity, cb) {
request({
url: this.url + "/log",
method: "POST",
json: true,
body: { identity: identity }
}, function (error, response, body) {
request(requestOptions(this.url + "/log", { identity: identity })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
Expand Down

0 comments on commit dc3739f

Please sign in to comment.