<commit_before><?php

class CleverApiRequestor
{
  public $auth;

  public function __construct($auth=null)
  {
    $this->_auth = $auth;
  }

  public static function apiUrl($url='')
  {
    $apiBase = Clever::$apiBase;
    return "$apiBase$url";
  }

  public static function utf8($value)
  {
    if (is_string($value))
      return utf8_encode($value);
    else
      return $value;
  }

  private static function _encodeObjects($d)
  {
    if ($d instanceof CleverApiRequestor) {
      return $d->id;
    } else if ($d === true) {
      return 'true';
    } else if ($d === false) {
      return 'false';
    } else if (is_array($d)) {
      $res = array();
      foreach ($d as $k => $v)
        $res[$k] = self::_encodeObjects($v);
      return $res;
    } else {
      return $d;
    }
  }

  public static function encode($d)
  {
    if (isset($d['where']) && is_array($d['where']))
      $d['where'] = json_encode($d['where']);
    return http_build_query($d, null, '&');
  }

  public function request($meth, $url, $params=null)
  {
    if (!$params)
      $params = array();
    list($rbody, $rcode, $myAuth) = $this->_requestRaw($meth, $url, $params);
    $resp = $this->_interpretResponse($rbody, $rcode);
    return array($resp, $myAuth);
  }

  public function handleApiError($rbody, $rcode, $resp)
  {
    $error = $resp['error'];
    switch ($rcode) {
    case 400:
    case 404:
      throw new CleverInvalidRequestError(isset($error['message']) ? $error['message'] : null,
                                           isset($error['param']) ? $error['param'] : null,
                                           $rcode, $rbody, $resp);
    case 401:
      throw new CleverAuthenticationError(isset($error['message']) ? $error['message'] : null, $rcode, $rbody, $resp);
    case 402:
      throw new CleverInvalidRequest(isset($error['message']) ? $error['message'] : null,
                                 isset($error['param']) ? $error['param'] : null,
                                 isset($error['code']) ? $error['code'] : null,
                                 $rcode, $rbody, $resp);
    default:
      throw new CleverError(isset($error['message']) ? $error['message'] : null, $rcode, $rbody, $resp);
    }
  }

  private function _requestRaw($meth, $url, $params)
  {
    $myAuth = $this->_auth;
    if (!$myAuth)
      $myAuth = Clever::$auth;
    if (!$myAuth)
      throw new CleverAuthenticationError('No API key or token provided. (HINT: set your API key using "Clever::setApiKey(<API-KEY>)".');

    $absUrl = $this->apiUrl($url);<commit_msg>Remove spurious api error check.<commit_after><?php

class CleverApiRequestor
{
  public $auth;

  public function __construct($auth=null)
  {
    $this->_auth = $auth;
  }

  public static function apiUrl($url='')
  {
    $apiBase = Clever::$apiBase;
    return "$apiBase$url";
  }

  public static function utf8($value)
  {
    if (is_string($value))
      return utf8_encode($value);
    else
      return $value;
  }

  private static function _encodeObjects($d)
  {
    if ($d instanceof CleverApiRequestor) {
      return $d->id;
    } else if ($d === true) {
      return 'true';
    } else if ($d === false) {
      return 'false';
    } else if (is_array($d)) {
      $res = array();
      foreach ($d as $k => $v)
        $res[$k] = self::_encodeObjects($v);
      return $res;
    } else {
      return $d;
    }
  }

  public static function encode($d)
  {
    if (isset($d['where']) && is_array($d['where']))
      $d['where'] = json_encode($d['where']);
    return http_build_query($d, null, '&');
  }

  public function request($meth, $url, $params=null)
  {
    if (!$params)
      $params = array();
    list($rbody, $rcode, $myAuth) = $this->_requestRaw($meth, $url, $params);
    $resp = $this->_interpretResponse($rbody, $rcode);
    return array($resp, $myAuth);
  }

  public function handleApiError($rbody, $rcode, $resp)
  {
    $error = $resp['error'];
    switch ($rcode) {
    case 400:
    case 404:
      throw new CleverInvalidRequestError(isset($error['message']) ? $error['message'] : null,
                                           isset($error['param']) ? $error['param'] : null,
                                           $rcode, $rbody, $resp);
    case 401:
      throw new CleverAuthenticationError(isset($error['message']) ? $error['message'] : null, $rcode, $rbody, $resp);
    default:
      throw new CleverError(isset($error['message']) ? $error['message'] : null, $rcode, $rbody, $resp);
    }
  }

  private function _requestRaw($meth, $url, $params)
  {
    $myAuth = $this->_auth;
    if (!$myAuth)
      $myAuth = Clever::$auth;
    if (!$myAuth)
      throw new CleverAuthenticationError('No API key or token provided. (HINT: set your API key using "Clever::setApiKey(<API-KEY>)".');

    $absUrl = $this->apiUrl($url);
{'fraction_non_alphanumeric': 0.17368855844692277, 'fraction_numerical': 0.005163155720776538, 'mean_word_length': 2.6495855312735492, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5420088', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1557, 'n_words': 367}