mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +00:00
Update jsonrpc2.js
This commit is contained in:
parent
c9c70d9be6
commit
3733eaea45
|
@ -3,46 +3,8 @@
|
|||
// https://github.com/gnh1201/welsonjs
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
function encode(method, params, id) {
|
||||
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;
|
||||
return this;
|
||||
}
|
||||
|
||||
function jsonrpc2(url) {
|
||||
this.url = url;
|
||||
this.call = function(method, params, id) {
|
||||
var result;
|
||||
var response = HTTP.create("MSXML")
|
||||
|
@ -67,16 +29,23 @@ function JsonRpcObject() {
|
|||
}
|
||||
}
|
||||
|
||||
function create() {
|
||||
return new JsonRpcObject();
|
||||
function encode(method, params, id) {
|
||||
return JSON.stringify({
|
||||
"jsonrpc": "2.0",
|
||||
"method": method,
|
||||
"params": params,
|
||||
"id": id
|
||||
});
|
||||
}
|
||||
|
||||
function create(url) {
|
||||
return new jsonrpc2(url);
|
||||
}
|
||||
|
||||
exports.encode = encode;
|
||||
exports.resultEncode = resultEncode;
|
||||
exports.errorEncode = errorEncode;
|
||||
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.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user