From 51fdf40a14e10e218adb8bc7b8355c9030359588 Mon Sep 17 00:00:00 2001 From: Steven Wade Date: Wed, 23 Nov 2016 14:06:19 -0500 Subject: [PATCH 1/3] Remove old static constructor `FreshBooksApi::init()` as it not longer serves a purpose When the change was made to add a proper constructor that takes the domain and token as parameters, it made a breaking change in the code, that the method was no longer passed in to the constructor. The update also made the `init()` method and protected static properties `$_domain` and `$_token` obsolete as well. --- src/Freshbooks/FreshBooksApi.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Freshbooks/FreshBooksApi.php b/src/Freshbooks/FreshBooksApi.php index 32f886d..0a6b80e 100644 --- a/src/Freshbooks/FreshBooksApi.php +++ b/src/Freshbooks/FreshBooksApi.php @@ -18,18 +18,16 @@ class FreshBooksApi { /* * The domain you need when making a request */ - protected static $_domain = ''; protected $domain = ''; /* * The API token you need when making a request */ - protected static $_token = ''; protected $token = ''; /* * The API url we're hitting. {{ DOMAIN }} will get replaced with $domain - * when you set FreshBooksApi::init($domain, $token) + * when you set `new FreshBooksApi($domain, $token)` */ protected $_api_url = 'https://{{ DOMAIN }}.freshbooks.com/api/2.1/xml-in'; @@ -59,19 +57,6 @@ class FreshBooksApi { */ protected $_response = array(); - /* - * Initialize the and store the domain/token for making requests - * - * @param string $domain The subdomain like 'yoursite'.freshbooks.com - * @param string $token The token found in your account settings area - * @return null - */ - public static function init($domain, $token) - { - self::$_domain = $domain; - self::$_token = $token; - } - /** * Initialize the and store the domain/token for making requests as init * does instead of doing what setMethod does @@ -169,7 +154,7 @@ public function request() if(!$this->domain || !$this->token) { throw new FreshBooksApiException( - 'You need to call new FreshBooksApi($domain, $token) or FreshBooksApi::init($domain, $token) with your domain and token.' + 'You need to call new FreshBooksApi($domain, $token) with your domain and token.' ); } From 974d5eafb86e2e8869ca48f303b1156abc686c76 Mon Sep 17 00:00:00 2001 From: Steven Wade Date: Wed, 23 Nov 2016 14:08:02 -0500 Subject: [PATCH 2/3] Update sample.php and README to remove references to the removed `init()` method and added use of the `->method()` as well --- README.md | 12 ------------ src/sample.php | 11 +++++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 663f506..35dd78d 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,6 @@ PHP wrapper for the FreshBooks API. Simplifies FreshBooks API XML structure into The XML tag parameters you see on the freshbooks API page are the ones you pass to $fb->post() (as an array) -Statically : -```php -$domain = 'your-subdomain'; // https://your-subdomain.freshbooks.com/ -$token = '1234567890'; // your api token found in your account -Freshbooks\FreshBooksApi::init($domain, $token); -``` - -Or using _construct and object instance: - ```php $domain = 'your-subdomain'; // https://your-subdomain.freshbooks.com/ $token = '1234567890'; // your api token found in your account @@ -37,9 +28,6 @@ Example: list clients with an email of some@email.com ```php // Method names are the same as found on the freshbooks API -// Statically -$fb = new Freshbooks\FreshBooksApi('client.list'); -// Or $fb->setMethod('client.list'); // For complete list of arguments see FreshBooks docs at http://developers.freshbooks.com diff --git a/src/sample.php b/src/sample.php index fa6ec43..5ca4691 100644 --- a/src/sample.php +++ b/src/sample.php @@ -10,7 +10,8 @@ /********************************************** * Fetch all clients by a specific id **********************************************/ -$fb = new FreshBooksApi('client.list'); +$fb = new FreshBooksApi($domain, $token); +$fb->setMethod('client.list'); $fb->post(array( 'email' => 'some@email.com' )); @@ -29,7 +30,8 @@ /********************************************** * List invoices from a specific client **********************************************/ -$fb = new FreshBooksApi('invoice.list'); +$fb = new FreshBooksApi($domain, $token); +$fb->setMethod('invoice.list'); $fb->post(array( 'client_id' => 41 )); @@ -47,7 +49,8 @@ /********************************************** * Create a recurring profile with multiple line items **********************************************/ -$fb = new FreshBooksApi('recurring.create'); +$fb = new FreshBooksApi($domain, $token); +$fb->setMethod('recurring.create'); $fb->post(array( 'recurring' => array( 'client_id' => 41, @@ -82,4 +85,4 @@ echo $fb->getError(); print_r($fb->getResponse()); -} \ No newline at end of file +} From 4320458ff77ae115d0c969487e43fccdda1dc561 Mon Sep 17 00:00:00 2001 From: Steven Wade Date: Wed, 23 Nov 2016 14:09:03 -0500 Subject: [PATCH 3/3] Remove a leftover reference to the removed `init()` method from the sample.php file --- src/sample.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sample.php b/src/sample.php index 5ca4691..f5d0ecd 100644 --- a/src/sample.php +++ b/src/sample.php @@ -5,7 +5,6 @@ // Setup the login credentials $domain = ''; $token = ''; -FreshBooksApi::init($domain, $token); /********************************************** * Fetch all clients by a specific id