Skip to content

Commit

Permalink
Merge pull request #4 from stevenwadejr/remove-static-constructor
Browse files Browse the repository at this point in the history
Remove Static Constructor
  • Loading branch information
rtconner authored Nov 24, 2016
2 parents 07201be + 4320458 commit fbe2e59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 2 additions & 17 deletions src/Freshbooks/FreshBooksApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.'
);
}

Expand Down
12 changes: 7 additions & 5 deletions src/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Setup the login credentials
$domain = '';
$token = '';
FreshBooksApi::init($domain, $token);

/**********************************************
* 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'
));
Expand All @@ -29,7 +29,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
));
Expand All @@ -47,7 +48,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,
Expand Down Expand Up @@ -82,4 +84,4 @@
echo $fb->getError();
print_r($fb->getResponse());

}
}

0 comments on commit fbe2e59

Please sign in to comment.