Skip to content

Commit

Permalink
Throw an Exception, add a proxy Server option.
Browse files Browse the repository at this point in the history
  • Loading branch information
najamhaq committed Sep 26, 2018
1 parent f793832 commit 83e5dcb
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ abstract class AmazonCore{
protected $env;
protected $rawResponses = array();
protected $disableSslVerify = false;
protected $proxy;

/**
* AmazonCore constructor sets up key information used in all Amazon requests.
Expand Down Expand Up @@ -181,6 +182,14 @@ public function setMock($b = true,$files = null){
}
}
}

/**
* set Proxy server to be used for all Amazon calls.
* @param $proxy
*/
public function setProxy($proxy){
$this->proxy = $proxy;
}

/**
* Fetches the given mock file, or attempts to.
Expand Down Expand Up @@ -611,8 +620,17 @@ protected function genQuery(){
protected function sendRequest($url,$param){
$this->log("Making request to Amazon: ".$this->options['Action']);
$response = $this->fetchURL($url,$param);

while (isset($response['code']) && $response['code'] == '503' && $this->throttleStop==false){

if ( $response['ok']) {
$this->rawResponses[] = $response;
return $response;
}

if ($this->throttleStop) {
throw new Exception("Api Call Throttled.", $response);
}

while (isset($response['code']) && $response['code'] == '503'){
$this->sleep();
$response = $this->fetchURL($url,$param);
}
Expand Down Expand Up @@ -787,6 +805,9 @@ function fetchURL ($url, $param) {
curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch,CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_URL,$url);
if ($this->proxy){
curl_setopt($ch,CURLOPT_PROXY,$this->proxy);
}
if ($this->disableSslVerify) {
$this->log('Caution: Request being sent without SSL verification.', 'Warning');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Expand Down

0 comments on commit 83e5dcb

Please sign in to comment.