cloudcms-cli
Version:
Cloud CMS Command-Line client
79 lines (64 loc) • 2.23 kB
JavaScript
var helper = require("../../../helper");
var AbstractCommand = require("../../abstract");
class PingCommand extends AbstractCommand
{
constructor()
{
super({
"group": "tools",
"name": "ping",
"description": "Pings the API endpoint and retrieves timing information",
"schema": {
"properties": []
}
});
}
handle(options, callback)
{
helper._handleGitanaGet("/ping", {}, function(err, body, headers, responseTimeMs) {
var result = {};
result.ok = true;
//result.body = body;
result.responseTimeMs = responseTimeMs;
var requestId = headers["x-cloudcms-request-id"];
if (requestId) {
result.requestId = requestId;
}
var apiExecutionTimeMs = headers["x-cloudcms-api-execution-time-ms"];
if (apiExecutionTimeMs) {
result.apiTimeMs = parseInt(apiExecutionTimeMs, 10);
}
var band = result.band = {};
var limit = headers["x-ratelimit-limit"];
if (limit) {
limit = parseInt(limit, 10);
}
var remaining = headers["x-ratelimit-remaining"];
if (remaining) {
remaining = parseInt(remaining, 10);
}
// var consumed = headers["x-ratelimit-consumed"];
// if (consumed) {
// consumed = parseInt(consumed, 10);
// }
if (typeof(limit) !== "undefined")
{
if (typeof(remaining) !== "undefined")
{
var reqsec = limit - remaining;
band.current = reqsec;
}
}
if (limit) {
band.max = limit;
}
var reset = headers["x-ratelimit-reset"];
if (reset) {
band.reset = reset;
}
helper._handleJsonResponse(err, result, callback);
callback();
});
}
}
module.exports = PingCommand;