diff --git a/README.md b/README.md index 569d987..21ecb32 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This package was developed to give you a quick start to receive public listings ## 💡 What is Flatfox? -Flatfox is a web based portal where you can Search & advertise apartments for free. +Flatfox is a web-based portal where you can Search & advertise apartments for free. ## 🛠 Requirements @@ -28,7 +28,7 @@ composer require codebar-ag/laravel-flatfox ## Usage ```php - $request = new GetPublicListing(142, '&expand=documents&expand=images'); + $request = new GetPublicListing(identifier: 142); $response = $request->send(); $status = $request->status(); diff --git a/src/DTO/Listing.php b/src/DTO/Listing.php index ed1f6ff..8810939 100644 --- a/src/DTO/Listing.php +++ b/src/DTO/Listing.php @@ -159,7 +159,6 @@ protected static function attributes(array $attributes): Collection return collect($attributes)->map(function ($result) { return Attribute::fromJson($result); }); - } protected static function images(array $images): Collection @@ -167,7 +166,6 @@ protected static function images(array $images): Collection return collect($images)->map(function ($result) { return Image::fromJson($result); }); - } protected static function documents(array $documents): Collection @@ -175,6 +173,5 @@ protected static function documents(array $documents): Collection return collect($documents)->map(function ($result) { return Document::fromJson($result); }); - } } diff --git a/src/Requests/GetPublicListing.php b/src/Requests/GetPublicListing.php index 7f019c2..899924f 100644 --- a/src/Requests/GetPublicListing.php +++ b/src/Requests/GetPublicListing.php @@ -8,8 +8,8 @@ use Saloon\CachePlugin\Contracts\Driver; use Saloon\CachePlugin\Drivers\LaravelCacheDriver; use Saloon\CachePlugin\Traits\HasCaching; -use Saloon\Http\Response; use Saloon\Enums\Method; +use Saloon\Http\Response; use Saloon\Http\SoloRequest; class GetPublicListing extends SoloRequest implements Cacheable @@ -22,12 +22,18 @@ public function resolveEndpoint(): string { $endpoint = trim(config('flatfox.endpoint', 'https://flatfox.ch'), '/'); - return "$endpoint/api/v1/public-listing/?organization={$this->identifier}{$this->expand}"; + $this->expand = array_merge($this->expand, ['documents', 'images']); + + return sprintf('%s/api/v1/public-listing/?organization=%s&expand=%s', + $endpoint, + urlencode($this->identifier), + urlencode(implode(',', $this->expand)) + ); } public function __construct( protected string $identifier, - protected ?string $expand = null, + protected array $expand = [], ) { } diff --git a/tests/Feature/GetPublicListingTest.php b/tests/Feature/GetPublicListingTest.php index 73485ee..99b545a 100644 --- a/tests/Feature/GetPublicListingTest.php +++ b/tests/Feature/GetPublicListingTest.php @@ -12,7 +12,7 @@ GetPublicListing::class => MockResponse::fixture('get-public-listing-request'), ]); - $request = new GetPublicListing(142, '&expand=documents&expand=images'); + $request = new GetPublicListing(identifier: 142); $request->withMockClient($mockClient); $response = $request->send(); @@ -21,5 +21,4 @@ expect($response->status())->toBe(200) ->and($response->dto())->not()->toBeEmpty(); -}) - ->group('get', 'public-listing'); +})->group('get', 'public-listing');