From 3733eaea455d92314126c123c4e13f50d21b4676 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 26 Jun 2024 16:37:04 +0900 Subject: [PATCH] Update jsonrpc2.js --- lib/jsonrpc2.js | 59 ++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/lib/jsonrpc2.js b/lib/jsonrpc2.js index 8fe13df..34527d3 100644 --- a/lib/jsonrpc2.js +++ b/lib/jsonrpc2.js @@ -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;