<commit_before><?php
/**
 *
 * http://api.dotmailer.com/v2/help/wadl
 * http://www.dotmailer.co.uk/api/more_about_api/api_error_codes.aspx
 *
 * @author <NAME> <<EMAIL>>
 *
 */

namespace DotMailer\Api;

use RestClient\Client,
	RestClient\Request;

/**
 * Class RestClient
 *
 * Bridge class providing the IRestClient interface.
 *
 * @package DotMailer\Api
 */
class RestClient implements IRestClient {

	/** @var \RestClient\Client */
	private $restClient;

	public function __construct($username, $password) {

		$this->restClient = new Client(array(
			Request::BASE_URL_KEY => 'https://api.dotmailer.com/v2',
			Request::USERNAME_KEY => $username,
			Request::PASSWORD_KEY => $password,
			Request::USER_AGENT_KEY => 'romanpitak/dotmailer-api-v2-php-client',
			Request::HEADERS_KEY => array(
				'Content-Type' => 'application/json'
			),
			Request::CURL_OPTIONS_KEY => array(
				CURLOPT_SSL_VERIFYPEER => false
			),
		));

	}

	public function execute($param_arr, $responses = array()) {

		// when only url is supplied
		if (is_string($param_arr)) {
			$param_arr = array($param_arr);
		}

		// get request
		$callback = array($this->restClient, 'newRequest');
		$request = call_user_func_array($callback, $param_arr);

		// get response
		$response = $request->getResponse();

		/*
		 * process response
		 */

		// get return code
		$returnCode = $response->getInfo()->http_code;

		// is there a special action to be done?
		if (isset($responses[$returnCode])) {
			return call_user_func($responses[$returnCode], $response);
		}

		// default response processing
		switch ((int)$returnCode) {
			case 200:
			case 201:
			case 202:
				return self::recursiveToArray(json_decode($response->getParsedResponse()));
				break;
			case 204: // no content
				return 'OK';
			default:

				// todo solve this maybe nicer?
				throw new ServiceException($response->getParsedResponse(), $returnCode);

				$message = 'ERROR';
				$response = $response->getParsedResponse();
				// todo solve HTML response on 404
				if (isset($response['message'])) {
					$message = $response['message'];
				} elseif ("" != $result->getError()) {
					$message = $result->getError();
				}
				throw new ServiceException($message, $returnCode);
		}
	}


}<commit_msg>bug fix reference to deprecated "recursiveToArray" removed<commit_after><?php
/**
 *
 * http://api.dotmailer.com/v2/help/wadl
 * http://www.dotmailer.co.uk/api/more_about_api/api_error_codes.aspx
 *
 * @author <NAME> <<EMAIL>>
 *
 */

namespace DotMailer\Api;

use RestClient\Client,
	RestClient\Request;

class RestClientException extends Exception {
}

/**
 * Class RestClient
 *
 * Bridge class providing the IRestClient interface.
 *
 * @package DotMailer\Api
 */
class RestClient implements IRestClient {

	/** @var \RestClient\Client */
	private $restClient;

	public function __construct($username, $password) {

		$this->restClient = new Client(array(
			Request::BASE_URL_KEY => 'https://api.dotmailer.com/v2',
			Request::USERNAME_KEY => $username,
			Request::PASSWORD_KEY => $password,
			Request::USER_AGENT_KEY => 'romanpitak/dotmailer-api-v2-php-client',
			Request::HEADERS_KEY => array(
				'Content-Type' => 'application/json'
			),
			Request::CURL_OPTIONS_KEY => array(
				CURLOPT_SSL_VERIFYPEER => false
			),
		));

	}

	public function execute($param_arr, $responses = array()) {

		// when only url is supplied
		if (is_string($param_arr)) {
			$param_arr = array($param_arr);
		}

		// get request
		$callback = array($this->restClient, 'newRequest');
		$request = call_user_func_array($callback, $param_arr);

		// get response
		$response = $request->getResponse();

		/*
		 * process response
		 */

		// get return code
		$returnCode = $response->getInfo()->http_code;

		// is there a special action to be done?
		if (isset($responses[$returnCode])) {
			return call_user_func($responses[$returnCode], $response);
		}

		// default response processing
		switch ((int)$returnCode) {
			case 200:
			case 201:
			case 202:
				return $response->getParsedResponse();
				break;
			case 204: // no content
				return 'OK';
			default:

				// todo solve this maybe nicer?
				throw new RestClientException($response->getParsedResponse(), $returnCode);

				$message = 'ERROR';
				$response = $response->getParsedResponse();
				// todo solve HTML response on 404
				if (isset($response['message'])) {
					$message = $response['message'];
				} elseif ("" != $result->getError()) {
					$message = $result->getError();
				}
				throw new RestClientException($message, $returnCode);
		}
	}


}
{'fraction_non_alphanumeric': 0.1523684784981445, 'fraction_numerical': 0.007858546168958742, 'mean_word_length': 3.6755102040816325, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2596884', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1461, 'n_words': 310}