retrieveToken(); $idAnnonce = $this->getIdAnnonceFromUrl($this->url); $url = sprintf('%s%s', self::LISTING_URL, $idAnnonce); $request = $this->client->request( 'GET', $url, [ 'headers' => [ 'AppToken' => $token, ], ] ); $annonce = json_decode($request->getBody()->getContents(), true); $parsedHome = new ParsedHome(); $parsedHome->city = $annonce['city']; //ex: Vente maison 110 m² Tréguier (22220) $parsedHome->title = $annonce['title']; $parsedHome->price = $annonce['price']; $parsedHome->surface = $annonce['livingArea']; $parsedHome->rooms = $annonce['rooms']; $parsedHome->energy = $annonce['energy']['grade']; $parsedHome->description = $annonce['description']; $parsedHome->pictures = $annonce['photos']; $location = $annonce['coordinates']; $parsedHome->map = ['lat' => $location['latitude'], 'lng' => $location['longitude']]; return $parsedHome; } /** * @param string $url * * @return string */ private function getIdAnnonceFromUrl($url) { // ex : https://www.seloger.com/annonces/achat/maison/franconville-95/vieux-marche-mare-des-noues/159100953.htm $url = parse_url($url, PHP_URL_PATH); return collect(explode('.', collect(explode('/', $url))->last()))->first(); } /** * @return string * @throws \GuzzleHttp\Exception\GuzzleException */ private function retrieveToken() { $request = $this->client->request( 'GET', self::TOKEN_URL, [ 'headers' => [ 'AppToken' => self::SELOGER_TOKEN, 'AppGuid' => self::SELOGER_GUID, ], ] ); return trim($request->getBody()->getContents(), '"'); } }