mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 13:16:05 +00:00
Update jsonrpc2.js
This commit is contained in:
parent
c91e01e13d
commit
2f974727d6
|
@ -1,16 +1,23 @@
|
||||||
// jsonrpc2.js
|
// jsonrpc2.js
|
||||||
|
// JSON-RPC 2.0 wrapper for WelsonJS framework
|
||||||
// Namhyeon Go <abuse@catswords.net>
|
// Namhyeon Go <abuse@catswords.net>
|
||||||
// https://github.com/gnh1201/welsonjs
|
// https://github.com/gnh1201/welsonjs
|
||||||
var HTTP = require("lib/http");
|
var HTTP = require("lib/http");
|
||||||
|
|
||||||
function jsonrpc2(url) {
|
function jsonrpc2(url) {
|
||||||
this.url = 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) {
|
this.invoke = function(method, params, id) {
|
||||||
var result;
|
var result;
|
||||||
var response = HTTP.create("MSXML")
|
var response = HTTP.create("MSXML")
|
||||||
.setContentType("application/json")
|
.setContentType("application/json")
|
||||||
.setDataType("json")
|
.setDataType("json")
|
||||||
.setRequestBody(encode(method, params, id))
|
.setUserAgent(this.userAgent)
|
||||||
|
.setRequestBody(wrap(method, params, id))
|
||||||
.open("POST", this.url)
|
.open("POST", this.url)
|
||||||
.send()
|
.send()
|
||||||
.responseBody
|
.responseBody
|
||||||
|
@ -29,23 +36,23 @@ function jsonrpc2(url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function encode(method, params, id) {
|
function wrap(method, params, id) {
|
||||||
return JSON.stringify({
|
return {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": method,
|
"method": method,
|
||||||
"params": params,
|
"params": params,
|
||||||
"id": id
|
"id": id
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(url) {
|
function create(url) {
|
||||||
return new jsonrpc2(url);
|
return new jsonrpc2(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.encode = encode;
|
exports.wrap = wrap;
|
||||||
exports.create = create;
|
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.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