<commit_before><?php

require_once "includes/config.php";

class IPS_Api {

  public function __construct() {

    $this->connect();

  }


  private function connect() {
    $login = $this->_call("GET", "/authenticate");
    return $login;
  }


  public function Clients_GetAll() {

    $clients = $this->_call("GET", "/clients");
    return $clients;

  }


  public function Domains_GetAll() {

    $domains = $this->_call("GET", "/domains");
    return $domains;

  }


  public function Domains_Autoresponders_GetAll($domainname) {

    if (!isset($domainname) or empty($domainname)) {
      return false;
    }
    else {
      $autoresponders = $this->_call("GET", "/domains/".$domainname."/mail_autoresponders/");
      return $autoresponders;
    }

  }


  private function _call($method, $url, $data = false) {

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => API_URL.API_VERSION.$url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => array(
          "authorization: Basic ".base64_encode(API_USER.":".API_PASS).""
        ),
      ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      return false;
    } else {
      return json_decode($response, true);
    }

  }


}<commit_msg>Use token instead of basic auth every request<commit_after><?php

require_once "includes/config.php";

class IPS_Api {

  var $token = null;

  public function __construct() {

    $connect = $this->connect();
    if ($connect !== true)
      die ("Login failed");

  }


  private function connect() {
    $login = $this->_call("GET", "/authenticate");

    if (isset($login['data']['token'])) {
      $this->token = $login['data']['token'];
      return true;
    }
    else
      return false;
  }


  public function Clients_GetAll() {

    $clients = $this->_call("GET", "/clients");
    return $clients;

  }


  public function Domains_GetAll() {

    $domains = $this->_call("GET", "/domains");
    return $domains;

  }


  public function Domains_Autoresponders_GetAll($domainname) {

    if (!isset($domainname) or empty($domainname)) {
      return false;
    }
    else {
      $autoresponders = $this->_call("GET", "/domains/".$domainname."/mail_autoresponders/");
      return $autoresponders;
    }

  }


  private function _call($method, $url, $data = false) {

    if ($this->token === null) {
      $login = "authorization: Basic ".base64_encode(API_USER.":".API_PASS)."\n";
    }
    else {
      $login = "authorization: ".$this->token."\n";
    }

    echo $login;

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => API_URL.API_VERSION.$url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => array(
          $login
        ),
      ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      return false;
    } else {
      return json_decode($response, true);
    }

  }


}
{'fraction_non_alphanumeric': 0.1530791788856305, 'fraction_numerical': 0.00469208211143695, 'mean_word_length': 2.6915584415584415, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 32, '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': '887909', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1101, 'n_words': 213}