Browse Source

use json-bigint for json parsing/serializing

pull/17/head
Brett Langdon 11 years ago
parent
commit
0b06f4199d
6 changed files with 22 additions and 10 deletions
  1. +3
    -2
      bin/dogapi
  2. +3
    -2
      lib/api/screenboard.js
  3. +5
    -4
      lib/api/timeboard.js
  4. +3
    -2
      lib/client.js
  5. +7
    -0
      lib/json.js
  6. +1
    -0
      package.json

+ 3
- 2
bin/dogapi View File

@ -1,5 +1,6 @@
#!/usr/bin/env node
var dogapi = require("../");
var json = require("../lib/json");
var minimist = require("minimist");
var rc = require("rc");
@ -56,13 +57,13 @@ if(command === "now"){
if(subcommand){
dogapi[command].handleCli(subcommand, args, function(err, res){
if(err){
console.error(JSON.stringify(err, null, ' '));
console.error(json.stringify(err, null, ' '));
process.exit(1);
} else {
if(res === ""){
res = "success";
}
console.log(JSON.stringify(res, null, ' '));
console.log(json.stringify(res, null, ' '));
}
});
} else {


+ 3
- 2
lib/api/screenboard.js View File

@ -1,4 +1,5 @@
var client = require("../client");
var json = require("../json");
var util = require("util");
@ -218,11 +219,11 @@ module.exports = {
} else if(subcommand === "create"){
var title = args._[4];
var description = args._[5];
var graphs = JSON.parse(args._[6]);
var graphs = json.parse(args._[6]);
var options = {};
if(args["tmpvars"]){
options.templateVariables = JSON.parse(args["tmpvars"]);
options.templateVariables = json.parse(args["tmpvars"]);
}
if(args["width"]){
options.width = parseInt(args["width"]);


+ 5
- 4
lib/api/timeboard.js View File

@ -1,4 +1,5 @@
var client = require("../client");
var json = require("../json");
var util = require("util");
/*section: timeboard
@ -249,10 +250,10 @@ module.exports = {
} else if(subcommand === "create"){
var title = args._[4];
var description = args._[5];
var graphs = JSON.parse(args._[6]);
var graphs = json.parse(args._[6]);
var templateVariables = [];
if(args["tmpvars"]){
templateVariables = JSON.parse(args["tmpvars"]);
templateVariables = json.parse(args["tmpvars"]);
}
create(title, description, graphs, templateVariables, callback);
@ -260,10 +261,10 @@ module.exports = {
var dashId = parseInt(args._[4]);
var title = args._[5];
var description = args._[6];
var graphs = JSON.parse(args._[7]);
var graphs = json.parse(args._[7]);
var templateVariables = [];
if(args["tmpvars"]){
templateVariables = JSON.parse(args["tmpvars"]);
templateVariables = json.parse(args["tmpvars"]);
}
update(dashId, title, description, graphs, templateVariables, callback);


+ 3
- 2
lib/client.js View File

@ -1,5 +1,6 @@
var extend = require("extend");
var https = require("https");
var json = require("./json");
var url = require("url");
var util = require("util");
@ -50,7 +51,7 @@ client.prototype.request = function(method, path, params, callback){
}
params = params || {};
var body = (typeof params["body"] === "object")? JSON.stringify(params["body"]) : params["body"];
var body = (typeof params["body"] === "object")? json.stringify(params["body"]) : params["body"];
var query = {
"api_key": this.api_key,
"application_key": this.app_key,
@ -97,7 +98,7 @@ client.prototype.request = function(method, path, params, callback){
res.on("end", function(){
var error = null;
try{ data = JSON.parse(data); }catch(e){}
try{ data = json.parse(data); }catch(e){}
if(data["errors"]){
error = data["errors"];
data = null;


+ 7
- 0
lib/json.js View File

@ -0,0 +1,7 @@
var JSONBig = require("json-bigint");
module.exports = {
stringify: JSONBig.stringify,
parse: JSONBig.parse
};

+ 1
- 0
package.json View File

@ -33,6 +33,7 @@
"gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc",
"dependencies": {
"extend": "^2.0.0",
"json-bigint": "^0.1.4",
"minimist": "^1.1.1",
"rc": "^1.0.0"
},


Loading…
Cancel
Save