mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-01 05:44:41 +03:00
Use method for Interaction::reservedFunctionName
Replace Mibew API Interaction "reservedFunctionName" property with "getReservedFunctionsNames" method to increase reliability of the code.
This commit is contained in:
parent
128d387ebe
commit
26b2d74cc4
@ -5,4 +5,4 @@
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
MibewAPIChatInteraction=function(){this.obligatoryArguments={"*":{threadId:null,token:null,"return":{},references:{}},result:{errorCode:0}};this.reservedFunctionNames=["result"]};MibewAPIChatInteraction.prototype=new MibewAPIInteraction;
|
||||
MibewAPIChatInteraction=function(){this.obligatoryArguments={"*":{threadId:null,token:null,"return":{},references:{}},result:{errorCode:0}};this.getReservedFunctionsNames=function(){return["result"]}};MibewAPIChatInteraction.prototype=new MibewAPIInteraction;
|
||||
|
@ -11,7 +11,7 @@
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
MibewAPIChatInteraction=function(){this.obligatoryArguments={"*":{threadId:null,token:null,"return":{},references:{}},result:{errorCode:0}};this.reservedFunctionNames=["result"]};MibewAPIChatInteraction.prototype=new MibewAPIInteraction;
|
||||
MibewAPIChatInteraction=function(){this.obligatoryArguments={"*":{threadId:null,token:null,"return":{},references:{}},result:{errorCode:0}};this.getReservedFunctionsNames=function(){return["result"]}};MibewAPIChatInteraction.prototype=new MibewAPIInteraction;
|
||||
/*
|
||||
Copyright 2005-2013 the original author or authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License").
|
||||
|
@ -6,13 +6,12 @@
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
function MibewAPI(a){this.protocolVersion="1.0";if("object"!=typeof a||!(a instanceof MibewAPIInteraction))throw Error("Wrong interaction type");this.interaction=a}
|
||||
MibewAPI.prototype.checkFunction=function(a,b){if("undefined"==typeof a["function"]||""==a["function"])throw Error("Cannot call for function with no name");if(b)for(var c=0;c<this.interaction.reservedFunctionNames.length;c++)if(a["function"]==this.interaction.reservedFunctionNames[c])throw Error("'"+a["function"]+"' is reserved function name");if("object"!=typeof a.arguments)throw Error("There are no arguments in '"+a["function"]+"' function");var d=0,f=this.interaction.getObligatoryArguments(a["function"]),
|
||||
e;a:for(e in a.arguments)for(c=0;c<f.length;c++)if(e==f[c]){d++;continue a}if(d!=f.length)throw Error("Not all obligatory arguments are set in '"+a["function"]+"' function");};
|
||||
MibewAPI.prototype.checkRequest=function(a){if("string"!=typeof a.token){if("undefined"==typeof a.token)throw Error("Empty token");throw Error("Wrong token type");}if(""==a.token)throw Error("Empty token");if("object"!=typeof a.functions||!(a.functions instanceof Array)||0==a.functions.length)throw Error("Empty functions set");for(var b=0;b<a.functions.length;b++)this.checkFunction(a.functions[b])};
|
||||
MibewAPI.prototype.checkFunction=function(a,b){if("undefined"==typeof a["function"]||""==a["function"])throw Error("Cannot call for function with no name");if(b)for(var c=this.interaction.getReservedFunctionsNames(),d=0;d<c.length;d++)if(a["function"]==c[d])throw Error("'"+a["function"]+"' is reserved function name");if("object"!=typeof a.arguments)throw Error("There are no arguments in '"+a["function"]+"' function");var c=0,f=this.interaction.getObligatoryArguments(a["function"]),e;a:for(e in a.arguments)for(d=
|
||||
0;d<f.length;d++)if(e==f[d]){c++;continue a}if(c!=f.length)throw Error("Not all obligatory arguments are set in '"+a["function"]+"' function");};MibewAPI.prototype.checkRequest=function(a){if("string"!=typeof a.token){if("undefined"==typeof a.token)throw Error("Empty token");throw Error("Wrong token type");}if(""==a.token)throw Error("Empty token");if("object"!=typeof a.functions||!(a.functions instanceof Array)||0==a.functions.length)throw Error("Empty functions set");for(var b=0;b<a.functions.length;b++)this.checkFunction(a.functions[b])};
|
||||
MibewAPI.prototype.checkPackage=function(a){if("undefined"==typeof a.signature)throw Error("Missed package signature");if("undefined"==typeof a.proto)throw Error("Missed protocol version");if(a.proto!=this.protocolVersion)throw Error("Wrong protocol version");if("undefined"==typeof a.async)throw Error("'async' flag is missed");if("boolean"!=typeof a.async)throw Error("Wrong 'async' flag value");if("object"!=typeof a.requests||!(a.requests instanceof Array)||0==a.requests.length)throw Error("Empty requests set");
|
||||
for(var b=0;b<a.requests.length;b++)this.checkRequest(a.requests[b])};MibewAPI.prototype.getResultFunction=function(a,b){"undefined"==typeof b&&(b=null);var c=null,d;for(d in a)if(a.hasOwnProperty(d)&&"result"==a[d]["function"]){if(null!==c)throw Error("Function 'result' already exists in functions list");c=a[d]}if(!0===b&&null===c)throw Error("There is no 'result' function in functions list");if(!1===b&&null!==c)throw Error("There is 'result' function in functions list");return c};
|
||||
MibewAPI.prototype.buildResult=function(a,b){var c=this.interaction.getObligatoryArgumentsDefaults("result"),d;for(d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);return{token:b,functions:[{"function":"result",arguments:a}]}};MibewAPI.prototype.encodePackage=function(a){var b={signature:""};b.proto=this.protocolVersion;b.async=!0;b.requests=a;return encodeURIComponent(JSON.stringify(b)).replace(/\%20/gi,"+")};
|
||||
MibewAPI.prototype.decodePackage=function(a){a=JSON.parse(decodeURIComponent(a.replace(/\+/gi," ")));this.checkPackage(a);return a};function MibewAPIInteraction(){this.obligatoryArguments={};this.reservedFunctionNames=[]}
|
||||
MibewAPI.prototype.decodePackage=function(a){a=JSON.parse(decodeURIComponent(a.replace(/\+/gi," ")));this.checkPackage(a);return a};function MibewAPIInteraction(){this.obligatoryArguments={};this.getReservedFunctionsNames=function(){return[]}}
|
||||
MibewAPIInteraction.prototype.getObligatoryArguments=function(a){var b=[];if("object"==typeof this.obligatoryArguments["*"])for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&b.push(c);if("object"==typeof this.obligatoryArguments[a])for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&b.push(c);return b};
|
||||
MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults=function(a){var b={};if("object"==typeof this.obligatoryArguments["*"])for(var c in this.obligatoryArguments["*"])this.obligatoryArguments["*"].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments["*"][c]);if("object"==typeof this.obligatoryArguments[a])for(c in this.obligatoryArguments[a])this.obligatoryArguments[a].hasOwnProperty(c)&&(b[c]=this.obligatoryArguments[a][c]);return b};
|
||||
function MibewAPIExecutionContext(){this.returnValues={};this.functionsResults=[]}
|
||||
|
@ -5,4 +5,4 @@
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
MibewAPIUsersInteraction=function(){this.obligatoryArguments={"*":{agentId:null,"return":{},references:{}},result:{errorCode:0}};this.reservedFunctionNames=["result"]};MibewAPIUsersInteraction.prototype=new MibewAPIInteraction;
|
||||
MibewAPIUsersInteraction=function(){this.obligatoryArguments={"*":{agentId:null,"return":{},references:{}},result:{errorCode:0}};this.getReservedFunctionsNames=function(){return["result"]}};MibewAPIUsersInteraction.prototype=new MibewAPIInteraction;
|
||||
|
@ -45,7 +45,7 @@ a={hash:{},data:d};return c+=j((f=e.L10n||b.L10n,f?f.call(b,"visitors.table.head
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
MibewAPIUsersInteraction=function(){this.obligatoryArguments={"*":{agentId:null,"return":{},references:{}},result:{errorCode:0}};this.reservedFunctionNames=["result"]};MibewAPIUsersInteraction.prototype=new MibewAPIInteraction;
|
||||
MibewAPIUsersInteraction=function(){this.obligatoryArguments={"*":{agentId:null,"return":{},references:{}},result:{errorCode:0}};this.getReservedFunctionsNames=function(){return["result"]}};MibewAPIUsersInteraction.prototype=new MibewAPIInteraction;
|
||||
/*
|
||||
Copyright 2005-2013 the original author or authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License").
|
||||
|
@ -24,8 +24,10 @@ MibewAPIChatInteraction = function() {
|
||||
}
|
||||
};
|
||||
|
||||
this.reservedFunctionNames = [
|
||||
'result'
|
||||
];
|
||||
this.getReservedFunctionsNames = function() {
|
||||
return [
|
||||
'result'
|
||||
];
|
||||
}
|
||||
}
|
||||
MibewAPIChatInteraction.prototype = new MibewAPIInteraction();
|
@ -53,9 +53,9 @@ MibewAPI.prototype.checkFunction = function(functionObject, filterReservedFuncti
|
||||
throw new Error("Cannot call for function with no name");
|
||||
}
|
||||
if (filterReservedFunctions) {
|
||||
for (var i = 0; i < this.interaction.reservedFunctionNames.length; i++) {
|
||||
if (functionObject["function"] ==
|
||||
this.interaction.reservedFunctionNames[i]) {
|
||||
var reservedFunctionsNames = this.interaction.getReservedFunctionsNames();
|
||||
for (var i = 0; i < reservedFunctionsNames.length; i++) {
|
||||
if (functionObject["function"] == reservedFunctionsNames[i]) {
|
||||
throw new Error(
|
||||
"'" + functionObject["function"] +
|
||||
"' is reserved function name"
|
||||
@ -307,12 +307,17 @@ function MibewAPIInteraction(){
|
||||
this.obligatoryArguments = {};
|
||||
|
||||
/**
|
||||
* Reserved function's names
|
||||
* Returns reserved (system) functions' names
|
||||
*
|
||||
* Defines reserved(system) function's names described in the Mibew API.
|
||||
* @type Array
|
||||
* Reserved functions cannon be called directly by the other side and are
|
||||
* used for low-level purposes. For example function "result" is used to
|
||||
* send back a result of request execution.
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
this.reservedFunctionNames = [];
|
||||
this.getReservedFunctionsNames = function() {
|
||||
return [];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,8 +23,10 @@ MibewAPIUsersInteraction = function() {
|
||||
}
|
||||
};
|
||||
|
||||
this.reservedFunctionNames = [
|
||||
'result'
|
||||
];
|
||||
this.getReservedFunctionsNames = function() {
|
||||
return [
|
||||
'result'
|
||||
];
|
||||
}
|
||||
}
|
||||
MibewAPIUsersInteraction.prototype = new MibewAPIInteraction();
|
@ -175,7 +175,7 @@ class API
|
||||
);
|
||||
}
|
||||
if ($filter_reserved_functions) {
|
||||
if (in_array($function['function'], $this->interaction->reservedFunctionNames)) {
|
||||
if (in_array($function['function'], $this->interaction->getReservedFunctionsNames())) {
|
||||
throw new APIException(
|
||||
"'{$function['function']}' is reserved function name",
|
||||
APIException::FUNCTION_NAME_RESERVED
|
||||
|
@ -23,12 +23,15 @@ namespace Mibew\API\Interaction;
|
||||
abstract class AbstractInteraction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* Returns reserved (system) functions' names.
|
||||
*
|
||||
* Defines reserved(system) function's names described in the Mibew API.
|
||||
* @var array
|
||||
* Reserved functions cannon be called directly by the other side and are
|
||||
* used for low-level purposes. For example function "result" is used to
|
||||
* send back a result of request execution.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public $reservedFunctionNames = array();
|
||||
abstract public function getReservedFunctionsNames();
|
||||
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
|
@ -23,13 +23,17 @@ namespace Mibew\API\Interaction;
|
||||
class ChatInteraction extends AbstractInteraction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::$reservedFunctionNames
|
||||
* Returns reserved (system) functions' names.
|
||||
*
|
||||
* @return array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::getReservedFunctionsNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
public function getReservedFunctionsNames()
|
||||
{
|
||||
return array(
|
||||
'result',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
|
@ -23,13 +23,17 @@ namespace Mibew\API\Interaction;
|
||||
class InviteInteraction extends AbstractInteraction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::$reservedFunctionNames
|
||||
* Returns reserved (system) functions' names.
|
||||
*
|
||||
* @return array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::getReservedFunctionsNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
public function getReservedFunctionsNames()
|
||||
{
|
||||
return array(
|
||||
'result',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
|
@ -23,13 +23,17 @@ namespace Mibew\API\Interaction;
|
||||
class UsersInteraction extends AbstractInteraction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::$reservedFunctionNames
|
||||
* Returns reserved (system) functions' names.
|
||||
*
|
||||
* @return array
|
||||
* @see \Mibew\API\Interaction\AbstractInteraction::getReservedFunctionsNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
public function getReservedFunctionsNames()
|
||||
{
|
||||
return array(
|
||||
'result',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
|
Loading…
Reference in New Issue
Block a user