Merge pull request #448 from chemel/amazon
[AmazonBridge] Add possibility to choose Amazon location
This commit is contained in:
commit
1e0cef8f7f
1 changed files with 36 additions and 14 deletions
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
class AmazonBridge extends BridgeAbstract {
|
class AmazonBridge extends BridgeAbstract {
|
||||||
|
|
||||||
const MAINTAINER = "Alexis CHEMEL";
|
const MAINTAINER = 'Alexis CHEMEL';
|
||||||
const NAME = "Amazon";
|
const NAME = 'Amazon';
|
||||||
const URI = "https://www.amazon.fr/";
|
const URI = 'https://www.amazon.com/';
|
||||||
const CACHE_TIMEOUT = 3600; // 1h
|
const CACHE_TIMEOUT = 3600; // 1h
|
||||||
const DESCRIPTION = "Returns products from Amazon search";
|
const DESCRIPTION = 'Returns products from Amazon search';
|
||||||
|
|
||||||
const PARAMETERS = array(array(
|
const PARAMETERS = array(array(
|
||||||
'q' => array(
|
'q' => array(
|
||||||
|
@ -19,26 +19,48 @@ class AmazonBridge extends BridgeAbstract {
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'values' => array(
|
'values' => array(
|
||||||
'Relevance' => 'relevanceblender',
|
'Relevance' => 'relevanceblender',
|
||||||
'Popularity' => 'popularity-rank',
|
'Price: Low to High' => 'price-asc-rank',
|
||||||
'Price : in ascending order' => 'price-asc-rank',
|
'Price: High to Low' => 'price-desc-rank',
|
||||||
'Price : in descending order' => 'price-desc-rank',
|
'Average Customer Review' => 'review-rank',
|
||||||
'Average rating' => 'review-rank',
|
'Newest Arrivals' => 'date-desc-rank',
|
||||||
'Newest item' => 'date-desc-rank',
|
),
|
||||||
|
'defaultValue' => 'relevanceblender',
|
||||||
|
),
|
||||||
|
'tld' => array(
|
||||||
|
'name' => 'Country',
|
||||||
|
'type' => 'list',
|
||||||
|
'required' => true,
|
||||||
|
'values' => array(
|
||||||
|
'Australia' => 'com.au',
|
||||||
|
'Brazil' => 'com.br',
|
||||||
|
'Canada' => 'ca',
|
||||||
|
'China' => 'cn',
|
||||||
|
'France' => 'fr',
|
||||||
|
'Germany' => 'de',
|
||||||
|
'India' => 'in',
|
||||||
|
'Italy' => 'it',
|
||||||
|
'Japan' => 'co.jp',
|
||||||
|
'Mexico' => 'com.mx',
|
||||||
|
'Netherlands' => 'nl',
|
||||||
|
'Spain' => 'es',
|
||||||
|
'United Kingdom' => 'co.uk',
|
||||||
|
'United States' => 'com',
|
||||||
|
),
|
||||||
|
'defaultValue' => 'com',
|
||||||
),
|
),
|
||||||
'defaultValue' => 'popularity-rank',
|
|
||||||
)
|
|
||||||
));
|
));
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
|
|
||||||
return 'Amazon - '.$this->getInput('q');
|
return 'Amazon.'.$this->getInput('tld').': '.$this->getInput('q');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function collectData() {
|
public function collectData() {
|
||||||
|
|
||||||
$url = self::URI.'s/?field-keywords='.urlencode($this->getInput('q')).'&sort='.$this->getInput('sort');
|
$uri = 'https://www.amazon.'.$this->getInput('tld').'/';
|
||||||
|
$uri .= 's/?field-keywords='.urlencode($this->getInput('q')).'&sort='.$this->getInput('sort');
|
||||||
|
|
||||||
$html = getSimpleHTMLDOM($url)
|
$html = getSimpleHTMLDOM($uri)
|
||||||
or returnServerError('Could not request Amazon.');
|
or returnServerError('Could not request Amazon.');
|
||||||
|
|
||||||
foreach($html->find('li.s-result-item') as $element) {
|
foreach($html->find('li.s-result-item') as $element) {
|
||||||
|
|
Loading…
Reference in a new issue