-
Notifications
You must be signed in to change notification settings - Fork 93
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
Remove X-Records header #314
Conversation
Tests/Recurly/Pager_Test.php
Outdated
@@ -69,8 +69,6 @@ public function testFromHref() { | |||
$pager->_loadFrom($url); | |||
|
|||
$this->assertEquals($url, $pager->getHref()); | |||
$this->assertEquals(6, $pager->count(), 'Returns correct count'); | |||
$this->assertEquals(6, count($pager), 'Returns correct count'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still want to keep this interface and we should just update the tests accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should definitely come back.
lib/recurly/pager.php
Outdated
// the same time. | ||
$this->_loadFrom($this->_href); | ||
} | ||
public function count($client = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the count method should take a client. That should be included in the constructor when the pager is instantiated. We should only be injecting it into static methods.
lib/recurly/pager.php
Outdated
@@ -45,7 +48,7 @@ public function rewind() { | |||
public function current() | |||
{ | |||
// Work around pre-PHP 5.5 issue that prevents `empty($this->count())`: | |||
if ($this->count() == 0) { | |||
if (count($this->_objects) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like if empty($this->_objects)
would be shorter. And I think then we can also ditch the comment above.
@@ -8,7 +8,7 @@ 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(); | |||
$accounts = Recurly_AccountList::get(null, $this->client)->get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to get()
because the mock client is expecting a GET
.
@@ -9,6 +9,5 @@ public function testGetMeasuredUnits() { | |||
$measured_units = Recurly_MeasuredUnitList::get(null, $this->client); | |||
|
|||
$this->assertInstanceOf('Recurly_MeasuredUnitList', $measured_units); | |||
$this->assertEquals(2, $measured_units->count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it might be okay to put some of these back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'd like to keep them if we can. At least for the embedded/nested ones that don't require a separate request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually i don't think we'll want to check the count, we should just check the href like we do on the other pager tests.
Tests/Recurly/Pager_Test.php
Outdated
@@ -69,8 +69,6 @@ public function testFromHref() { | |||
$pager->_loadFrom($url); | |||
|
|||
$this->assertEquals($url, $pager->getHref()); | |||
$this->assertEquals(6, $pager->count(), 'Returns correct count'); | |||
$this->assertEquals(6, count($pager), 'Returns correct count'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should definitely come back.
Tests/Recurly/Pager_Test.php
Outdated
@@ -81,8 +79,6 @@ public function testFromStub() { | |||
$this->assertInstanceOf('Mock_Pager', $pager); | |||
|
|||
$this->assertEquals($url, $pager->getHref()); | |||
$this->assertEquals($pager->count(), 6, 'Returns correct count'); | |||
$this->assertEquals(count($pager), 6, 'Returns correct count'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should also come back. we can stub in the correctly sized response.
Tests/Recurly/Pager_Test.php
Outdated
$this->client->addResponse('HEAD', '/mocks', 'pager/head-200.xml'); | ||
$pager = new Mock_Pager('/mocks', $this->client); | ||
$this->assertEquals($pager->count(), 42); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this one, it should be covered by the other three scenarios.
@@ -6,7 +6,6 @@ Content-Language: en-US | |||
X-RateLimit-Limit: 2000 | |||
X-RateLimit-Remaining: 1998 | |||
X-RateLimit-Reset: 1467912540 | |||
X-Records: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure X-Api-Version: 1.999
would still have the X-Records
header ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
lib/recurly/base.php
Outdated
@@ -30,6 +30,21 @@ public static function _get($uri, $client = null) | |||
} | |||
|
|||
/** | |||
* Send a HEAD request to the URI, validate the response and return the headers. | |||
* @param string Resource URI, if not fully qualified, the base URL will be appended |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick (I get that we're following the existing comment convention): should be "prepended" rather than "appended".
lib/recurly/pager.php
Outdated
* Number of records in this list. | ||
* Number of records in this list. This calls | ||
* the server with a HEAD request every time the function | ||
* is called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line wrapping seems odd here.
lib/recurly/pager.php
Outdated
@@ -45,8 +46,8 @@ public function rewind() { | |||
public function current() | |||
{ | |||
// Work around pre-PHP 5.5 issue that prevents `empty($this->count())`: | |||
if ($this->count() == 0) { | |||
return null; | |||
if (isset($this->_objects) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the == 0
doing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it could be !isset(
?
224e362
to
60f5a45
Compare
Tests/Recurly/Pager_Test.php
Outdated
$this->assertIteratesCorrectly($pager, 6); | ||
$this->assertEquals(2, $pager->count(), 'Returns correct count'); | ||
- $this->assertEquals(2, count($pager), 'Returns correct count'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ weird that this -
didn't cause any problems
661cda6
to
2c43a70
Compare
The X-Records header was removed on all GET index endpoints. You must now call HEAD explicitly to get the header and thus the count.
2c43a70
to
1dfaf59
Compare
Finally 🍰 |
This is for API v2.6.
The X-Records header was removed on all GET index endpoints. You must
now call HEAD explicitly to get the header and thus the count.
The consequence of this is that the
Recurly_Pager#count
method has changed. If the pager has a URL, it will send a HEAD request to get the count of all records. Otherwise it'll return the count of the cached _objects.