<commit_before><?php
/**
 * Created by <NAME> <<EMAIL>>
 * Date: 9/27/16
 */

namespace YandexWebmaster\ActionHandler;

use Yandex\ActionHandler\ActionHandlerInterface;
use Yandex\Exception\BadRequestException;
use Yandex\Exception\BadResponseException;
use Yandex\Exception\ConflictException;
use Yandex\Exception\ForbiddenException;
use Yandex\Exception\NotFoundException;
use Yandex\Http\Response;
use Yandex\Utils\Json;

final class AddSitemapActionHandler implements ActionHandlerInterface
{
    /**
     * @var array
     */
    private $exceptionsMap = array(
        400 => BadRequestException::class,
        403 => ForbiddenException::class,
        404 => NotFoundException::class,
        409 => ConflictException::class
    );

    /**
     * @param Response $response
     * @return string
     * @throws BadResponseException
     */
    public function handle(Response $response)
    {
        if ($response->getStatusCode() != 201) {
            $exceptionClass = $this->exceptionsMap[$response->getStatusCode()];
            throw new $exceptionClass(\Yandex\apiJsonErrorToMessage($response));
        }

        $responseData = Json::decode($response->getBody());
        if (isset($responseData['sitemap_id']) == false) {
            throw new BadResponseException('Bad response.' . var_export($responseData, true));
        }

        return (string)$responseData['sitemap_id'];
    }
}<commit_msg>add extra<commit_after><?php
/**
 * Created by <NAME> <<EMAIL>>
 * Date: 9/27/16
 */

namespace YandexWebmaster\ActionHandler;

use Yandex\ActionHandler\ActionHandlerInterface;
use Yandex\Exception\BadRequestException;
use Yandex\Exception\BadResponseException;
use Yandex\Exception\ConflictException;
use Yandex\Exception\ForbiddenException;
use Yandex\Exception\NotFoundException;
use Yandex\Http\Response;
use Yandex\Utils\Json;

final class AddSitemapActionHandler implements ActionHandlerInterface
{
    /**
     * @var array
     */
    private $exceptionsMap = array(
        400 => BadRequestException::class,
        403 => ForbiddenException::class,
        404 => NotFoundException::class,
        409 => ConflictException::class
    );

    /**
     * @param Response $response
     * @return string
     * @throws BadResponseException
     */
    public function handle(Response $response)
    {
        $responseData = Json::decode($response->getBody());

        if ($response->getStatusCode() != 201) {
            $extra = [];
            if (isset($responseData['sitemap_id'])) {
                $extra['sitemap_id'] = $responseData['sitemap_id'];
            }

            $exceptionClass = $this->exceptionsMap[$response->getStatusCode()];
            throw new $exceptionClass(\Yandex\apiJsonErrorToMessage($response), 0, null, $extra);
        }

        if (isset($responseData['sitemap_id']) == false) {
            throw new BadResponseException('Bad response.' . var_export($responseData, true));
        }

        return (string)$responseData['sitemap_id'];
    }
}
{'fraction_non_alphanumeric': 0.12616201859229748, 'fraction_numerical': 0.013612217795484728, 'mean_word_length': 3.2376933895921236, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '3304727', 'n_tokens_mistral': 878, 'n_tokens_neox': 846, 'n_words': 159}