/** * Singleton instance * * @return FreshBooks_HttpClient */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * processes response xml */ protected function _processResponse(&$XMLObject) { if ($XMLObject === false) { $this->lastError = FreshBooks_HttpClient::getInstance()->getLastError(); return false; } $result = (string) $XMLObject["status"] == "ok"; if (!$result) { $this->lastError = (string) $XMLObject->error; } return $result; }
<?php /** * Copy this file as init.php and update url and token */ define("LIB_PATH", realpath(dirname(__FILE__) . '/../../library')); include_once LIB_PATH . '/FreshBooks/HttpClient.php'; //you API url and token obtained from freshbooks.com $url = ""; $token = ""; //init singleton FreshBooks_HttpClient FreshBooks_HttpClient::init($url, $token);
private static function init_api() { require_once GFFreshBooks::get_base_path() . '/api/Client.php'; require_once GFFreshBooks::get_base_path() . '/api/Invoice.php'; require_once GFFreshBooks::get_base_path() . '/api/Estimate.php'; require_once GFFreshBooks::get_base_path() . '/api/Item.php'; $url = "https://" . get_option("gf_freshbooks_site_name") . ".freshbooks.com/api/2.1/xml-in"; $authtoken = get_option("gf_freshbooks_auth_token"); self::log_debug("Initializing API - url: {$url} - token: {$authtoken}"); FreshBooks_HttpClient::init($url, $authtoken); self::log_debug("API Initialized."); }
private function init_api() { require_once GFFreshBooks::get_base_path() . '/api/Client.php'; require_once GFFreshBooks::get_base_path() . '/api/Invoice.php'; require_once GFFreshBooks::get_base_path() . '/api/Estimate.php'; require_once GFFreshBooks::get_base_path() . '/api/Item.php'; require_once GFFreshBooks::get_base_path() . '/api/Payment.php'; $settings = $this->get_plugin_settings(); $url = 'https://' . $settings['siteName'] . '.freshbooks.com/api/2.1/xml-in'; $authtoken = $settings['authToken']; $this->log_debug(__METHOD__ . "(): Initializing API - url: {$url} - token: {$authtoken}"); FreshBooks_HttpClient::init($url, $authtoken); $this->log_debug(__METHOD__ . '(): API Initialized.'); }