From b0e33e4e01d72387577b68adea9ef4ee9ce50982 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 28 Aug 2018 14:20:02 +0100 Subject: [PATCH] Update LeBonCoinBridge to use the site's API (#795) * Update LeBonCoinBridge to use the site's API --- bridges/LeBonCoinBridge.php | 81 +++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 57c58c61..295a188c 100644 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -150,43 +150,35 @@ class LeBonCoinBridge extends BridgeAbstract { ) ); + public static $LBC_API_KEY = 'ba0c2dad52b3ec'; + public function collectData(){ - $params = array( - 'text' => $this->getInput('k'), - 'region' => $this->getInput('r'), - 'cities' => $this->getInput('cities'), - 'category' => $this->getInput('c'), - 'owner_type' => $this->getInput('o'), - ); - - $url = self::URI . 'recherche/?' . http_build_query($params); + $url = 'https://api.leboncoin.fr/finder/search/'; + $data = $this->buildRequestJson(); $header = array( - 'Accept: text/html', - 'Accept-Language: ' . getEnv('HTTP_ACCEPT_LANGUAGE'), - 'Accept-Encoding: identity' + 'Content-Type: application/json', + 'Content-Length: ' . strlen($data), + 'api_key: ' . self::$LBC_API_KEY ); - $html = getContents($url, $header) + $opts = array( + CURL_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => $data + + ); + + $content = getContents($url, $header, $opts) or returnServerError('Could not request LeBonCoin. Tried: ' . $url); - if(!preg_match('/^', '