<commit_before><?php

class EventApi extends Extension {

	private $api_endpoint = '';
	private $api_username = '';
	private $api_password = ''; 
	private $api_connection_tested = false;

	/*
	constructor
	*/
	function __construct() {
		$config = Config::inst();
	
		$this->api_endpoint = $config->get('EventApi', 'eventFinderApiEndPoint'); // update later to switch endpoints depending upon query type 
		$this->api_username = $config->get('EventApi', 'eventFinderUsername');
		$this->api_password = $config->get('EventApi', 'eventFinderPassword');

	}


	/*
	test the connection before we query for 
	@param null
	@return boolean
	*/
	public function test_connection() {

		$config = Config::inst();

		return $this->api_connect('rows=1') ? true : false;;

	}

	public function api_connect($query_string = null) {

		$qs = '';

		if($query_string && strlen($query_string) > 0) {
			$qs = '?' . $query_string;
		}

		$process = curl_init($this->api_endpoint);
		curl_setopt($process, CURLOPT_USERPWD, $this->api_username . ":" . $this->api_password);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
		$event_data = curl_exec($process);

		return $event_data;
	}

	/*
	utiliuty function to set up query string from array key / value pairs
	@param $parameters Array - key: value pairs
	@return String
	*/
	public function set_query_string(Array $parameters) {
		$qs = '?';

		foreach ($parameters as $key => $value) {
			$qs .= urlencode($key) . '=' . urlencode($value).'&';	
		}

		if(strlen($qs) > 0) {
			// strip last &
			$qs = substr($qs, 0, strlen($qs) - 1);
		}

		return $qs;
	}

	/*
	get latest data
	@param String $qsParams - query string parameters to pass to query 
	@param $modified_since DateTime
	@return Array - structured event data 
	*/
	public function get_data(Array $qsParams, String $modified_since) {

		if(!$this->api_connection_tested) {
			if(!$this->test_connection()) {
				// TODO: log error
				return false;
			}
			else {
				$this->api_connection_tested = true;
			}
		}
		
		$qs = '';


		if(!empty($qsParams)) {
			$qs = $this->set_query_string($qsParams);
		}

		$data = $this->api_connect($qs);

		// print_r($data);

		// format as array
		return Convert::json2array($data->events);
	}

}<commit_msg>figuring out returned JSON structure<commit_after><?php

class EventApi extends Extension {

	private $api_endpoint = '';
	private $api_username = '';
	private $api_password = ''; 
	private $api_connection_tested = false;

	/*
	constructor
	*/
	function __construct() {
		$config = Config::inst();
	
		$this->api_endpoint = $config->get('EventApi', 'eventFinderApiEndPoint'); // update later to switch endpoints depending upon query type 
		$this->api_username = $config->get('EventApi', 'eventFinderUsername');
		$this->api_password = $config->get('EventApi', 'eventFinderPassword');

	}


	/*
	test the connection before we query for 
	@param null
	@return boolean
	*/
	public function test_connection() {

		$config = Config::inst();

		return $this->api_connect('rows=1') ? true : false;;

	}

	public function api_connect($query_string = null) {

		$qs = '';

		if($query_string && strlen($query_string) > 0) {
			$qs = '?' . $query_string;
		}

		$process = curl_init($this->api_endpoint);
		curl_setopt($process, CURLOPT_USERPWD, $this->api_username . ":" . $this->api_password);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
		$event_data = curl_exec($process);

		return $event_data;
	}

	/*
	utiliuty function to set up query string from array key / value pairs
	@param $parameters Array - key: value pairs
	@return String
	*/
	public function set_query_string(Array $parameters) {
		$qs = '?';

		foreach ($parameters as $key => $value) {
			$qs .= urlencode($key) . '=' . urlencode($value).'&';	
		}

		if(strlen($qs) > 0) {
			// strip last &
			$qs = substr($qs, 0, strlen($qs) - 1);
		}

		return $qs;
	}

	/*
	get latest data
	@param String $qsParams - query string parameters to pass to query 
	@param $modified_since DateTime
	@return Array - structured event data 
	*/
	public function get_data(Array $qsParams, String $modified_since) {

		if(!$this->api_connection_tested) {
			if(!$this->test_connection()) {
				// TODO: log error
				return false;
			}
			else {
				$this->api_connection_tested = true;
			}
		}
		
		$qs = '';


		if(!empty($qsParams)) {
			$qs = $this->set_query_string($qsParams);
		}

		$data = $this->api_connect($qs);

		print_r($data);

		// format as array
		return Convert::json2array($data->events);
	}

}
{'fraction_non_alphanumeric': 0.15609756097560976, 'fraction_numerical': 0.0026607538802660754, 'mean_word_length': 3.7786016949152543, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 41, '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': '1307592', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1489, 'n_words': 350}