Skip to content

Commit 6983a76

Browse files
authored
Merge pull request #12 from codebar-ag/fix-request-array
Updates
2 parents 7c86b5a + 48c83fe commit 6983a76

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This package was developed to give you a quick start to receive public listings
99

1010
## 💡 What is Flatfox?
1111

12-
Flatfox is a web based portal where you can Search & advertise apartments for free.
12+
Flatfox is a web-based portal where you can Search & advertise apartments for free.
1313

1414
## 🛠 Requirements
1515

@@ -28,7 +28,7 @@ composer require codebar-ag/laravel-flatfox
2828
## Usage
2929

3030
```php
31-
$request = new GetPublicListing(142, '&expand=documents&expand=images');
31+
$request = new GetPublicListing(identifier: 142);
3232
$response = $request->send();
3333

3434
$status = $request->status();

src/DTO/Listing.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,19 @@ protected static function attributes(array $attributes): Collection
159159
return collect($attributes)->map(function ($result) {
160160
return Attribute::fromJson($result);
161161
});
162-
163162
}
164163

165164
protected static function images(array $images): Collection
166165
{
167166
return collect($images)->map(function ($result) {
168167
return Image::fromJson($result);
169168
});
170-
171169
}
172170

173171
protected static function documents(array $documents): Collection
174172
{
175173
return collect($documents)->map(function ($result) {
176174
return Document::fromJson($result);
177175
});
178-
179176
}
180177
}

src/Requests/GetPublicListing.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Saloon\CachePlugin\Contracts\Driver;
99
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
1010
use Saloon\CachePlugin\Traits\HasCaching;
11-
use Saloon\Http\Response;
1211
use Saloon\Enums\Method;
12+
use Saloon\Http\Response;
1313
use Saloon\Http\SoloRequest;
1414

1515
class GetPublicListing extends SoloRequest implements Cacheable
@@ -22,12 +22,18 @@ public function resolveEndpoint(): string
2222
{
2323
$endpoint = trim(config('flatfox.endpoint', 'https://flatfox.ch'), '/');
2424

25-
return "$endpoint/api/v1/public-listing/?organization={$this->identifier}{$this->expand}";
25+
$this->expand = array_merge($this->expand, ['documents', 'images']);
26+
27+
return sprintf('%s/api/v1/public-listing/?organization=%s&expand=%s',
28+
$endpoint,
29+
urlencode($this->identifier),
30+
urlencode(implode(',', $this->expand))
31+
);
2632
}
2733

2834
public function __construct(
2935
protected string $identifier,
30-
protected ?string $expand = null,
36+
protected array $expand = [],
3137
) {
3238
}
3339

tests/Feature/GetPublicListingTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
GetPublicListing::class => MockResponse::fixture('get-public-listing-request'),
1313
]);
1414

15-
$request = new GetPublicListing(142, '&expand=documents&expand=images');
15+
$request = new GetPublicListing(identifier: 142);
1616
$request->withMockClient($mockClient);
1717

1818
$response = $request->send();
@@ -21,5 +21,4 @@
2121

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

0 commit comments

Comments
 (0)