<commit_before><?php
# Check for required Curl extension
if (!function_exists('curl_init')) {
	throw new Exception('You need to have the CURL PHP extension.');
}
# Check for required JSON extension
if (!function_exists('json_decode') || !function_exists('json_encode')) {
	throw new Exception('You need to have the JSON PHP extension.');
}

class sosocio_base{
	
	# API endpoint
	protected $serverUrl;
	# API user key
	protected $apiKey;
	# API user secret
	protected $apiSecret;
	# API bundle certificate for SSL
	protected $bundleCertificate;
	
	# Mimetype for requests	
	protected $mimeType = 'application/json';
	
	# Curl timeout
	protected $curlTimeOut = 60;
	
	# Http codes used to check for errors
	public $httpCodes = array(200,201);
	
	# Total record count api
	public $totalRecords;
	
	# Pagination api
	public $pagination;
	
	private $responseHeaders;
	
	# Request data
	private $arrData;
	
	# Default request parameters
	private $defaultData = 	array(
		'options'	=>	array(),
		'inputdata'	=>	array()
	);
	
	private $result;
	protected $error;

	/**
	 * Get default curl options for request
	 * 
	 * @return array curl options
	 */
	public function getDefaultCurlOptions(){
		return array(
			CURLOPT_CONNECTTIMEOUT	=> 10,
			CURLOPT_RETURNTRANSFER	=> true,
			CURLOPT_TIMEOUT			=> $this->curlTimeOut,
			CURLOPT_USERAGENT		=> 'sosocio',
			CURLOPT_HEADER 			=> true,
			CURLOPT_HTTPHEADER		=> array('apiKey:'.$this->apiKey,'apiSecret:'.$this->apiSecret,'X-Requested-With:XMLHttpRequest','Accept:'.$this->mimeType),
			CURLOPT_CAINFO			=> $this->bundleCertificate
		);
	}

	/**
	 * Build URL for API request
	 * 
	 * @param str $url: the request endpoint
	 * 
	 * @return str $finalUrl
	 */
	public function buildUrl($url){
		# URL for request starts with the server url
		$finalUrl  = $this->serverUrl;
		# Analyze request endpoint
		$urlParts = parse_url($url);
	
		# Add request endpoint path to final URL
		if(isset($urlParts['path']) && !empty($urlParts['path'])){
			$finalUrl .= $urlParts['path'];
		}
		
		if(isset($urlParts['query'])){
			# Parse the query string 
			parse_str($urlParts['query'],$arrQueryParts);
			
			$finalUrl .= '?'.http_build_query($arrQueryParts);
		}
		
		# Return final url
		return $finalUrl;
	}
	
	private function handleError($ch, $result){

		$curlInfo = curl_getinfo($ch);

		if($curlError = curl_error($ch)){
			throw new Exception($curlError);
		}

		if(!in_array($curlInfo['http_code'],$this->httpCodes)){
			$code = $curlInfo['http_code'];
			if (PHP_SAPI!='cli') {
				$this->error = array(
					'code' => $code,
					'text' => trim($result)
				);
			}
			
			throw new \Exception($code.': '.$result);<commit_msg>ADDED url to error array<commit_after><?php
# Check for required Curl extension
if (!function_exists('curl_init')) {
	throw new Exception('You need to have the CURL PHP extension.');
}
# Check for required JSON extension
if (!function_exists('json_decode') || !function_exists('json_encode')) {
	throw new Exception('You need to have the JSON PHP extension.');
}

class sosocio_base{
	
	# API endpoint
	protected $serverUrl;
	# API user key
	protected $apiKey;
	# API user secret
	protected $apiSecret;
	# API bundle certificate for SSL
	protected $bundleCertificate;
	
	# Mimetype for requests	
	protected $mimeType = 'application/json';
	
	# Curl timeout
	protected $curlTimeOut = 60;
	
	# Http codes used to check for errors
	public $httpCodes = array(200,201);
	
	# Total record count api
	public $totalRecords;
	
	# Pagination api
	public $pagination;
	
	private $responseHeaders;
	
	# Request data
	private $arrData;
	
	# Default request parameters
	private $defaultData = 	array(
		'options'	=>	array(),
		'inputdata'	=>	array()
	);
	
	private $result;
	protected $error;

	/**
	 * Get default curl options for request
	 * 
	 * @return array curl options
	 */
	public function getDefaultCurlOptions(){
		return array(
			CURLOPT_CONNECTTIMEOUT	=> 10,
			CURLOPT_RETURNTRANSFER	=> true,
			CURLOPT_TIMEOUT			=> $this->curlTimeOut,
			CURLOPT_USERAGENT		=> 'sosocio',
			CURLOPT_HEADER 			=> true,
			CURLOPT_HTTPHEADER		=> array('apiKey:'.$this->apiKey,'apiSecret:'.$this->apiSecret,'X-Requested-With:XMLHttpRequest','Accept:'.$this->mimeType),
			CURLOPT_CAINFO			=> $this->bundleCertificate
		);
	}

	/**
	 * Build URL for API request
	 * 
	 * @param str $url: the request endpoint
	 * 
	 * @return str $finalUrl
	 */
	public function buildUrl($url){
		# URL for request starts with the server url
		$finalUrl  = $this->serverUrl;
		# Analyze request endpoint
		$urlParts = parse_url($url);
	
		# Add request endpoint path to final URL
		if(isset($urlParts['path']) && !empty($urlParts['path'])){
			$finalUrl .= $urlParts['path'];
		}
		
		if(isset($urlParts['query'])){
			# Parse the query string 
			parse_str($urlParts['query'],$arrQueryParts);
			
			$finalUrl .= '?'.http_build_query($arrQueryParts);
		}
		
		# Return final url
		return $finalUrl;
	}
	
	private function handleError($ch, $result){

		$curlInfo = curl_getinfo($ch);

		if($curlError = curl_error($ch)){
			throw new Exception($curlError);
		}

		if(!in_array($curlInfo['http_code'],$this->httpCodes)){
			$code = $curlInfo['http_code'];
			if (PHP_SAPI!='cli') {
				$this->error = array(
					'code' => $code,
					'text' => trim($result),
					'url' => $curlInfo['url']
				);
			}
			
			throw new \Exception($code.': '.$result);
{'fraction_non_alphanumeric': 0.14001857010213556, 'fraction_numerical': 0.003714020427112349, 'mean_word_length': 3.982423681776133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '1849865', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1743, 'n_words': 447}