Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on API deprecation #250

Merged
merged 1 commit into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Added support for `original_transaction` to `Recurly_Transaction` [#238](https://github.com/recurly/recurly-client-php/pull/238)
* Added `Recurly_AccountBalance` [#239](https://github.com/recurly/recurly-client-php/pull/239)
* Print warnings when using a deprecated version of the API.

## Version 2.5.3 (July 5th, 2016)

Expand Down
7 changes: 7 additions & 0 deletions Tests/Recurly/Client_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
class Recurly_ClientTest extends Recurly_TestCase
{

public function testDeprecationError() {
$this->client->addResponse('GET', '/accounts', 'client/deprecated-200.xml');

// This should print an error but not raise.
$accounts = Recurly_AccountList::get(null, $this->client)->count();
}

public function testUnauthorizedError() {
$this->client->addResponse('GET', '/accounts/abcdef1234567890', 'client/unauthorized-401.xml');

Expand Down
21 changes: 21 additions & 0 deletions Tests/fixtures/client/deprecated-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HTTP/1.1 200 OK
X-Api-Version: 1.999
Recurly-Deprecated: true
Recurly-Sunset-Date: 2014-01-01T00:00:00+00:00
Content-Language: en-US
X-RateLimit-Limit: 2000
X-RateLimit-Remaining: 1998
X-RateLimit-Reset: 1467912540
X-Records: 3
Link: <https://api.recurly.com/v2/accounts?order=asc&per_page=1>; rel="start", <https://api.recurly.com/v2/accounts?cursor=-1963376195782139893&order=asc&per_page=1>; rel="prev"
ETag: "d41d8cd98f00b204e9800998ecf8427e"
Content-Type: application/xml; charset=utf-8
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 6a8c07775f9dac83402cea1a28752a55
X-Runtime: 0.048038
Connection: close
Transfer-Encoding: chunked

<?xml version="1.0" encoding="UTF-8"?>
<accounts type="array">
</accounts>
4 changes: 4 additions & 0 deletions lib/recurly/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function assertSuccessResponse($object)

public function assertValidResponse()
{
if (!empty($this->headers['Recurly-Deprecated'])) {
error_log("WARNING: API version {$this->headers['X-Api-Version']} is deprecated and will only be available until {$this->headers['Recurly-Sunset-Date']}. Please upgrade the Recurly PHP client.");
}

// Successful response code
if ($this->statusCode >= 200 && $this->statusCode < 400)
return;
Expand Down