Skip to content

Commit

Permalink
Merge pull request #383 from developer-devPHP/issue-276
Browse files Browse the repository at this point in the history
Added new method getHeaders(), which will allow to get all response headers after each API call
  • Loading branch information
Aaron Suarez committed Nov 27, 2018
2 parents 72afabd + 6164e4e commit be69617
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit be69617

Please sign in to comment.