<commit_before><?php

namespace Maidmaid\Zoho;

use Maidmaid\Zoho\Serializer\Encoder\ZohoEncoder;
use Maidmaid\Zoho\Serializer\Normalizer\ZohoNormalizer;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;

class Client
{
    protected $client;
    protected $authtoken;
    protected $serializer;
    protected $lastErrors;

    public function __construct($authtoken, ClientInterface $client = null, SerializerInterface $serializer = null)
    {
        $this->authtoken = $authtoken;
        $this->serializer = $serializer ?: new Serializer(array(new ZohoNormalizer()), array(new ZohoEncoder()));
        $this->client = $client ?: new GuzzleClient();
    }

    public function call($module, $method, $params = array(), $data = array())
    {
        $this->lastErrors = array();

        // Set basic options
        $options = array(
            'base_uri' => 'https://crm.zoho.com/crm/private/json/',
            'query' => array_merge(array(
                'authtoken' => $this->authtoken,
                'scope' => 'crmapi',
            ), $params),
        );

        // Set form params options (xmlData)
        if ($data) {
            $options['form_params'] = array(
                'xmlData' => $this->serializer->serialize($data, 'zoho', array('module' => $module)),
            );
        }

        $response = $this->client->post($uri = sprintf('%s/%s', $module, $method), $options);<commit_msg>Allow optional uri to support https://crm.zoho.eu clients (#5)<commit_after><?php

namespace Maidmaid\Zoho;

use Maidmaid\Zoho\Serializer\Encoder\ZohoEncoder;
use Maidmaid\Zoho\Serializer\Normalizer\ZohoNormalizer;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;

class Client
{
    protected $client;
    protected $authtoken;
    protected $uri;
    protected $serializer;
    protected $lastErrors;

    public function __construct($authtoken, ClientInterface $client = null, SerializerInterface $serializer = null, $uri = 'https://crm.zoho.com')
    {
        $this->authtoken = $authtoken;
        $this->serializer = $serializer ?: new Serializer(array(new ZohoNormalizer()), array(new ZohoEncoder()));
        $this->client = $client ?: new GuzzleClient();
        $this->uri = $uri;
    }

    public function call($module, $method, $params = array(), $data = array())
    {
        $this->lastErrors = array();

        // Set basic options
        $options = array(
            'base_uri' => $this->uri.'/crm/private/json/', //https://crm.zoho.com or https://crm.zoho.eu
            'query' => array_merge(array(
                'authtoken' => $this->authtoken,
                'scope' => 'crmapi',
            ), $params),
        );

        // Set form params options (xmlData)
        if ($data) {
            $options['form_params'] = array(
                'xmlData' => $this->serializer->serialize($data, 'zoho', array('module' => $module)),
            );
        }

        $response = $this->client->post($uri = sprintf('%s/%s', $module, $method), $options);
{'fraction_non_alphanumeric': 0.1492583436341162, 'fraction_numerical': 0.00030902348578491963, 'mean_word_length': 2.7992957746478875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2076181', 'n_tokens_mistral': 1005, 'n_tokens_neox': 957, 'n_words': 201}