<commit_before><?php

namespace Contactzilla\Api;

use Guzzle;

class Client
{
    const ERROR_MESSAGE = 'An unexpected error occurred communicating with Contactzilla. If the problem persists, please contact support.';

    protected $debug;

    public function __construct(
        $accessToken,
        $addressBook = false,
        $appInstallId = false,
        $apiHost = false,
        $debug = false
    ) {
        $this->client = new Guzzle\Http\Client('https://' . ($apiHost ?: API_HOST));

        $this->setAccessToken($accessToken);
        $this->setAddressBook($addressBook ?: (isset($_GET['appContextAddressBook']) ? $_GET['appContextAddressBook'] : null));
        $this->setAppInstallId($appInstallId ?: (isset($_GET['appContextInstallId']) ? $_GET['appContextInstallId'] : null));
        $this->setDebug($debug);

        $this->client->getEventDispatcher()->addListener('request.before_send', array($this, 'beforeRequestFixLegacyEndpoints'));
    }

    public function get($endpoint, $params = array())
    {
        try {
            $response = $this->client->get($endpoint, array(), array('query' => $params))->send();
        } catch(Guzzle\Http\Exception\ClientErrorResponseException $e) {
            $message = $this->getDebug() ? 'API responded with: ' . $e->getResponse()->getBody() : self::ERROR_MESSAGE;

            throw new Guzzle\Http\Exception\ClientErrorResponseException($message);
        }

        return $response->json();
    }

    public function post($endpoint, $params = array())
    {
        try {
            $response = $this->client->post($endpoint, array(), $params)->send();
        } catch(Guzzle\Http\Exception\ClientErrorResponseException $e) {
            $message = $this->getDebug() ? 'API responded with: ' . $e->getResponse()->getBody() : self::ERROR_MESSAGE;

            throw new Guzzle\Http\Exception\ClientErrorResponseException($message);
        }

        return $response->json();
    }

    public function call($endpoint, $params = array(), $method)
    {
        return $this->$method($endpoint, $params);
    }

    public function getContacts($params = array())
    {
        return $this->get('/address_books/' . $this->addressBook . '/contacts', $params);
    }

    public function getDeletedContacts($params = array())
    {
        return $this->get('/address_books/' . $this->addressBook . '/contacts/deleted', $params);
    }

    /**
     * Gets user data for this application
     */
    public function getUserData()
    {
        return $this->get($this->getUserDataUrl());
    }

    /**
     * Saves user data against the application
     */
    public function saveUserDataKeyValue($key, $value)
    {
        return $this->post($this->getUserDataUrl(), array(
            'body' => json_encode(array(
                array('key' => $key, 'value' => $value)
            ))
        ));
    }
<commit_msg>Removed deletedContacts method, this is now rolled into status param on getContacts.<commit_after><?php

namespace Contactzilla\Api;

use Guzzle;

class Client
{
    const ERROR_MESSAGE = 'An unexpected error occurred communicating with Contactzilla. If the problem persists, please contact support.';

    protected $debug;

    public function __construct(
        $accessToken,
        $addressBook = false,
        $appInstallId = false,
        $apiHost = false,
        $debug = false
    ) {
        $this->client = new Guzzle\Http\Client('https://' . ($apiHost ?: API_HOST));

        $this->setAccessToken($accessToken);
        $this->setAddressBook($addressBook ?: (isset($_GET['appContextAddressBook']) ? $_GET['appContextAddressBook'] : null));
        $this->setAppInstallId($appInstallId ?: (isset($_GET['appContextInstallId']) ? $_GET['appContextInstallId'] : null));
        $this->setDebug($debug);

        $this->client->getEventDispatcher()->addListener('request.before_send', array($this, 'beforeRequestFixLegacyEndpoints'));
    }

    public function get($endpoint, $params = array())
    {
        try {
            $response = $this->client->get($endpoint, array(), array('query' => $params))->send();
        } catch(Guzzle\Http\Exception\ClientErrorResponseException $e) {
            $message = $this->getDebug() ? 'API responded with: ' . $e->getResponse()->getBody() : self::ERROR_MESSAGE;

            throw new Guzzle\Http\Exception\ClientErrorResponseException($message);
        }

        return $response->json();
    }

    public function post($endpoint, $params = array())
    {
        try {
            $response = $this->client->post($endpoint, array(), $params)->send();
        } catch(Guzzle\Http\Exception\ClientErrorResponseException $e) {
            $message = $this->getDebug() ? 'API responded with: ' . $e->getResponse()->getBody() : self::ERROR_MESSAGE;

            throw new Guzzle\Http\Exception\ClientErrorResponseException($message);
        }

        return $response->json();
    }

    public function call($endpoint, $params = array(), $method)
    {
        return $this->$method($endpoint, $params);
    }

    public function getContacts($params = array())
    {
        return $this->get('/address_books/' . $this->addressBook . '/contacts', $params);
    }

    /**
     * Gets user data for this application
     */
    public function getUserData()
    {
        return $this->get($this->getUserDataUrl());
    }

    /**
     * Saves user data against the application
     */
    public function saveUserDataKeyValue($key, $value)
    {
        return $this->post($this->getUserDataUrl(), array(
            'body' => json_encode(array(
                array('key' => $key, 'value' => $value)
            ))
        ));
    }

{'fraction_non_alphanumeric': 0.15367053038285916, 'fraction_numerical': 0.0, 'mean_word_length': 2.796666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 2, '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': '102739', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1556, 'n_words': 324}