Skip to content

Commit

Permalink
design changes, add Ontop placements
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobBruening committed Jul 12, 2021
1 parent 8366b17 commit 2b5fa98
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development
/.idea/
/src/vendor/
/vendor/
/composer.lock

# PHPUnit
Expand Down
23 changes: 23 additions & 0 deletions docs/OnTop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OnTop placement

**API reference**: https://api.immobilienscout24.de/api-docs/import-export/ontop-placement/overview/
<br><br>

## 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);
```

8 changes: 4 additions & 4 deletions src/Immoscout/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions src/Immoscout/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? [];
}
Expand All @@ -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));
}
}
4 changes: 2 additions & 2 deletions src/Immoscout/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class Contact extends ApiRequest
*/
public function getAll(): array
{
return $this->request('user/me/contact');
return $this->request('contact');
}

/**
* Gets a contact by contact id
*/
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));
}

/**
Expand Down
48 changes: 48 additions & 0 deletions src/Immoscout/OnTopPlacement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);

namespace Immoscout;

use http\Exception\InvalidArgumentException;

class OnTopPlacement extends ApiRequest
{
public const SHOW_CASE = 'showcaseplacement';
public const PREMIUM = 'premiumplacement';
public const TOP = 'topplacement';
private const PLACEMENT_TYPES = [self::SHOW_CASE, self::PREMIUM, self::TOP];

private string $placement = self::SHOW_CASE;

/**
* Gets all ontop placed real estates
*/
public function getAll(): array
{
return $this->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;
}
}
4 changes: 2 additions & 2 deletions src/Immoscout/RealEstate.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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)];
}

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
Expand Down

0 comments on commit 2b5fa98

Please sign in to comment.