<commit_before><?php
namespace OpenAgenda;

use OpenAgenda\Cache;

class OpenAgenda
{
    /**
     * api secret token
     * @var string|null
     */
    protected $_secret = null;

    /**
     * guzzleClient
     * @var GuzzleHttp\Client|null
     */
    public $guzzleClient = null;

    /**
     * constuctor
     * @param string $apiSecret openagenda api secret
     */
    public function __construct($apiSecret)
    {
        $this->_secret = $apiSecret;

        $this->guzzleClient = new \GuzzleHttp\Client;

        $this->_initToken();
    }

    /**
     * get access token from API or local cache
     * @return string api access_token
     */
    protected function _initToken()
    {
        $cache = Cache::read('openagenda-token');
    }
}<commit_msg>openagenda init access token<commit_after><?php
namespace OpenAgenda;

use \DateTime;

class OpenAgenda
{
    /**
     * api secret token
     * @var string|null
     */
    protected $_secret = null;

    /**
     * http client
     * @var OpenAgenda\Client|null
     */
    public $client = null;

    /**
     * constuctor
     * @param string $apiSecret openagenda api secret
     */
    public function __construct($apiSecret)
    {
        $this->_secret = $apiSecret;

        $this->client = new Client;

        $this->_initToken();
    }

    /**
     * get access token from API or local cache
     * @return string api access_token
     */
    protected function _initToken()
    {
        $accessToken = Cache::read('openagenda-token');

        if (empty($accessToken)) {
            $options = [
                'grant_type' => 'authorization_code',
                'code' => $this->_secret,
            ];

            try {
                $response = $this->client->post('/requestAccessToken', $options);

                Cache::write('openagenda-token', $response->access_token, $response->expires_in);

                $accessToken = $response->access_token;
            } catch (\GuzzleHttp\Exception\RequestException $e) {
                $request = $e->getRequest();
                $response = $e->getResponse();
                if ($e->hasResponse()) {
                    throw new \Exception($response->getBody()->getContents());
                }
            }
        }

        $this->client->setAccessToken($accessToken);
    }

    public function newEvent()
    {
        return new Event;
    }
}
{'fraction_non_alphanumeric': 0.1267723102585488, 'fraction_numerical': 0.0, 'mean_word_length': 1.8696172248803828, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '306769', 'n_tokens_mistral': 700, 'n_tokens_neox': 667, 'n_words': 147}