-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Curl Response Wrapper, improved Response, Fixed Void Response.
- Loading branch information
Viaprestige
committed
Apr 8, 2020
1 parent
f1892bb
commit 9e28bff
Showing
25 changed files
with
198 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "jakiboy/apaapi", | ||
"version" : "1.0.3", | ||
"version" : "1.0.4", | ||
"type": "library", | ||
"description": "Amazon Product Advertising API v5", | ||
"keywords": ["php","amazon","product","api","apaapi","paapi5","jakiboy"], | ||
|
@@ -11,6 +11,11 @@ | |
"name": "Jihad Sinnaour", | ||
"email": "[email protected]", | ||
"role": "Founder" | ||
}, | ||
{ | ||
"name": "Softgine", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
*/ | ||
|
||
namespace Apaapi\lib; | ||
|
||
use Apaapi\interfaces\RequestInterface; | ||
|
||
/** | ||
* Basic Apaapi Curl Wrapper Class | ||
*/ | ||
class RequestClient | ||
{ | ||
/** | ||
* @access public | ||
* @var mixed $body Amazon API Response | ||
* @var mixed $error Response Error | ||
*/ | ||
public $body = false; | ||
public $error = false; | ||
|
||
/** | ||
* @access private | ||
* @var RequestInterface $request | ||
* @var Curl $handler | ||
* @var boolean $forceSSL | ||
*/ | ||
private $request; | ||
private $handler; | ||
private $forceSSL = false; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param boolean $forceSSL | ||
* @param boolean $failOnError | ||
* @return void | ||
*/ | ||
public function __construct(RequestInterface $request, $forceSSL = false) | ||
{ | ||
$this->request = $request; | ||
$this->forceSSL = $forceSSL; | ||
$this->init(); | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return void | ||
*/ | ||
private function init() | ||
{ | ||
$this->handler = curl_init(); | ||
curl_setopt($this->handler, CURLOPT_URL, "https://{$this->request->endpoint}"); | ||
curl_setopt($this->handler, CURLOPT_POSTFIELDS, $this->request->params['http']['content']); | ||
curl_setopt($this->handler, CURLOPT_POST, true); | ||
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($this->handler, CURLOPT_SSL_VERIFYHOST, $this->forceSSL); | ||
curl_setopt($this->handler, CURLOPT_SSL_VERIFYPEER, $this->forceSSL); | ||
$this->setHeader(); | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return void | ||
*/ | ||
private function close() | ||
{ | ||
curl_close($this->handler); | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return void | ||
*/ | ||
private function setHeader() | ||
{ | ||
$header = explode("\n", $this->request->params['http']['header']); | ||
curl_setopt($this->handler, CURLOPT_HTTPHEADER, $header); | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return boolean | ||
*/ | ||
private function isValid() | ||
{ | ||
if ( !curl_errno($this->handler) ) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return int | ||
*/ | ||
private function getHttpCode() | ||
{ | ||
return curl_getinfo($this->handler)['http_code']; | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return string | ||
*/ | ||
private function getError() | ||
{ | ||
return curl_error($this->handler); | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return void | ||
*/ | ||
private function setHttpError() | ||
{ | ||
if ( $this->getHttpCode() == 400 ) { | ||
$this->error = 'The partner tag is not mapped to a valid associate store with your access key'; | ||
|
||
} elseif ( $this->getHttpCode() == 401 ) { | ||
$this->error = 'The Access Key ID or security token included in the request is invalid'; | ||
|
||
} elseif ( $this->getHttpCode() == 403 ) { | ||
$this->error = 'Your access key is not mapped to Primary of approved associate store'; | ||
|
||
} else { | ||
$this->error = 'Unestablished Server Connection'; | ||
} | ||
} | ||
|
||
/** | ||
* @param void | ||
* @return void | ||
*/ | ||
public function getBody() | ||
{ | ||
// Exec Curl | ||
$reponse = curl_exec($this->handler); | ||
// Validate curl response | ||
if ( $this->isValid() ) { | ||
// Get Amazon JSON response | ||
if ( $this->getHttpCode() == 200 ) { | ||
$this->body = $reponse; | ||
} else { | ||
// Set Amazon API errors | ||
$this->setHttpError(); | ||
} | ||
} else { | ||
// Get Curl errors | ||
$this->error = $this->getError(); | ||
} | ||
// End Curl | ||
$this->close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
@@ -13,44 +13,29 @@ | |
use Apaapi\interfaces\RequestInterface; | ||
|
||
/** | ||
* Basic Apaapi ResponseCurl Wrapper Class | ||
* @todo Use PSR-7 | ||
* Basic Apaapi Response Wrapper Class | ||
*/ | ||
class Response implements ResponseInterface | ||
{ | ||
/** | ||
* @access public | ||
* @var JSON|False $body, Amazon API Response | ||
* @var mixed $body Amazon API Response | ||
* @var mixed $error Response Error | ||
*/ | ||
public $body = false; | ||
public $body = false; | ||
public $error = false; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @return void | ||
*/ | ||
public function __construct(RequestInterface $request) | ||
{ | ||
$handler = curl_init(); | ||
$header = explode("\n", $request->params['http']['header']); | ||
|
||
curl_setopt($handler, CURLOPT_URL, "https://{$request->endpoint}"); | ||
curl_setopt($handler, CURLOPT_POSTFIELDS, ($request->params['http']['content'])); | ||
curl_setopt($handler, CURLOPT_HTTPHEADER, $header); | ||
curl_setopt($handler, CURLOPT_POST, true); | ||
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($handler, CURLOPT_SSL_VERIFYHOST, false); | ||
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false); | ||
|
||
$data = curl_exec($handler); | ||
|
||
if ($data) { | ||
if ($data !== false && strpos($data, 'Errors') === false) { | ||
$this->body = $data; | ||
} | ||
else if (strpos($data, 'Errors') !== true) { | ||
$data = json_decode($data); | ||
$this->error = $data->Errors[0]->Message; | ||
} | ||
$response = new RequestClient($request); | ||
$response->getBody(); | ||
if ($response->error) { | ||
$this->error = $response->error; | ||
} | ||
$this->body = $response->body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* @package Amazon Product Advertising API | ||
* @copyright Copyright (c) 2019 Jakiboy | ||
* @copyright (c) 2019 - 2020 Jakiboy | ||
* @author Jihad Sinnaour <[email protected]> | ||
* @link https://jakiboy.github.io/apaapi/ | ||
* @license MIT | ||
|
Oops, something went wrong.