Skip to content

Commit

Permalink
Merge pull request #12 from codebar-ag/fix-request-array
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
StanBarrows authored Feb 27, 2024
2 parents 7c86b5a + 48c83fe commit 6983a76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/DTO/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,19 @@ protected static function attributes(array $attributes): Collection
return collect($attributes)->map(function ($result) {
return Attribute::fromJson($result);
});

}

protected static function images(array $images): Collection
{
return collect($images)->map(function ($result) {
return Image::fromJson($result);
});

}

protected static function documents(array $documents): Collection
{
return collect($documents)->map(function ($result) {
return Document::fromJson($result);
});

}
}
12 changes: 9 additions & 3 deletions src/Requests/GetPublicListing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [],
) {
}

Expand Down
5 changes: 2 additions & 3 deletions tests/Feature/GetPublicListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -21,5 +21,4 @@

expect($response->status())->toBe(200)
->and($response->dto())->not()->toBeEmpty();
})
->group('get', 'public-listing');
})->group('get', 'public-listing');

0 comments on commit 6983a76

Please sign in to comment.