<commit_before><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\UDB2;

use CultuurNet\Auth\ConsumerCredentials;
use CultuurNet\Auth\Guzzle\OAuthProtectedService;
use ValueObjects\String\String;

/**
 * Service to retrieve event CDBXML, from the Entry API.
 *
 * This uses the 'Light UiTID' authentication, as described in
 * https://docs.google.com/document/d/14vteMLuhDbUbn_49WMoGxHXtGJIpMaD7fqoR7VyQDwI/edit#.
 */
class EventCdbXmlFromEntryAPI extends OAuthProtectedService implements EventCdbXmlServiceInterface
{
    /**
     * @var String
     */
    private $userId;

    /**
     * @param string $baseUrl
     * @param ConsumerCredentials $consumerCredentials
     * @param String $userId
     */
    public function __construct(
        $baseUrl,
        ConsumerCredentials $consumerCredentials,
        String $userId
    ) {
        parent::__construct(
            $baseUrl,
            $consumerCredentials
        );

        $this->userId = $userId;
    }

    /**
     * @return \Guzzle\Http\Client
     */
    protected function getClient(array $additionalOAuthParameters)
    {
        $client = parent::getClient($additionalOAuthParameters);
        $client->setDefaultOption(
            'headers',
            [
                'Accept' => 'text/xml'
            ]
        );
        $client->setDefaultOption(
            'query',
            [
                'uid' => (string) $this->userId
            ]
        );

        return $client;
    }

    /**
     * @param string $eventId
     * @return string
     * @throws EventNotFoundException If the event can not be found.
     */
    public function getCdbXmlOfEvent($eventId)
    {
        $this->guardEventId($eventId);

        $request = $this->getClient()->get('event/' . $eventId);
        $response = $request->send();

        // @todo verify response Content-Type<commit_msg>III-349: Update method signature according to parent class<commit_after><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\UDB2;

use CultuurNet\Auth\ConsumerCredentials;
use CultuurNet\Auth\Guzzle\OAuthProtectedService;
use ValueObjects\String\String;

/**
 * Service to retrieve event CDBXML, from the Entry API.
 *
 * This uses the 'Light UiTID' authentication, as described in
 * https://docs.google.com/document/d/14vteMLuhDbUbn_49WMoGxHXtGJIpMaD7fqoR7VyQDwI/edit#.
 */
class EventCdbXmlFromEntryAPI extends OAuthProtectedService implements EventCdbXmlServiceInterface
{
    /**
     * @var String
     */
    private $userId;

    /**
     * @param string $baseUrl
     * @param ConsumerCredentials $consumerCredentials
     * @param String $userId
     */
    public function __construct(
        $baseUrl,
        ConsumerCredentials $consumerCredentials,
        String $userId
    ) {
        parent::__construct(
            $baseUrl,
            $consumerCredentials
        );

        $this->userId = $userId;
    }

    /**
     * @inheritdoc
     */
    protected function getClient(array $additionalOAuthParameters = array())
    {
        $client = parent::getClient($additionalOAuthParameters);
        $client->setDefaultOption(
            'headers',
            [
                'Accept' => 'text/xml'
            ]
        );
        $client->setDefaultOption(
            'query',
            [
                'uid' => (string) $this->userId
            ]
        );

        return $client;
    }

    /**
     * @param string $eventId
     * @return string
     * @throws EventNotFoundException If the event can not be found.
     */
    public function getCdbXmlOfEvent($eventId)
    {
        $this->guardEventId($eventId);

        $request = $this->getClient()->get('event/' . $eventId);
        $response = $request->send();

        // @todo verify response Content-Type
{'fraction_non_alphanumeric': 0.11361826387045394, 'fraction_numerical': 0.00504380143350146, 'mean_word_length': 2.1905165114309906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4107054', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1108, 'n_words': 220}