<commit_before><?php
/*******************************************************************************
 * XboxLeaders Xbox LIVE REST API                                              *
 * =========================================================================== *
 * @file        base.class.php                                                 *
 * @package     XboxLiveApi                                                    *
 * @version     2.0                                                            *
 * @copyright   (c) 2013 - <NAME> <<EMAIL>>                  *
 * @contributor <NAME> <http://github.com/djekl>                            *
 * @contributor <NAME> <http://github.com/lukezbihlyj>                   *
 * @license     http://opensource.org/licenses/mit-license.php The MIT License *
 *******************************************************************************/

class Base {
	public $__cache;

	public $error;
	public $stack_trace = array();
	public $logged_in = false;
	public $redirects = 0;

	public $email, $password;
	public $debug = false;
	public $timeout = 8;

	public $cookie_file = "";
	public $debug_file = "";
	public $stack_trace_file = "";
	public $access_file = "";

	public $runtime = null;
	public $ip = null;
	public $format = "xml";
	public $version = null;

	/**
	 * Error Codes
	 */
	public $errors = array(
		300 => "The key supplied was not valid.",
		301 => "The gamertag supplied was not valid.",
		302 => "The gameid supplied was not valid.",
		303 => "No version specified.",
		304 => "No method specified.",
		305 => "The region supplied is not supported by Xbox LIVE.",
		306 => "The query supplied was not valid.",
		500 => "There was an internal server error.",
		501 => "The gamertag supplied does not exist on Xbox Live.",
		502 => "The gamertag supplied has never played this game or does not exist on Xbox Live.",
		503 => "No friends found, or friend's list is set to private.",
		504 => "The search query returned empty.",
		600 => "Could not login to Windows Live. Please contact me immediately.",
		601 => "The Windows Live email address supplied was invalid.",
		602 => "The Windows Live password supplied was invalid.",
		603 => "Could not write to the cookie file.",
		604 => "Could not write to the debug file.",
		605 => "Could not write to the stack trace file.",
		606 => "Windows Live caused an infinite redirect loop.",
		607 => "The server timed out when trying to fetch some data.",
		608 => "Could not write to the access file.",
		700 => "The Xbox LIVE Service is down."
	);

	function __construct($cache) {
		if($cache) $this->__cache = &$cache;
		
		$this->runtime = microtime(true);
		$this->ip = rand(60, 80) . "." . rand(60, 140) . "." . rand(80, 120) . "." . rand(120, 200);
	}

	public function init($email, $password) {
		$this->email = str_replace("@", "%40", strtolower($email));
		$this->password = <PASSWORD>;

		if($this->check_login()) {
			$this->logged_in = true;
		} else {
			$this->perform_login();
		}
	}

	public function output_headers() {
		header("Content-Type: application/" . str_replace("jsonp", "javascript", $this->format) . "; charset=utf-8");
		header('Access-Control-Allow-Origin: *');
		header('Access-Control-Max-Age: 3628800');
		header("Content-Type: application/" . $this->format . "; charset=utf-8");
	}

	public function output_payload($data) {
		if($this->version == "1.0") {
			$payload = array(
				"Data" => $data,
				"In" => round(microtime(true) - $this->runtime, 3),
				"Stat" => "ok",
				"Authed" => "false",
				"AuthedAs" => null
			);
		} else {
			$payload = array(
				"status" => "success",
				"version" => $this->version,
				"data" => $data,
				"runtime" => round(microtime(true) - $this->runtime, 3) 
			);
		}

		switch ($this->format) {
			case "xml":
				return output_pretty_xml($payload);
			case "json":
				return output_pretty_json($payload);
			case "jsonp":
				return output_pretty_jsonp($payload, $_GET['callback']);
		}

		return false;
	}

