Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #12

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});

}
}
10 changes: 7 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,16 @@ 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']);

$expand = implode(',', $this->expand);
RhysLees marked this conversation as resolved.
Show resolved Hide resolved

return "$endpoint/api/v1/public-listing/?organization={$this->identifier}&expand={$expand}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RhysLees

  $endpointUrl = sprintf('%s/api/v1/public-listing/?organization=%s&expand=%s',
        $endpoint,
        urlencode($this->identifier),
        urlencode($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');
Loading