<commit_before><?php
require_once ('ELSTR_Service_Abstract.php');
require_once ('ELSTR_HttpClient.php');

/**
 * This as an example of a custom application, using http authentication
 *
 * @author <NAME>
 */
class ELSTR_Service_Windchill_REST extends ELSTR_Service_Abstract {

    private $m_timeout;
    private $m_maxredirects;
    private $m_url;
    
    private $m_username;
    private $m_password;

    /**
     *
     * @return
     */
    function __construct($options) {
        parent::__construct();

        $this->m_timeout = $options['timeout'];
        $this->m_maxredirects = $options['maxredirects'];
        $this->m_url = $options['url'];
        
        $this->m_username = $options['username'];
        $this->m_password = $options['password'];

    }

	protected function request($serviceUrl, $parameters) {
			
			$restClient = new ELSTR_HttpClient();
			$restClient->setAuth($this->m_username, $this->m_password);
			$restClient->setUri($this->m_url.$serviceUrl);
			$restClient->setConfig(array(
			'maxredirects' => $this->m_maxredirects,
			'timeout'      => $this->m_timeout));			
			$restClient->setParameterGet($parameters);
            $response = $restClient->request();
            //print_r($restClient->getLastRequest());
			return $response;
	}	

}
?><commit_msg>Added persistent (cached) session with a cookie jar<commit_after><?php
require_once ('ELSTR_Service_Abstract.php');
require_once ('ELSTR_HttpClient.php');

/**
 * This as an example of a custom application, using http authentication
 *
 * @author <NAME>
 */
class ELSTR_Service_Windchill_REST extends ELSTR_Service_Abstract {

    private $m_timeout;
    private $m_maxredirects;
    private $m_url;
    
    private $m_username;
    private $m_password;

    private $m_cookieJarCache = null;

    /**
     *
     * @return
     */
    function __construct($options) {
        parent::__construct();

        $this->m_timeout = $options['timeout'];
        $this->m_maxredirects = $options['maxredirects'];
        $this->m_url = $options['url'];
        
        $this->m_username = $options['username'];
        $this->m_password = $options['password'];

        if(isset($options['cookieJarCache'])){
            $this->m_cookieJarCache = $options['cookieJarCache'];
        }
        
    }

	protected function request($serviceUrl, $parameters) {

		$restClient = new ELSTR_HttpClient();
		$restClient->setAuth($this->m_username, $this->m_password);
		$restClient->setUri($this->m_url.$serviceUrl);
		$restClient->setConfig(array(
		'maxredirects' => $this->m_maxredirects,
		'timeout'      => $this->m_timeout));			
		$restClient->setParameterGet($parameters);

        if($this->m_cookieJarCache) {
            $last_char = substr(sys_get_temp_dir(), -1, 1);
            $systemTempDir = sys_get_temp_dir();
            //last char might be \n => account for that
            if (strpos($last_char, "/")===false || strpos($last_char, "\\")===false) {
                $systemTempDir .= "/";
            }
            $systemTempDir .= "ELSTR_Service_Windchill_REST/";
            if (!file_exists($systemTempDir)){
                mkdir($systemTempDir);
            }

            $cache = Zend_Cache::factory('Core','File',$this->m_cookieJarCache,array('cache_dir' => $systemTempDir));            
            if(!$cookieJar = $cache->load('cookieJar_'.Zend_Session::getId())) {
                // Cache miss; 
                $restClient->setCookieJar();
            } else {
                $restClient->setCookieJar($cookieJar);
            }
        }

        $response = $restClient->request();
        //print_r($restClient->getLastRequest());

        if($this->m_cookieJarCache) {
            if ($restClient->getCookieJar() !== $cookieJar){
                $cache->save($restClient->getCookieJar(),'cookieJar_'.Zend_Session::getId());
            }
        }

        
		return $response;
	}

}
?>
{'fraction_non_alphanumeric': 0.15321756894790603, 'fraction_numerical': 0.0005107252298263534, 'mean_word_length': 2.7304761904761903, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 55, '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': '5522041', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1187, 'n_words': 188}