Skip to content

callback function to return data to controller #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 37 additions & 42 deletions angular-json-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,59 @@ angular.module('angular-json-rpc', []);
// spec - http://www.jsonrpc.org/specification
//
var jsonRpc = angular.module('angular-json-rpc', []).factory("jsonRpc", ['$http', function($http) {
this.version = "2.0";
this.version = "2.0";
this.url = null;

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

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

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

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

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

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

}

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

if (options.id === undefined)
options.id = 1;
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){
return data;
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) {
successCallback(data);
}).error(function (data, status, headers, config) {
return data;
errorCallback(data);
});
// return
return true;
}
}

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

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

return this;
return this;

}]);
}]);