<commit_before><?php
/**
 * Twitter API server proxy class, simulates a Twitter API based HTTP server
 *
 * @author  <NAME> <<EMAIL>>
 * @license MIT License
 */
class TwitterApiServer
{
  protected
    $baseUrl  = 'http://twitter.com',
    $options  = array(),
    $password = <PASSWORD>,
    $username = null;
  
  public function __construct($baseUrl = null, array $options = array())
  {
    if (!function_exists('curl_init'))
    {
      throw new RuntimeException('Curl PHP support must be enabled in order to use the TwitterApiServer class. Check the curl php manual there: http://us.php.net/curl');
    }
    
    if (!is_null($baseUrl))
    {
      $this->baseUrl = $baseUrl;
    }
    
    $this->setOptions($options);
  }
  
  /**
   * Sends a request to the server, receive a response
   *
   * @param  string   $apiPath       Request API path
   * @param  array    $parameters    Parameters
   * @param  string   $httpMethod    HTTP method to use
   * @param  Boolean  $authenticate  Authenticate user?
   *
   * @return string  HTTP response
   */
  public function request($apiPath, $parameters = array(), $httpMethod = 'GET', $authenticate = true)
  {
    // FIXME: hack to detect search requests, unsupported with XML currently and having a different subdomain
    if ('search.xml' === $apiPath)
    {
      $url = 'http://search.twitter.com/search.json';
    }
    else
    {
      $url = sprintf('%s/%s', $this->baseUrl, $apiPath);
    }
    
    $queryString = utf8_encode(http_build_query($parameters));

    $options[CURLOPT_URL] = $url . ('GET' === $httpMethod ? '?' . $queryString : '');
    $options[CURLOPT_PORT] = $this->getOption('httpPort', 80);
    $options[CURLOPT_USERAGENT] = $this->getOption('userAgent');
    $options[CURLOPT_FOLLOWLOCATION] = true;
    $options[CURLOPT_RETURNTRANSFER] = true;
    $options[CURLOPT_TIMEOUT] = $this->getOption('timeOut');

    if ($authenticate)
    {
      $options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
      $options[CURLOPT_USERPWD] = sprintf('%s:%s', $this->getUsername(), $this->getPassword());
    }

    if (!empty($parameters) && 'POST' === $httpMethod)
    {<commit_msg>Fix 401 statuses when authenticate with empty username<commit_after><?php
/**
 * Twitter API server proxy class, simulates a Twitter API based HTTP server
 *
 * @author  <NAME> <<EMAIL>>
 * @license MIT License
 */
class TwitterApiServer
{
  protected
    $baseUrl  = 'http://twitter.com',
    $options  = array(),
    $password = <PASSWORD>,
    $username = null;
  
  public function __construct($baseUrl = null, array $options = array())
  {
    if (!function_exists('curl_init'))
    {
      throw new RuntimeException('Curl PHP support must be enabled in order to use the TwitterApiServer class. Check the curl php manual there: http://us.php.net/curl');
    }
    
    if (!is_null($baseUrl))
    {
      $this->baseUrl = $baseUrl;
    }
    
    $this->setOptions($options);
  }
  
  /**
   * Sends a request to the server, receive a response
   *
   * @param  string   $apiPath       Request API path
   * @param  array    $parameters    Parameters
   * @param  string   $httpMethod    HTTP method to use
   * @param  Boolean  $authenticate  Authenticate user?
   *
   * @return string  HTTP response
   */
  public function request($apiPath, $parameters = array(), $httpMethod = 'GET', $authenticate = true)
  {
    // FIXME: hack to detect search requests, unsupported with XML currently and having a different subdomain
    if ('search.xml' === $apiPath)
    {
      $url = 'http://search.twitter.com/search.json';
    }
    else
    {
      $url = sprintf('%s/%s', $this->baseUrl, $apiPath);
    }
    
    $queryString = utf8_encode(http_build_query($parameters));

    $options[CURLOPT_URL] = $url . ('GET' === $httpMethod ? '?' . $queryString : '');
    $options[CURLOPT_PORT] = $this->getOption('httpPort', 80);
    $options[CURLOPT_USERAGENT] = $this->getOption('userAgent');
    $options[CURLOPT_FOLLOWLOCATION] = true;
    $options[CURLOPT_RETURNTRANSFER] = true;
    $options[CURLOPT_TIMEOUT] = $this->getOption('timeOut');

    if ($authenticate && $this->getUsername() && $this->getPassword())
    {
      $options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
      $options[CURLOPT_USERPWD] = sprintf('%s:%s', $this->getUsername(), $this->getPassword());
    }

    if (!empty($parameters) && 'POST' === $httpMethod)
    {
{'fraction_non_alphanumeric': 0.1464750171115674, 'fraction_numerical': 0.002053388090349076, 'mean_word_length': 3.1992337164750957, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '3842572', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1398, 'n_words': 339}