Skip to content

Commit 773c8dc

Browse files
authored
22: Refactors Xero Client based on guzzle enshittification (#23)
* 22: Bumps PHP version in GitHub workflow * 22: Refactors guzzle and removes deprecated oauth1 * 22: Refactors to use middleware and deprecate InvalidOptionsException
1 parent 96d44c1 commit 773c8dc

18 files changed

+303
-582
lines changed

.github/workflows/code-quality.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
continue-on-error: ${{ matrix.experimental }}
1515
strategy:
1616
matrix:
17-
php-versions: [8.0, 8.1, 8.2]
17+
php-versions: [8.1, 8.2, 8.3]
1818
experimental: [false]
1919
steps:
2020
- uses: actions/checkout@v2

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Thumbs.db
77
composer.lock
88
/coverage
99

10-
example.php
10+
example.php
11+
.phpunit.result.cache
12+
/.phpunit.cache/

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Ultimately it is up to the software that uses xeroclient to deal with [serializa
1515

1616
## Dependencies
1717

18-
* PHP 8.0 or greater
19-
* (Deprecated) [guzzlehttp/oauth-subscriber](https://packagist.org/packages/guzzlehttp/oauth-subscriber)
18+
* PHP 8.1 or greater
2019
* [league/oauth2-client](https://packagist.org/packages/league/oauth2-client)
2120
* [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle)
2221

@@ -38,15 +37,15 @@ $provider = new \Radcliffe\Xero\XeroProvider([
3837
$url = $provider->getAuthorizationUrl();
3938
```
4039

41-
### Create a guzzle client from an authorization code (see above)
40+
### Create with a guzzle client from an authorization code (see above)
4241

4342
```php
4443
$client = \Radcliffe\Xero\XeroClient::createFromToken('my consumer key', 'my consumer secret', $code, 'authorization_code', 'accounting');
4544
// Store the access token for the next 30 minutes or so if making additional requests.
4645
$tokens = $client->getRefreshedToken();
4746
```
4847

49-
### Create a guzzle client with an access token
48+
### Create with a guzzle client with an access token
5049

5150
```php
5251
$client = \Radcliffe\Xero\XeroClient::createFromToken(
@@ -61,7 +60,7 @@ $client = \Radcliffe\Xero\XeroClient::createFromToken(
6160
);
6261
```
6362

64-
### Create a guzzle client with a refresh token
63+
### Create with a guzzle client with a refresh token
6564

6665
Access tokens expire after 30 minutes so you can create a new client with a stored refresh token too.
6766

@@ -88,7 +87,7 @@ try {
8887
'query' => ['where' => 'Name.StartsWith("John")'],
8988
'headers' => ['Accept' => 'application/json'],
9089
];
91-
$response = $client->get('Accounts', $options);
90+
$response = $client->request('GET', 'Accounts', $options);
9291

9392
// Or use something like Symfony Serializer component.
9493
$accounts = json_decode($response->getBody()->getContents());
@@ -98,6 +97,12 @@ try {
9897

9998
```
10099

100+
### Error handling
101+
102+
If the configured client does not have a valid Xero API URL or if an auth_token is not provided, then XeroRequestException is thrown as part of the Guzzle request.
103+
104+
Previously XeroClient would throw an exception on instantiation, but this is no longer the case. If the initialize method is used directly, XeroClient will probably fail for other reasons.
105+
101106
### Use with a legacy OAuth1 application
102107

103108
Please see the 0.2 branch and versions < 0.3.0.

composer.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "mradcliffe/xeroclient",
33
"description": "Provides a Guzzle client for use with the Xero Accounting and Payroll APIs.",
44
"minimum-stability": "stable",
5-
"license": "MIT",
5+
"license": [
6+
"MIT",
7+
"GPL-2.0-or-later"
8+
],
69
"authors": [
710
{
811
"name": "Matthew Radcliffe",
@@ -21,10 +24,10 @@
2124
}
2225
},
2326
"require": {
24-
"php": "^8",
25-
"league/oauth2-client": "^2.4",
26-
"guzzlehttp/oauth-subscriber": "0.6.0",
27-
"ext-json": "*"
27+
"php": "^8.1",
28+
"league/oauth2-client": "^2",
29+
"ext-json": "*",
30+
"guzzlehttp/guzzle": "^7"
2831
},
2932
"require-dev": {
3033
"ext-openssl": "*",

src/Exception/InvalidOptionsException.php

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
namespace Radcliffe\Xero\Exception;
44

5+
/**
6+
* An exception to throw when the client has invalid options.
7+
*
8+
* @deprecated in 0.5.0 and removed in 0.6.0. Use a guzzle request exception
9+
* instead.
10+
* @see \Radcliffe\Xero\Exception\XeroRequestException
11+
*/
512
class InvalidOptionsException extends \Exception
613
{
714
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Radcliffe\Xero\Exception;
4+
5+
use GuzzleHttp\Exception\RequestException;
6+
7+
class XeroRequestException extends RequestException
8+
{
9+
}

0 commit comments

Comments
 (0)