mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-15 14:11:03 +00:00
Update jsonrpc2.js
This commit is contained in:
parent
c9c70d9be6
commit
3733eaea45
|
@ -3,46 +3,8 @@
|
||||||
// https://github.com/gnh1201/welsonjs
|
// https://github.com/gnh1201/welsonjs
|
||||||
var HTTP = require("lib/http");
|
var HTTP = require("lib/http");
|
||||||
|
|
||||||
function encode(method, params, id) {
|
function jsonrpc2(url) {
|
||||||
var data = {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": method,
|
|
||||||
"params": params,
|
|
||||||
"id": id
|
|
||||||
};
|
|
||||||
|
|
||||||
return JSON.stringify(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resultEncode(result, id) {
|
|
||||||
var data = {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"result": result
|
|
||||||
"id": id
|
|
||||||
};
|
|
||||||
|
|
||||||
return JSON.stringify(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function errorEncode(error, id) {
|
|
||||||
var data = {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"error": error,
|
|
||||||
"id": id
|
|
||||||
}
|
|
||||||
|
|
||||||
return JSON.stringify(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// See also: https://github.com/gnh1201/caterpillar
|
|
||||||
function JsonRpcObject() {
|
|
||||||
this.url = "http://localhost:5555";
|
|
||||||
|
|
||||||
this.setUrl = function(url) {
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.call = function(method, params, id) {
|
this.call = function(method, params, id) {
|
||||||
var result;
|
var result;
|
||||||
var response = HTTP.create("MSXML")
|
var response = HTTP.create("MSXML")
|
||||||
|
@ -67,16 +29,23 @@ function JsonRpcObject() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function create() {
|
function encode(method, params, id) {
|
||||||
return new JsonRpcObject();
|
return JSON.stringify({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": method,
|
||||||
|
"params": params,
|
||||||
|
"id": id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function create(url) {
|
||||||
|
return new jsonrpc2(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.encode = encode;
|
exports.encode = encode;
|
||||||
exports.resultEncode = resultEncode;
|
|
||||||
exports.errorEncode = errorEncode;
|
|
||||||
exports.create = create;
|
exports.create = create;
|
||||||
|
|
||||||
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1";
|
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.1";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user