Skip to content

All responses now stored and all can be retrieved #24

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

Merged
merged 1 commit into from
Apr 28, 2014
Merged
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
41 changes: 34 additions & 7 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ abstract class AmazonCore{
protected $mockIndex = 0;
protected $logpath;
protected $env;
protected $lastResponse;
protected $rawResponses = array();

/**
* AmazonCore constructor sets up key information used in all Amazon requests.
Expand Down Expand Up @@ -590,17 +590,44 @@ protected function sendRequest($url,$param){
$response = $this->fetchURL($url,$param);
}

$this->lastResponse=$response;
$this->rawResponses[]=$response;
return $response;
}

/**
* Gives the last response code received from Amazon.
* @return int|boolean HTTP reponse code (200, 404, etc) or <b>FALSE</b> if not set yet
* Gives the latest response data received from Amazon.
* Response arrays contain the following keys:
* <ul>
* <li><b>head</b> - The raw HTTP head, including the response code and content length</li>
* <li><b>body</b> - The raw HTTP body, which will almost always be in XML format</li>
* <li><b>code</b> - The HTTP response code extracted from the head for convenience</li>
* <li><b>answer</b> - The HTTP response message extracted from the head for convenience</li>
* <li><b>ok</b> - Contains a <b>1</b> if the response was normal, or <b>0</b> if there was a problem</li>
* <li><b>headarray</b> - An associative array of the head data, for convenience</li>
* </ul>
* @param int $i [optional] <p>If set, retrieves the specific response instead of the last one.
* If the index for the response is not used, <b>FALSE</b> will be returned.</p>
* @return array associative array of HTTP response or <b>FALSE</b> if not set yet
*/
public function getLastResponse($i=NULL) {
if (!isset($i)) {
$i=count($this->rawResponses)-1;
}
if ($i >= 0 && isset($this->rawResponses[$i])) {
return $this->rawResponses[$i];
} else {
return false;
}
}

/**
* Gives all response code received from Amazon.
* @return array list of associative arrays of HTTP response or <b>FALSE</b> if not set yet
* @see getLastResponse
*/
public function getLastResponse() {
if (isset($this->lastResponse)) {
return $this->lastResponse;
public function getRawResponses() {
if (!empty($this->rawResponses)) {
return $this->rawResponses;
} else {
return false;
}
Expand Down