<commit_before><?php
/**
 * Provides functions to get data from the public blizzar World of Warcraft API.
 *
 * This is a free, none commercial package to give a basic standardised function
 * set to communicate between your own tool and the public web api for the game
 * World of Warcraft from Blizzard Entertainment's®. Before you use this package
 * please read the Legal FAQ from Blizzard:
 * http://eu.blizzard.com/en-gb/company/about/legal-faq.html
 *
 * @package jpWoW
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2015, <NAME>
 * @license http://opensource.org/licenses/MIT MIT see LICENSE.txt
 *
 * @link http://blizzard.github.io/api-wow-docs
 */
class jpWoW
{
	/**
	 * @var jpWoWregion
	 */
	private $_region;

	/**
	 * @var false|jpWoWAuthentication
	 */
	private $_authentication;

	/**
	 * @param jpWoWregion $region
	 * @param jpWoWAuthentication $auth
	 */
	public function __construct(jpWoWregion $region, jpWoWAuthentication $auth = null)
	{
		$this->_setRegion($region);

		if(!empty($auth)) {
			$this->setAuthentication($auth);
		} else {
			$this->_authentication = false;
		}
	}

	/**
	 * @param jpWoWregion $region
	 */
	protected function _setRegion(jpWoWregion $region)
	{
		$this->_region = $region;
	}

	/**
	 * @param string $subPath
	 * @return mixed
	 */
	private function _performRequest($subPath, $jsonencode = true)
	{
		$urlPath = '/api/wow/'.$subPath;

		if($this->_authentication !== false) {
			$this->_authentication->setHost($this->_region->getHost());
			$this->_authentication->setTimestamp(time());
			$this->_authentication->setUrlPath($urlPath);
		}

		$url = $this->_region->getHost().$urlPath;

		if(strpos($url, '?') !== false) {
			$url .= '&';
		} else {
			$url .= '?';
		}

		$url .= 'locale='.$this->_region->getLocale();

		$cr = curl_init();
		curl_setopt($cr, CURLOPT_URL, $url);
		curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($cr);
		curl_close($cr);

		if (
			$jsonencode
			&& strpos($output, '{') !== false
			&& strpos($output, '}') !== false
		) {
			return json_decode($output, true);
		} else {
			return $output;
		}
	}

	/**
	 * @param jpWoWAuthentication $auth
	 */
	public function setAuthentication(jpWoWAuthentication $auth)
	{
		$this->_authentication = $auth;
	}

	/**
	 * Reset the authentication to <b>false</b> to allow using the none
	 * authentification mode.
	 */<commit_msg>Fix missing jsonencode parameter implementation<commit_after><?php
/**
 * Provides functions to get data from the public blizzar World of Warcraft API.
 *
 * This is a free, none commercial package to give a basic standardised function
 * set to communicate between your own tool and the public web api for the game
 * World of Warcraft from Blizzard Entertainment's®. Before you use this package
 * please read the Legal FAQ from Blizzard:
 * http://eu.blizzard.com/en-gb/company/about/legal-faq.html
 *
 * @package jpWoW
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2015, <NAME>
 * @license http://opensource.org/licenses/MIT MIT see LICENSE.txt
 *
 * @link http://blizzard.github.io/api-wow-docs
 */
class jpWoW
{
	/**
	 * @var jpWoWregion
	 */
	private $_region;

	/**
	 * @var false|jpWoWAuthentication
	 */
	private $_authentication;

	/**
	 * @var bool
	 */
	private $_decodeResult = true;

	/**
	 * Set to false if you wand that the class returns the data in raw json instead of an array.
	 *
	 * @param bool $val
	 */
	public function setDecodeResult($val)
	{
		$this->_decodeResult = (bool)$val;
	}

	/**
	 * @param jpWoWregion $region
	 * @param jpWoWAuthentication $auth
	 */
	public function __construct(jpWoWregion $region, jpWoWAuthentication $auth = null)
	{
		$this->_setRegion($region);

		if(!empty($auth)) {
			$this->setAuthentication($auth);
		} else {
			$this->_authentication = false;
		}
	}

	/**
	 * @param jpWoWregion $region
	 */
	protected function _setRegion(jpWoWregion $region)
	{
		$this->_region = $region;
	}

	/**
	 * @param string $subPath
	 * @return mixed
	 */
	private function _performRequest($subPath)
	{
		$urlPath = '/api/wow/'.$subPath;

		if($this->_authentication !== false) {
			$this->_authentication->setHost($this->_region->getHost());
			$this->_authentication->setTimestamp(time());
			$this->_authentication->setUrlPath($urlPath);
		}

		$url = $this->_region->getHost().$urlPath;

		if(strpos($url, '?') !== false) {
			$url .= '&';
		} else {
			$url .= '?';
		}

		$url .= 'locale='.$this->_region->getLocale();

		$cr = curl_init();
		curl_setopt($cr, CURLOPT_URL, $url);
		curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($cr);
		curl_close($cr);

		if (
			$this->_decodeResult
			&& strpos($output, '{') !== false
			&& strpos($output, '}') !== false
		) {
			return json_decode($output, true);
		} else {
			return $output;
		}
	}

	/**
	 * @param jpWoWAuthentication $auth
	 */
	public function setAuthentication(jpWoWAuthentication $auth)
	{
		$this->_authentication = $auth;
	}

	/**
	 * Reset the authentication to <b>false</b> to allow using the none
	 * authentification mode.
	 */
{'fraction_non_alphanumeric': 0.15992865636147444, 'fraction_numerical': 0.0019817677368212444, 'mean_word_length': 3.6260311640696608, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, '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': '6279879', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1703, 'n_words': 404}