	public function output_error($code) {
		if($this->version == "1.0") {
			$payload = array(
				"Error" => $this->errors[$code],
				"In" => round(microtime(true) - $this->runtime, 3),
				"Stat" => "fail",
				"Authed" => "false",
				"AuthedAs" => null
			);
		} else {
			$payload = array(
				"status" => "error",
				"version" => $this->version,
				"data" => array(
					"code" => $code,
					"message" => $this->errors[$code]
				),
				"runtime" => round(microtime(true) - $this->runtime, 3) 
			);
		}

		switch ($this->format) {
			case "xml":
				return output_pretty_xml($payload);
			case "json":
				return output_pretty_json($payload);
			case "jsonp":
				return output_pretty_jsonp($payload, $_GET['callback']);
		}

		return false;<commit_msg>output response codes that co-incide with the error codes<commit_after><?php
/*******************************************************************************
 * XboxLeaders Xbox LIVE REST API                                              *
 * =========================================================================== *
 * @file        base.class.php                                                 *
 * @package     XboxLiveApi                                                    *
 * @version     2.0                                                            *
 * @copyright   (c) 2013 - <NAME>lemons <<EMAIL>>                  *
 * @contributor <NAME> <http://github.com/djekl>                            *
 * @contributor <NAME> <http://github.com/lukezbihlyj>                   *
 * @license     http://opensource.org/licenses/mit-license.php The MIT License *
 *******************************************************************************/

class Base {
	public $__cache;

	public $error;
	public $stack_trace = array();
	public $logged_in = false;
	public $redirects = 0;

	public $email, $password;
	public $debug = false;
	public $timeout = 8;

	public $cookie_file = "";
	public $debug_file = "";
	public $stack_trace_file = "";
	public $access_file = "";

	public $runtime = null;
	public $ip = null;
	public $format = "xml";
	public $version = null;

	/**
	 * Error Codes
	 */
	public $errors = array(
		300 => "The key supplied was not valid.",
		301 => "The gamertag supplied was not valid.",
		302 => "The gameid supplied was not valid.",
		303 => "No version specified.",
		304 => "No method specified.",
		305 => "The region supplied is not supported by Xbox LIVE.",
		306 => "The query supplied was not valid.",
		500 => "There was an internal server error.",
		501 => "The gamertag supplied does not exist on Xbox Live.",
		502 => "The gamertag supplied has never played this game or does not exist on Xbox Live.",
		503 => "No friends found, or friend's list is set to private.",
		504 => "The search query returned empty.",
		600 => "Could not login to Windows Live. Please contact me immediately.",
		601 => "The Windows Live email address supplied was invalid.",
		602 => "The Windows Live password supplied was invalid.",
		603 => "Could not write to the cookie file.",
		604 => "Could not write to the debug file.",
		605 => "Could not write to the stack trace file.",
		606 => "Windows Live caused an infinite redirect loop.",
		607 => "The server timed out when trying to fetch some data.",
		608 => "Could not write to the access file.",
		700 => "The Xbox LIVE Service is down."
	);

	function __construct($cache) {
		if($cache) $this->__cache = &$cache;
		
		$this->runtime = microtime(true);
		$this->ip = rand(60, 80) . "." . rand(60, 140) . "." . rand(80, 120) . "." . rand(120, 200);
	}

	public function init($email, $password) {
		$this->email = str_replace("@", "%40", strtolower($email));
		$this->password = <PASSWORD>;

		if($this->check_login()) {
			$this->logged_in = true;
		} else {
			$this->perform_login();
		}
	}

	public function output_headers() {
		header("Content-Type: application/" . str_replace("jsonp", "javascript", $this->format) . "; charset=utf-8");
		header('Access-Control-Allow-Origin: *');
		header('Access-Control-Max-Age: 3628800');
		header("Content-Type: application/" . $this->format . "; charset=utf-8");
	}

	public function output_payload($data) {
		if($this->version == "1.0") {
			$payload = array(
				"Data" => $data,
				"In" => round(microtime(true) - $this->runtime, 3),
				"Stat" => "ok",
				"Authed" => "false",
				"AuthedAs" => null
			);
		} else {
			$payload = array(
				"status" => "success",
				"version" => $this->version,
				"data" => $data,
				"runtime" => round(microtime(true) - $this->runtime, 3) 
			);
		}

		switch ($this->format) {
			case "xml":
				return output_pretty_xml($payload);
			case "json":
				return output_pretty_json($payload);
			case "jsonp":
				return output_pretty_jsonp($payload, $_GET['callback']);
		}

		return false;
	}

	public function output_error($code) {
		// output the response code
		if(array_key_exists((int)$code, $this->errors)) {
			http_response_code((int)$code);
		}

		if($this->version == "1.0") {
			$payload = array(
				"Error" => $this->errors[$code],
				"In" => round(microtime(true) - $this->runtime, 3),
				"Stat" => "fail",
				"Authed" => "false",
				"AuthedAs" => null
			);
		} else {
			$payload = array(
				"status" => "error",
				"version" => $this->version,
				"data" => array(
					"code" => $code,
					"message" => $this->errors[$code]
				),
				"runtime" => round(microtime(true) - $this->runtime, 3) 
			);
		}

		switch ($this->format) {
			case "xml":
				return output_pretty_xml($payload);
			case "json":
				return output_pretty_json($payload);
			case "jsonp":
				return output_pretty_jsonp($payload, $_GET['callback']);
		}

		return false;
{'fraction_non_alphanumeric': 0.20396776193428395, 'fraction_numerical': 0.023351932217400288, 'mean_word_length': 2.8061344868265827, 'pattern_counts': {'":': 12, '<': 21, '<?xml version=': 0, '>': 148, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4213952', 'n_tokens_mistral': 3432, 'n_tokens_neox': 2844, 'n_words': 832}