public function addOriginalText($text, $yandexSiteID)
    {
        /** @var Cache $cache */
        $cache = \Yii::$app->get($this->cacheComponent);
        $cacheKey = "Yandex_OT_sent:" . $this->clientID . "_" . $this->clientSecret;

        $sent = $cache->get($cacheKey);
        if ($sent === false) {
            $sent = 0;
        }

        if ($sent >= self::YANDEX_OT_DAILY_LIMIT) {
            throw new InvalidParamException("Daily limit exceeded!");
        }

        $validator = new StringValidator([
            'min' => self::YANDEX_OT_MIN,
            'max' => self::YANDEX_OT_MAX,
            'enableClientValidation' => false,
        ]);

        if (!$validator->validate($text, $error)) {
            throw new InvalidParamException($error);
        }

        $text = urlencode(htmlspecialchars($text));
        $text = "<original-text><content>{$text}</content></original-text>";

        $response = $this->apiClient->rawApi("hosts/$yandexSiteID/original-texts/", "POST", $text);

        $success = ArrayHelper::keyExists('id', $response) && ArrayHelper::keyExists('link', $response);
        if ($success) {
            $sent++;
            $cache->set($cacheKey, $sent, 60 * 60 * 24);
        }
        return $success;
    }
public function addOriginalText($text, $yandexSiteID)
    {
        /** @var Cache $cache */
        $cache = \Yii::$app->get($this->cacheComponent);
        $cacheKey = "Yandex_OT_sent:" . $this->clientID . "_" . $this->clientSecret;

        $sent = $cache->get($cacheKey);
        if ($sent === false) {
            $sent = 0;
        }

        if ($sent >= self::YANDEX_OT_DAILY_LIMIT) {
            throw new InvalidParamException("Daily limit exceeded!");
        }

        $validator = new StringValidator([
            'min' => self::YANDEX_OT_MIN,
            'max' => self::YANDEX_OT_MAX,
            'enableClientValidation' => false,
        ]);

        if (!$validator->validate($text, $error)) {
            throw new InvalidParamException($error);
        }

        $text = urlencode(htmlspecialchars($text));
        $text = "<original-text><content>{$text}</content></original-text>";

        $response = $this->apiClient->rawApi("hosts/$yandexSiteID/original-texts/", "POST", $text);

        $success = ArrayHelper::keyExists('id', $response) && ArrayHelper::keyExists('link', $response);
        if ($success) {
            $sent++;
            $cache->set($cacheKey, $sent, 60 * 60 * 24);
        }
        return $success;
    }
public function addOriginalText ( $ text , $ yandexSiteID ) { /** @var Cache $cache */ $ cache = \ Yii :: $ app -> get ( $ this -> cacheComponent ) ; $ cacheKey = "Yandex_OT_sent:" . $ this -> clientID . "_" . $ this -> clientSecret ; $ sent = $ cache -> get ( $ cacheKey ) ; if ( $ sent === false ) { $ sent = 0 ; } if ( $ sent >= self :: YANDEX_OT_DAILY_LIMIT ) { throw new InvalidParamException ( "Daily limit exceeded!" ) ; } $ validator = new StringValidator ( [ 'min' => self :: YANDEX_OT_MIN , 'max' => self :: YANDEX_OT_MAX , 'enableClientValidation' => false , ] ) ; if ( ! $ validator -> validate ( $ text , $ error ) ) { throw new InvalidParamException ( $ error ) ; } $ text = urlencode ( htmlspecialchars ( $ text ) ) ; $ text = "<original-text><content>{$text}</content></original-text>" ; $ response = $ this -> apiClient -> rawApi ( "hosts/$yandexSiteID/original-texts/" , "POST" , $ text ) ; $ success = ArrayHelper :: keyExists ( 'id' , $ response ) && ArrayHelper :: keyExists ( 'link' , $ response ) ; if ( $ success ) { $ sent ++ ; $ cache -> set ( $ cacheKey , $ sent , 60 * 60 * 24 ) ; } return $ success ; }
Add Original Text
@param string $text
@param int $yandexSiteID
@throws InvalidParamException
@return string|bool
Add Original Text