<commit_before>/*
 * Simple kaltura javascript api
 *
 * uses configuration Kaltura.ServiceUrl and Kaltura.ServiceBase for api entry point
 */ 

/**
 * kApi takes supports a few mixed argument types
 * 
 * @param {Number}
 * 		partner_id used to establish a request key for the given session
 * 		( this enables multiple sessions per partner id on a single page )
 * @param {Mixed}
 * 		Array An Array of request params for multi-request 
 * 		Object Named request params
 */
	
mw.KApi = function( partner_id ){
	return this.init( partner_id );	
};

mw.KApi.prototype = {
	baseParam: {
		'apiVersion' : '3.1',
		'clientTag' : 'html5:v' + window[ 'KALTURA_LOADER_VERSION' ],
		'expiry' : '86400',
		'format' : 9, // 9 = JSONP format
		'ignoreNull' : 1
	},
	playerLoaderCache: [],
	
	// The local kaltura session key ( so it does not have to be re-grabbed with every request
	ks : null,
	init: function( partner_id ){
		this.partner_id = partner_id;
	},
	getPartnerId: function( ){
		return this.partner_id;
	},
	doRequest : function( requestObject, callback ){
		var _this = this;
		var param = {};
		// Convert into a multi-request if no session is set ( ks will be added bellow ) 
		if( !requestObject.length && !this.ks ){
			requestObject = [ requestObject ];
		}

		// If we have Kaltura.NoApiCache flag, pass 'nocache' param to the client
		if( mw.getConfig('Kaltura.NoApiCache') === true ) {
			param['nocache'] = 'true';
		}
		
		// Check that we have a session established if not make it part of our multi-part request
		if( requestObject.length ){
			param['service'] = 'multirequest';
			param['action'] = 'null';

			// Kaltura api starts with index 1 for some strange reason. 
			var mulitRequestIndex = 1;
			
			for( var i = 0 ; i < requestObject.length; i++ ){
				var requestInx = mulitRequestIndex + i;
				// MultiRequest pre-process each param with inx:param
				for( var paramKey in requestObject[i] ){
					// support multi dimension array request:  
					// NOTE kaltura api only has sub arrays ( would be more feature complete to 
					// recursively define key appends )
					if( typeof requestObject[i][paramKey] == 'object' ){
						for( var subParamKey in requestObject[i][paramKey] ){
							param[ requestInx + ':' + paramKey + ':' +  subParamKey ] =
								requestObject[i][paramKey][subParamKey];
						}
					} else {
						param[ requestInx + ':' + paramKey ] = requestObject[i][paramKey];
					}					
				}
			}			
		} else { 
			param = requestObject;
		}				
		
		// add in the base parameters:
		for( var i in this.baseParam ){
			if( typeof param[i] == 'undefined' ){
				param[i] = this.baseParam[i];
			}
		};
		
		// Make sure we have the kaltura session
		// ideally this could be part of the multi-request but could not get it to work 
		// see commented out code above. 
		this.getKS( function( ks ){
			param['ks'] = ks;
			// Do the getJSON jQuery call with special callback=? parameter: 
			_this.doApiRequest( param, callback);
		});
	},
	setKS: function( ks ){
		this.ks = ks;
	},
	getKS: function( callback ){
		if( this.ks ){
			callback( this.ks );
			return true;
		}
		var _this = this;
		// Add the Kaltura session ( if not already set ) 
		var ksParam = {
        	'action' : 'startwidgetsession',
        	'widgetId': '_' + this.partner_id, 
        	'partnerId' : + this.partner_id // don't ask me, I did not design the API!
        };
		// add in the base parameters:
		var param = $j.extend( { 'service' : 'session' }, this.baseParam, ksParam );
		this.doApiRequest( param, function( data ){
			_this.ks = data.ks;
			callback( _this.ks );
		});
	},
	doApiRequest: function( param, callback ){
		var _this = this;
		// Remove service tag ( hard coded into the api url ) 
		var serviceType = param['service'];
		delete param['service'];	
		
		// Add the signature ( if not a session init ) 
		if( serviceType != 'session' ){
			param['kalsig'] = _this.getSignature( param );
		}

		// Build the request url with sorted params:
		var requestURL = _this.getApiUrl() + serviceType + '&' + $j.param( param );
		
		var globalCBName = 'kapi_' + _this.getSignature( param );
		if( window[ globalCBName ] ){
			mw.log("Error global callback name already exists: " + globalCBName );
			this.doApiRequest(requestUrl, _this.getSignature( param ) + Math.random(), callback );
		}
		window[ globalCBName ] = function( data ){
			// issue the local scope callback:
			callback( data );
			// null this global function name: 
			window[ globalCBName ] = null;
		};
		mw.log("kAPI:: doApiRequest: " + requestURL);
		$j.getScript( requestURL + '&callback=' + globalCBName );
	},
	getApiUrl : function(){
		return mw.getConfig( 'Kaltura.ServiceUrl' ) + mw.getConfig( 'Kaltura.ServiceBase' );
	},
	getSignature: function( params ){
		params = this.ksort(params);
		var str = "";
		for(var v in params) {<commit_msg>requestURL!<commit_after>/*
 * Simple kaltura javascript api
 *
 * uses configuration Kaltura.ServiceUrl and Kaltura.ServiceBase for api entry point
 */ 

/**
 * kApi takes supports a few mixed argument types
 * 
 * @param {Number}
 * 		partner_id used to establish a request key for the given session
 * 		( this enables multiple sessions per partner id on a single page )
 * @param {Mixed}
 * 		Array An Array of request params for multi-request 
 * 		Object Named request params
 */
	
mw.KApi = function( partner_id ){
	return this.init( partner_id );	
};

mw.KApi.prototype = {
	baseParam: {
		'apiVersion' : '3.1',
		'clientTag' : 'html5:v' + window[ 'KALTURA_LOADER_VERSION' ],
		'expiry' : '86400',
		'format' : 9, // 9 = JSONP format
		'ignoreNull' : 1
	},
	playerLoaderCache: [],
	
	// The local kaltura session key ( so it does not have to be re-grabbed with every request
	ks : null,
	init: function( partner_id ){
		this.partner_id = partner_id;
	},
	getPartnerId: function( ){
		return this.partner_id;
	},
	doRequest : function( requestObject, callback ){
		var _this = this;
		var param = {};
		// Convert into a multi-request if no session is set ( ks will be added bellow ) 
		if( !requestObject.length && !this.ks ){
			requestObject = [ requestObject ];
		}

		// If we have Kaltura.NoApiCache flag, pass 'nocache' param to the client
		if( mw.getConfig('Kaltura.NoApiCache') === true ) {
			param['nocache'] = 'true';
		}
		
		// Check that we have a session established if not make it part of our multi-part request
		if( requestObject.length ){
			param['service'] = 'multirequest';
			param['action'] = 'null';

			// Kaltura api starts with index 1 for some strange reason. 
			var mulitRequestIndex = 1;
			
			for( var i = 0 ; i < requestObject.length; i++ ){
				var requestInx = mulitRequestIndex + i;
				// MultiRequest pre-process each param with inx:param
				for( var paramKey in requestObject[i] ){
					// support multi dimension array request:  
					// NOTE kaltura api only has sub arrays ( would be more feature complete to 
					// recursively define key appends )
					if( typeof requestObject[i][paramKey] == 'object' ){
						for( var subParamKey in requestObject[i][paramKey] ){
							param[ requestInx + ':' + paramKey + ':' +  subParamKey ] =
								requestObject[i][paramKey][subParamKey];
						}
					} else {
						param[ requestInx + ':' + paramKey ] = requestObject[i][paramKey];
					}					
				}
			}			
		} else { 
			param = requestObject;
		}				
		
		// add in the base parameters:
		for( var i in this.baseParam ){
			if( typeof param[i] == 'undefined' ){
				param[i] = this.baseParam[i];
			}
		};
		
		// Make sure we have the kaltura session
		// ideally this could be part of the multi-request but could not get it to work 
		// see commented out code above. 
		this.getKS( function( ks ){
			param['ks'] = ks;
			// Do the getJSON jQuery call with special callback=? parameter: 
			_this.doApiRequest( param, callback);
		});
	},
	setKS: function( ks ){
		this.ks = ks;
	},
	getKS: function( callback ){
		if( this.ks ){
			callback( this.ks );
			return true;
		}
		var _this = this;
		// Add the Kaltura session ( if not already set ) 
		var ksParam = {
        	'action' : 'startwidgetsession',
        	'widgetId': '_' + this.partner_id, 
        	'partnerId' : + this.partner_id // don't ask me, I did not design the API!
        };
		// add in the base parameters:
		var param = $j.extend( { 'service' : 'session' }, this.baseParam, ksParam );
		this.doApiRequest( param, function( data ){
			_this.ks = data.ks;
			callback( _this.ks );
		});
	},
	doApiRequest: function( param, callback ){
		var _this = this;
		// Remove service tag ( hard coded into the api url ) 
		var serviceType = param['service'];
		delete param['service'];	
		
		// Add the signature ( if not a session init ) 
		if( serviceType != 'session' ){
			param['kalsig'] = _this.getSignature( param );
		}

		// Build the request url with sorted params:
		var requestURL = _this.getApiUrl() + serviceType + '&' + $j.param( param );
		
		var globalCBName = 'kapi_' + _this.getSignature( param );
		if( window[ globalCBName ] ){
			mw.log("Error global callback name already exists: " + globalCBName );
			this.doApiRequest(requestURL, _this.getSignature( param ) + Math.random(), callback );
		}
		window[ globalCBName ] = function( data ){
			// issue the local scope callback:
			callback( data );
			// null this global function name: 
			window[ globalCBName ] = null;
		};
		mw.log("kAPI:: doApiRequest: " + requestURL);
		$j.getScript( requestURL + '&callback=' + globalCBName );
	},
	getApiUrl : function(){
		return mw.getConfig( 'Kaltura.ServiceUrl' ) + mw.getConfig( 'Kaltura.ServiceBase' );
	},
	getSignature: function( params ){
		params = this.ksort(params);
		var str = "";
		for(var v in params) {
{'fraction_non_alphanumeric': 0.1286302780638517, 'fraction_numerical': 0.002883625128733265, 'mean_word_length': 3.0012360939431395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5543505', 'n_tokens_mistral': 3599, 'n_tokens_neox': 3118, 'n_words': 980}