Skip to content

Commit

Permalink
Added files missing in last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj committed Jun 9, 2013
1 parent cc89c48 commit b5e0381
Show file tree
Hide file tree
Showing 7 changed files with 972 additions and 0 deletions.
Empty file added .gitignore
Empty file.
73 changes: 73 additions & 0 deletions res/js/3rd_party/angular_jsonrpc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
angular.module('angular-json-rpc', []);
//
// json rpc for angular js. JSON-RPC-2.0 compatible.
// spec - http://www.jsonrpc.org/specification
//
var jsonRpc = angular.module('angular-json-rpc', []).factory("jsonRpc", ['$http', function($http) {
this.version = "2.0";

this.url = null;

//
// setup rpc
//
this.setup = function(params){
// check params
check_params(params);
this.url = params.url;
return this;
}


success = function(data, status, headers, config){

}

error = function(data, status, headers, config){

}

//
// json-rpc request
//
this.request = function(method, options, onSuccess, onFail){
if(options === undefined)
options = { id: 1 };

if (options.id === undefined)
options.id = 1;

// make request
var bodyRequest = JSON.stringify({"jsonrpc": this.version, "method": method, "params": options.params, "id" : options.id});
var headers = {'Content-Type': 'application/json'};
$http({'url': this.url, 'method': 'POST', 'data' : bodyRequest, 'headers': headers})
.success(function (data, status, headers, config){
if (data.error) {
if (onFail) onFail(data.error);
} else {
if (onSuccess) onSuccess(data.result);
}
return data;
}).error(function (data, status, headers, config) {
if (onFail) onFail(data);
return data;
});
// return
return true;
}

//
// Check params
//
check_params = function(params){
if (params == undefined){
throw("Wrong params");
}

if (typeof(params.url) !== 'string' || params.url == '')
throw("Wrong url parameter");
}

return this;

}]);
Loading

0 comments on commit b5e0381

Please sign in to comment.