protected function RateBotDetector::checkBotscout in Rate 8
Check if botscout thinks the IP is a bot.
Return value
bool True if botscout returns a positive; false otherwise.
1 call to RateBotDetector::checkBotscout()
- RateBotDetector::checkIsBot in src/
RateBotDetector.php  - Check if the current user is blocked.
 
File
- src/
RateBotDetector.php, line 154  
Class
- RateBotDetector
 - The rate.bot_detector service.
 
Namespace
Drupal\rateCode
protected function checkBotscout() {
  $key = $this->config
    ->get('botscout_key');
  if ($key) {
    // @Todo: move to config.
    $uri = "http://botscout.com/test/?ip={$this->ip}&key={$key}";
    try {
      $response = $this->httpClient
        ->get($uri, [
        'headers' => [
          'Accept' => 'text/plain',
        ],
      ]);
      $data = (string) $response
        ->getBody();
      $status_code = $response
        ->getStatusCode();
      if (!empty($data) && $status_code == 200) {
        if (substr($data, 0, 1) === 'Y') {
          return TRUE;
        }
      }
    } catch (RequestException $e) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('An error occurred contacting BotScout.'), 'warning');
      watchdog_exception('rate', $e);
    }
  }
  return FALSE;
}