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

Remove X-Records header #314

Merged
merged 1 commit into from
Jun 2, 2017
Merged

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented May 16, 2017

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.

$accounts = Recurly_AccountList::get();
// Calling count will make a HEAD request to the server on each call
print $accounts->count() . "\n"; // 1033
print $accounts->count() . "\n"; // 1033

@bhelx bhelx added the WIP label May 16, 2017
@@ -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');
Copy link

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

Copy link

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.

// the same time.
$this->_loadFrom($this->_href);
}
public function count($client = null) {
Copy link

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.

@@ -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) {
Copy link

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.

@bhelx bhelx removed the WIP label May 22, 2017
@@ -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();
Copy link
Contributor Author

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());
Copy link
Contributor Author

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?

Copy link

@drewish drewish May 22, 2017

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.

Copy link

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.

@@ -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');
Copy link

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.

@@ -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');
Copy link

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.

$this->client->addResponse('HEAD', '/mocks', 'pager/head-200.xml');
$pager = new Mock_Pager('/mocks', $this->client);
$this->assertEquals($pager->count(), 42);
}
Copy link

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
Copy link

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 ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@@ -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
Copy link

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".

* 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.
Copy link

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.

@@ -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) {
Copy link

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?

Copy link

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(?

$this->assertIteratesCorrectly($pager, 6);
$this->assertEquals(2, $pager->count(), 'Returns correct count');
- $this->assertEquals(2, count($pager), 'Returns correct count');
Copy link
Contributor Author

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

@drewish drewish force-pushed the remove_x_records_header branch 3 times, most recently from 661cda6 to 2c43a70 Compare June 2, 2017 19:16
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.
@drewish drewish merged commit 8ffa389 into api_version_2_6 Jun 2, 2017
@drewish drewish deleted the remove_x_records_header branch June 2, 2017 19:25
@bhelx
Copy link
Contributor Author

bhelx commented Jun 2, 2017

Finally 🍰

@bhelx bhelx mentioned this pull request Jun 2, 2017
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants