From 2b5fa9825a500e0de561aab57ef91d4a79c39e05 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 12 Jul 2021 18:35:30 +0200 Subject: [PATCH] design changes, add Ontop placements --- .gitignore | 2 +- docs/OnTop.md | 23 +++++++++++++++ src/Immoscout/ApiRequest.php | 8 +++--- src/Immoscout/Attachment.php | 4 +-- src/Immoscout/Contact.php | 4 +-- src/Immoscout/OnTopPlacement.php | 48 ++++++++++++++++++++++++++++++++ src/Immoscout/RealEstate.php | 4 +-- 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 docs/OnTop.md create mode 100644 src/Immoscout/OnTopPlacement.php diff --git a/.gitignore b/.gitignore index 8f506a0..bbbe7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Development /.idea/ -/src/vendor/ +/vendor/ /composer.lock # PHPUnit diff --git a/docs/OnTop.md b/docs/OnTop.md new file mode 100644 index 0000000..1c8ab7d --- /dev/null +++ b/docs/OnTop.md @@ -0,0 +1,23 @@ +# OnTop placement + +**API reference**: https://api.immobilienscout24.de/api-docs/import-export/ontop-placement/overview/ +

+ +## Get all Ontop placed real estates + +```php +$otPlacement = new OnTopPlacement(); +$otPlacement->getAll(); + +// placement is "showcaseplacement" (OnTopPlacement::SHOW_CASE) by default +// but you can change that of course! +$otPlacement->setPlacement(OnTopPlacement::PREMIUM); +$otPlacement->setPlacement(OnTopPlacement::TOP); +``` + +## Get information about OnTop placement of real estate + +```php +$otPlacement->getOneById(int $id); +``` + diff --git a/src/Immoscout/ApiRequest.php b/src/Immoscout/ApiRequest.php index 2dcd351..dc4d5c7 100644 --- a/src/Immoscout/ApiRequest.php +++ b/src/Immoscout/ApiRequest.php @@ -20,17 +20,17 @@ class ApiRequest { private Client $client; - protected const API_URL = 'https://rest.immobilienscout24.de/restapi/api/offer/v1.0/%s'; + protected const API_URL = 'https://rest.immobilienscout24.de/restapi/api/offer/v1.0/user/me/%s'; public function __construct(?array $auth = null) { - $this->prepareClient($auth); + $this->client = $this->getPreparedClient($auth); } /** * Authenticate and prepare GuzzleHttp client */ - private function prepareClient(?array $authData = null): void + private function getPreparedClient(?array $authData = null): Client { $key = $authData['consumer_key'] ?? $_ENV['IMSC_CONSUMER_KEY'] ?? null; $secret = $authData['consumer_secret'] ?? $_ENV['IMSC_CONSUMER_SECRET'] ?? null; @@ -50,7 +50,7 @@ private function prepareClient(?array $authData = null): void 'token_secret' => $tokenSecret ])); - $this->client = new Client([ + return new Client([ 'handler' => $stack, RequestOptions::AUTH => 'oauth', RequestOptions::HEADERS => ['Accept' => 'application/json'], diff --git a/src/Immoscout/Attachment.php b/src/Immoscout/Attachment.php index 1c0c915..d3e1d50 100644 --- a/src/Immoscout/Attachment.php +++ b/src/Immoscout/Attachment.php @@ -16,7 +16,7 @@ class Attachment extends ApiRequest */ public function getAllByRealEstate(int $id) { - $url = sprintf('user/me/realestate/%s/attachment', $id,); + $url = sprintf('realestate/%s/attachment', $id,); return $this->request($url)['common.attachments'] ?? []; } @@ -26,6 +26,6 @@ public function getAllByRealEstate(int $id) */ public function getOneById(int $realEstateId, int $id) { - return $this->request(sprintf('user/me/realestate/%s/attachment/%s', $realEstateId, $id)); + return $this->request(sprintf('realestate/%s/attachment/%s', $realEstateId, $id)); } } \ No newline at end of file diff --git a/src/Immoscout/Contact.php b/src/Immoscout/Contact.php index e753f02..a15488f 100644 --- a/src/Immoscout/Contact.php +++ b/src/Immoscout/Contact.php @@ -16,7 +16,7 @@ class Contact extends ApiRequest */ public function getAll(): array { - return $this->request('user/me/contact'); + return $this->request('contact'); } /** @@ -24,7 +24,7 @@ public function getAll(): array */ public function getOneById(int $id, bool $external = false): array { - return $this->request(sprintf('user/me/contact/%s%s', $external ? 'ext-' : '', $id)); + return $this->request(sprintf('contact/%s%s', $external ? 'ext-' : '', $id)); } /** diff --git a/src/Immoscout/OnTopPlacement.php b/src/Immoscout/OnTopPlacement.php new file mode 100644 index 0000000..2d3f156 --- /dev/null +++ b/src/Immoscout/OnTopPlacement.php @@ -0,0 +1,48 @@ +request(sprintf('%s/all', $this->placement)); + } + + /** + * Get one ontop placed real estate by id + */ + public function getOneById(int $id): array + { + return $this->request(sprintf('realestate/%s/%s', $id, $this->placement)); + } + + public function setPlacement(string $placement): self + { + if (!in_array($placement, self::PLACEMENT_TYPES, true)) { + throw new InvalidArgumentException(sprintf('Placement %s is invalid.', $placement)); + } + + $this->placement = $placement; + + return $this; + } + + public function getPlacement(): string + { + return $this->placement; + } +} \ No newline at end of file diff --git a/src/Immoscout/RealEstate.php b/src/Immoscout/RealEstate.php index a6b9a7f..5c0725f 100644 --- a/src/Immoscout/RealEstate.php +++ b/src/Immoscout/RealEstate.php @@ -66,7 +66,7 @@ public function getAllWithDetails(): array */ public function getOneById(int $id): array { - $realEstate = $this->request(sprintf('user/me/realestate/%s', $id)); + $realEstate = $this->request(sprintf('realestate/%s', $id)); return $realEstate[array_key_first($realEstate)]; } @@ -74,7 +74,7 @@ public function getOneById(int $id): array private function handleRequest(?int $page = null): array { $url = sprintf( - 'user/me/realestate?archivedobjectsincluded=%s&pagesize=%s&pagenumber=%s', + 'realestate?archivedobjectsincluded=%s&pagesize=%s&pagenumber=%s', $this->includeArchive ? 'true' : 'false', $this->pageSize, $page ?? 1