mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 09:24:58 +00:00
Update jsonrpc2.js
This commit is contained in:
parent
c91e01e13d
commit
2f974727d6
|
@ -1,16 +1,23 @@
|
|||
// jsonrpc2.js
|
||||
// JSON-RPC 2.0 wrapper for WelsonJS framework
|
||||
// Namhyeon Go <abuse@catswords.net>
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
function jsonrpc2(url) {
|
||||
this.url = url;
|
||||
this.userAgent = "php-httpproxy/0.1.5 (Client; WelsonJS; abuse@catswords.net)";
|
||||
|
||||
this.setUserAgent = function(agent) {
|
||||
this.userAgent = agent;
|
||||
};
|
||||
this.invoke = function(method, params, id) {
|
||||
var result;
|
||||
var response = HTTP.create("MSXML")
|
||||
.setContentType("application/json")
|
||||
.setDataType("json")
|
||||
.setRequestBody(encode(method, params, id))
|
||||
.setUserAgent(this.userAgent)
|
||||
.setRequestBody(wrap(method, params, id))
|
||||
.open("POST", this.url)
|
||||
.send()
|
||||
.responseBody
|
||||
|
@ -29,23 +36,23 @@ function jsonrpc2(url) {
|
|||
}
|
||||
}
|
||||
|
||||
function encode(method, params, id) {
|
||||
return JSON.stringify({
|
||||
function wrap(method, params, id) {
|
||||
return {
|
||||
"jsonrpc": "2.0",
|
||||
"method": method,
|
||||
"params": params,
|
||||
"id": id
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function create(url) {
|
||||
return new jsonrpc2(url);
|
||||
}
|
||||
|
||||
exports.encode = encode;
|
||||
exports.wrap = wrap;
|
||||
exports.create = create;
|
||||
|
||||
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.2";
|
||||
exports.VERSIONINFO = "JSON-RPC 2.0 wrapper (jsonrpc2.js) version 0.1.4";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user