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

Added new method getHeaders(), which will allow to get all response headers after each API call #383

Merged
merged 3 commits into from
Nov 27, 2018
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
17 changes: 17 additions & 0 deletions Tests/Recurly/Base_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ public function testPassingClientToStub() {
$this->assertInstanceOf('Recurly_Stub', $invoice);
$this->assertEquals(getProtectedProperty($invoice, '_client'), $this->client);
}

public function testCheckIfResponseContainGetHeadersFunction() {
$this->client->addResponse('GET', 'accounts', 'accounts/index-200.xml');
$accounts = Recurly_Base::_get('accounts', $this->client);
$this->assertTrue(method_exists($accounts, 'getHeaders'),"Accounts Class does not have method getHeaders");
$this->assertInternalType('array',$accounts->getHeaders());

$this->client->addResponse('GET', 'subscriptions', 'subscriptions/index-200.xml');
$subscriptions = Recurly_Base::_get('subscriptions', $this->client);
$this->assertTrue(method_exists($subscriptions, 'getHeaders'),'Subscriptions Class does not have method getHeaders');
$this->assertInternalType('array',$subscriptions->getHeaders());

$this->client->addResponse('GET', 'abcdef1234567890', 'adjustments/show-200.xml');
$adjustment = Recurly_Base::_get('abcdef1234567890', $this->client);
$this->assertTrue(method_exists($adjustment, 'getHeaders'),'Adjustments Class does not have method getHeaders');
$this->assertInternalType('array',$adjustment->getHeaders());
}
}
17 changes: 17 additions & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ abstract class Recurly_Base
protected $_links;
protected $_values;
protected $_errors;
protected $_headers;

public function __construct($href = null, $client = null)
{
Expand Down Expand Up @@ -177,6 +178,21 @@ public function setHref($href) {
$this->_href = $href;
}


/**
* @param array $headers
*/
private function setHeaders($headers){
$this->_headers = $headers;
}

/**
* @return array|null
*/
public function getHeaders(){
return $this->_headers;
}

/** Refers to the `type` root xml attribute **/
public function getType() {
return $this->_type;
Expand Down Expand Up @@ -277,6 +293,7 @@ protected static function __parseResponseToNewObject($response, $uri, $client) {
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $obj);
if ($obj instanceof self) {
$obj->_afterParseResponse($response, $uri);
$obj->setHeaders($response->headers);
}
return $obj;
}
Expand Down