Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakiboy committed Mar 27, 2024
1 parent 33a9567 commit 55eb344
Show file tree
Hide file tree
Showing 66 changed files with 7,555 additions and 1,698 deletions.
86 changes: 51 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<img src="https://raw.githubusercontent.com/Jakiboy/apaapi/master/amazon.svg" width="100" alt="Amazon Product Advertising API PHP">

Amazon Product Advertising API V5.0 (**Without Amazon SDK**).
This repository contains a PHP Lightweight (155 Ko) Wrapper Library, Allows you accessing the [Amazon Product Advertising API V5.0](https://webservices.amazon.com/paapi5/documentation/index.html) from your PHP App, Quickly & easily!
This repository contains a PHP Lightweight (155 Ko) Wrapper Library,
Easily access the [Amazon Product Advertising API V5.0](https://webservices.amazon.com/paapi5/documentation/index.html) from your PHP app.

-- Become an Amazon Affiliate With PHP --

Expand All @@ -30,41 +31,56 @@ include('apaapi-master/src/Autoloader.php');

* **4** - You can now use the [Quickstart examples](#quickstart).

## 🔨 Upgrade :
## 💡 Upgrade :

**See changes before migrate**:

This version includes:

* Support for **disabled cURL** (*Used Stream*).
* Throws exception if **cURL** AND **Stream** are disabled.
* Error reporting (Including semantic errors with **status 200** & **HTTP Client Errors**), [More](https://webservices.amazon.com/paapi5/documentation/troubleshooting/processing-of-errors.html#processing-of-errors).
* HTTP Client helpers (*RequestClient::hasCurl() & RequestClient::hasStream()*).
* Response parsing (*object/array/serialized*).
* Throws exception if Locale (*Region/TLD*) is invalid, [More](https://webservices.amazon.fr/paapi5/documentation/locale-reference.html).
* Throws exception if Resource (*e.g. Images.Primary.Large*) is invalid, [More](https://webservices.amazon.fr/paapi5/documentation/resources.html).
* Basic built-in **Caching System**.
* **Request Builder** (Easier way to fetch data).
* **Response Normalizer** (Normalize response items).
* **Search Filters** (Using builder).
* **Geotargeting** (Automatically redirect links based on the visitor's region).
* **Rating** (Lagacy).
* **Keyword Converter** (ASIN, ISBN, EAN, Node, Root).

And had many improvements:

* Uses default [Ressources](https://webservices.amazon.fr/paapi5/documentation/resources.html) for each [Operation](https://webservices.amazon.fr/paapi5/documentation/operations.html).
* Clean ecosystem.
* [Extendable HTTP Client](#advanced-custom-http-request-client).
[Full Changelog](#).


## ⚡ Getting Started:

### Variables (Basics):

* "{Your-partner-tag}" : From your Amazon Associates (*your locale*), [More](https://webservices.amazon.com/paapi5/documentation/troubleshooting/sign-up-as-an-associate.html).
* "{Your-secrect-key}" : From your Amazon Associates (*your locale*), [More](https://affiliate-program.amazon.com/help/node/topic/GTPNVFFUV2GQ8AZV).
* "{Your-key-id}" : From your Amazon Associates (*your locale*), [More](https://affiliate-program.amazon.com/help/node/topic/GTPNVFFUV2GQ8AZV).
* "{Your-keywords}" : What you are looking for (*Products*), [More](https://webservices.amazon.com/paapi5/documentation/search-items.html).
* "{Your-region}" : **TLD** of the target to which you are sending requests (*com/fr/com.be/de*), [Get TLD](https://webservices.amazon.com/paapi5/documentation/common-request-parameters.html#host-and-region).
* "{ASIN}" : Amazon Standard Identification Number (*your locale*), [More](https://webservices.amazon.com/paapi5/documentation/get-items.html#ItemLookup-rp).
* "_TAG_" : From your Amazon Associates (*your locale*), [More](https://webservices.amazon.com/paapi5/documentation/troubleshooting/sign-up-as-an-associate.html).
* "_SECRET_" : From your Amazon Associates (*your locale*), [More](https://affiliate-program.amazon.com/help/node/topic/GTPNVFFUV2GQ8AZV).
* "_KEY_" : From your Amazon Associates (*your locale*), [More](https://affiliate-program.amazon.com/help/node/topic/GTPNVFFUV2GQ8AZV).
* "_KEYWORDS_" : What you are looking for (*Products*), [More](https://webservices.amazon.com/paapi5/documentation/search-items.html).
* "_REGION_" : **TLD** of the target to which you are sending requests (*com/fr/com.be/de*), [Get TLD](https://webservices.amazon.com/paapi5/documentation/common-request-parameters.html#host-and-region).
* "_ASIN_" : Amazon Standard Identification Number (*your locale*), [More](https://webservices.amazon.com/paapi5/documentation/get-items.html#ItemLookup-rp).


### Quickstart:

```php

/**
* @see Use Composer,
* Or include Apaapi Autoloader Here.
*/

use Apaapi\includes\Builder;

// Init request builder
$builder = new Builder('_KEY_', '_SECRET_', '_TAG_', '_REGION_');

// Get response
$data = $builder->searchOne('Sony Xperia Pro-I') // Normalized array

```

### Quickstart (OLD):


```php

Expand All @@ -86,11 +102,11 @@ use Apaapi\lib\Response;

// (1) Set Operation
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}');
$operation->setPartnerTag('_TAG_')->setKeywords('_KEYWORDS_');

// (2) Prapere Request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request->setLocale('{Your-region}')->setPayload($operation);
$request = new Request('_KEY_','_SECRET_');
$request->setLocale('_REGION_')->setPayload($operation);

// (3) Get Response
$response = new Response($request);
Expand All @@ -116,22 +132,22 @@ use Apaapi\operations\GetBrowseNodes;

// GetItems
$operation = new GetItems();
$operation->setPartnerTag('{Your-partner-tag}')
->setItemIds(['{ASIN}']); // Array|String
$operation->setPartnerTag('_TAG_')
->setItemIds(['_ASIN_']); // Array|String

// SearchItems
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')
->setKeywords('{Your-keywords}'); // Array|String
$operation->setPartnerTag('_TAG_')
->setKeywords('_KEYWORDS_'); // Array|String

// GetVariations
$operation = new GetVariations();
$operation->setPartnerTag('{Your-partner-tag}')
->setASIN('{ASIN}'); // String
$operation->setPartnerTag('_TAG_')
->setASIN('_ASIN_'); // String

// GetBrowseNodes
$operation = new GetBrowseNodes();
$operation->setPartnerTag('{Your-partner-tag}')
$operation->setPartnerTag('_TAG_')
->setBrowseNodeIds(['{NodeId}']); // Array|String

```
Expand All @@ -147,7 +163,7 @@ $operation->setPartnerTag('{Your-partner-tag}')
*/

// Set Operation
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}')
$operation->setPartnerTag('_TAG_')->setKeywords('_KEYWORDS_')
->setResources(['Images.Primary.Small','ItemInfo.Title','Offers.Listings.Price']);

```
Expand All @@ -174,10 +190,10 @@ class MyRequestClient extends RequestClient

// Set Operation
$operation = new GetItems();
$operation->setPartnerTag('{Your-partner-tag}')->setItemIds('{ASIN}');
$operation->setPartnerTag('_TAG_')->setItemIds('_ASIN_');

// Prapere Request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request = new Request('_KEY_','_SECRET_');
$request->setLocale('{your-region}')->setPayload($operation);

// Set Custom Client After Payload
Expand Down Expand Up @@ -249,11 +265,11 @@ if ( $response->hasError() ) {
// Set Cart
$cart = new Cart();
$cart->setLocale('{Your-locale}');
$cart->setPartnerTag('{Your-partner-tag}');
$cart->setPartnerTag('_TAG_');

// Set Items
$items = [
'{ASIN1}' => '3', // ({ASIN} => {Quantity})
'{ASIN1}' => '3', // (_ASIN_ => {Quantity})
'{ASIN2}' => '5'
];

Expand Down
26 changes: 13 additions & 13 deletions examples/add-to-cart.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @author : JIHAD SINNAOUR
* @package : Apaapi | Amazon Product Advertising API Library (v5)
* @version : 1.1.7
* @copyright : (c) 2019 - 2023 Jihad Sinnaour <[email protected]>
* @author : Jakiboy
* @package : Amazon Product Advertising API Library (v5)
* @version : 1.2.0
* @copyright : (c) 2019 - 2024 Jihad Sinnaour <[email protected]>
* @link : https://jakiboy.github.io/apaapi/
* @license : MIT
*
Expand All @@ -12,26 +12,26 @@

/**
* @see You can use Composer,
* Or include Apaapi Standalone Autoloader Here.
* Or include Apaapi standalone autoloader here.
*/
include('../src/Autoloader.php');
\apaapi\Autoloader::init();

use Apaapi\lib\Cart;

// Set Cart
// init cart
$cart = new Cart();
$cart->setLocale('{Your-locale}');
$cart->setPartnerTag('{Your-partner-tag}');

// Set Items
// Set items
$items = [
'{ASIN1}' => '3', // ({ASIN} => {Quantity})
'{ASIN2}' => '5'
'{ASIN1|ISBN1}' => '3', // ({ASIN|ISBN} => {Quantity})
'{ASIN2|ISBN2}' => '5'
];

// Get Response
$url = $cart->add($items);
var_dump($url); // String URL
// Get response
$url = $cart->set($items);
echo $url; // String

// Hope you found this useful, any suggestions (Pull requests) are welcome!
// Any suggestions (PR) are welcome!
22 changes: 12 additions & 10 deletions examples/basic.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @author : JIHAD SINNAOUR
* @package : Apaapi | Amazon Product Advertising API Library (v5)
* @version : 1.1.7
* @copyright : (c) 2019 - 2023 Jihad Sinnaour <[email protected]>
* @author : Jakiboy
* @package : Amazon Product Advertising API Library (v5)
* @version : 1.2.0
* @copyright : (c) 2019 - 2024 Jihad Sinnaour <[email protected]>
* @link : https://jakiboy.github.io/apaapi/
* @license : MIT
*
Expand All @@ -12,7 +12,7 @@

/**
* @see You can use Composer,
* Or include Apaapi Standalone Autoloader Here.
* Or include Apaapi standalone autoloader here.
*/
include('../src/Autoloader.php');
\apaapi\Autoloader::init();
Expand All @@ -21,16 +21,18 @@
use Apaapi\lib\Request;
use Apaapi\lib\Response;

// Set Operation
// Set operation
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}');

// Prapere Request
// Prapere request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request->setLocale('{Your-locale}')->setPayload($operation);

// Get Response
// Get response
$response = new Response($request);
echo $response->get(); // JSON ready to be parsed
$data = $response->get(); // Array
$body = $response->getBody(); // String
print_r($data);

// Hope you found this useful, any suggestions (Pull requests) are welcome!
// Any suggestions (PR) are welcome!
57 changes: 32 additions & 25 deletions examples/custom-client.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @author : JIHAD SINNAOUR
* @package : Apaapi | Amazon Product Advertising API Library (v5)
* @version : 1.1.7
* @copyright : (c) 2019 - 2023 Jihad Sinnaour <[email protected]>
* @author : Jakiboy
* @package : Amazon Product Advertising API Library (v5)
* @version : 1.2.0
* @copyright : (c) 2019 - 2024 Jihad Sinnaour <[email protected]>
* @link : https://jakiboy.github.io/apaapi/
* @license : MIT
*
Expand All @@ -12,66 +12,73 @@

/**
* @see You can use Composer,
* Or include Apaapi Standalone Autoloader Here.
* Or include Apaapi standalone autoloader here.
*/
include('../src/Autoloader.php');
\apaapi\Autoloader::init();

use Apaapi\operations\SearchItems;
use Apaapi\lib\Request;
use Apaapi\lib\Response;
use Apaapi\includes\RequestClient;
use Apaapi\includes\Client;

/**
* Create Custom Request Client Class.
* Custom request client class.
*/
class MyRequestClient extends RequestClient
class MyClient extends Client
{
protected function init()
// Enable request client exception
public function __construct(string $endpoint, array $params = [])
{
parent::__construct($endpoint, $params, true);
}

// Override handler behavior
protected function setHandler()
{
if ( self::hasCurl() ) {

// cURL override example
// Override curl
$this->handler = curl_init();
curl_setopt($this->handler, CURLOPT_URL, $this->endpoint);
curl_setopt($this->handler, CURLOPT_HTTPHEADER, $this->getRequestHeader());
curl_setopt($this->handler, CURLOPT_POSTFIELDS, $this->getRequestContent());
curl_setopt($this->handler, CURLOPT_POST, true);
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->handler, CURLOPT_SSL_VERIFYPEER, true); // Force SSL instead of Auto
curl_setopt($this->handler, CURLOPT_TIMEOUT, 10); // Custom Timeout instead of 30
curl_setopt($this->handler, CURLOPT_SSL_VERIFYPEER, true); // Force SSL
curl_setopt($this->handler, CURLOPT_TIMEOUT, 10); // Set custom timeout

} elseif ( self::hasStream() ) {

// Stream override example
$this->handler = [
// Override stream
$this->handler = stream_context_create([
'http' => [
'method' => 'POST',
'header' => $this->getRequestHeader(),
'content' => $this->getRequestContent(),
'timeout' => 10 // Custom Timeout instead of 30
'timeout' => $this->timeout // Set custom timeout
]
];
]);
}
}
}

// Set Operation
// Set operation
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}')
->setResources(['Images.Primary.Small','ItemInfo.Title','Offers.Listings.Price']);
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}');

// Prapere Request
// Prapere request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
$request->setLocale('{Your-locale}')->setPayload($operation);

// Set Custom Client after Payload
// Set custom client after payload
$request->setClient(
new MyRequestClient($request->getEndpoint(), $request->getParams())
new MyClient($request->getEndpoint(), $request->getParams())
);

// Get Response
// Get response
$response = new Response($request);
echo $response->get(); // JSON ready to be parsed
$data = $response->get(); // Array
print_r($data);

// Hope you found this useful, any suggestions (Pull requests) are welcome!
// Any suggestions (PR) are welcome!
11 changes: 5 additions & 6 deletions examples/custom-error-handling.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @author : JIHAD SINNAOUR
* @package : Apaapi | Amazon Product Advertising API Library (v5)
* @version : 1.1.7
* @copyright : (c) 2019 - 2023 Jihad Sinnaour <[email protected]>
* @author : Jakiboy
* @package : Amazon Product Advertising API Library (v5)
* @version : 1.2.0
* @copyright : (c) 2019 - 2024 Jihad Sinnaour <[email protected]>
* @link : https://jakiboy.github.io/apaapi/
* @license : MIT
*
Expand All @@ -23,8 +23,7 @@

// Set Operation
$operation = new SearchItems();
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}')
->setResources(['Images.Primary.Small','ItemInfo.Title','Offers.Listings.Price']);
$operation->setPartnerTag('{Your-partner-tag}')->setKeywords('{Your-keywords}');

// Prapere Request
$request = new Request('{Your-key-id}','{Your-secrect-key}');
Expand Down
Loading

0 comments on commit 55eb344

Please sign in to comment.