public function __construct($hostname = '', $apiKeyOrStorageProvider = null, $port = 443)
{
if (strpos($hostname, ".") === false) {
$hostname = $hostname . '.infusionsoft.com';
}
$this->hostname = $hostname;
if (is_a($apiKeyOrStorageProvider, 'Infusionsoft_TokenStorageProvider')) {
/** @var Infusionsoft_TokenStorageProvider $storageProvider */
$this->tokenStorageProvider = $apiKeyOrStorageProvider;
} elseif ($apiKeyOrStorageProvider == null) {
$this->tokenStorageProvider = Infusionsoft_AppPool::getDefaultStorageProvider();
} else {
$this->apiKey = $apiKeyOrStorageProvider;
}
if ($this->tokenStorageProvider != null) {
$this->usingOAuth = true;
$tokens = $this->tokenStorageProvider->getTokens($this->hostname);
$this->accessToken = $tokens['accessToken'];
$this->refreshToken = $tokens['refreshToken'];
$this->tokenExpiresAt = $tokens['expiresAt'];
}
$this->port = $port;
if ($this->usingOAuth) {
$this->client = new xmlrpc_client('/crm/xmlrpc/v1', 'api.infusionsoft.com', 443);
} else {
$this->client = new xmlrpc_client('/api/xmlrpc', $this->getHostname(), $this->port);
}
$this->client->setSSLVerifyPeer(true);
$this->client->setCaCertificate(dirname(__FILE__) . '/infusionsoft.pem');
$this->client->request_charset_encoding = "UTF-8";
if ($this->usingOAuth == true) {
$this->client->extraUrlParams = array('access_token' => $this->accessToken);
}
}