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

add create dossier method #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,77 @@ $response = $pricehubble->pointsOfInterest()->gather([
print_r($response);
```

### Dossier Create

Creates a new dossier. The dossier can then be shared using the Dossier Sharing endpoint.

👉 https://docs.pricehubble.com/international/dossier_creation/

```php
$pricehubble = new Pricehubble();
$pricehubble->authenticate($username, $password)
$response = $pricehubble->dossier()->create([
'title' => 'My dossier',
'description' => 'My description',
'dealType' => 'sale',
'property' => [
'location' => [
'address' => [
'postCode' => '8037',
'city' => 'Zurich',
'street' => 'Nordstrasse',
'houseNumber' => '391',
],
'coordinates' => [
'latitude' => 47.3968601,
'longitude' => 8.5153549,
],
],
'propertyType' => [
'code' => 'house',
'subcode' => 'house_detached',
],
'buildingYear' => 1990,
'livingArea' => 100.00,
'landArea' => 900.00,
'volume' => 900.00,
'numberOfRooms' => 3,
'numberOfBathrooms' => 1,
'numberOfIndoorParkingSpaces' => 0,
'numberOfOutdoorParkingSpaces' => 0,
'hasPool' => true,
'condition' => [
'bathrooms' => 'renovation_needed',
'kitchen' => 'renovation_needed',
'flooring' => 'well_maintained',
'windows' => 'new_or_recently_renovated',
],
'quality' => [
'bathrooms' => 'simple',
'kitchen' => 'normal',
'flooring' => 'high_quality',
'windows' => 'luxury',
],
],
'userDefinedFields' => [
[
'label' => 'Extra garage',
'value' => 'Yes',
],
],
'images' => [
[
'filename' => '633390e8-0455-4520-87ba-3c5c8c234cb3.jpg',
'caption' => 'Front view',
],
],
'logo' => 'b7219677-f4d5-4e99-9d7f-7cf1dee68900.png',
'countryCode' => 'CH',
]);
print_r($response);
```


Troubleshooting
---------------

Expand Down
1 change: 1 addition & 0 deletions src/Pricehubble.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @method \Antistatique\Pricehubble\Resource\Valuation valuation()
* @method \Antistatique\Pricehubble\Resource\PointsOfInterest pointsOfInterest()
* @method \Antistatique\Pricehubble\Resource\Dossier dossier()
*/
class Pricehubble
{
Expand Down
38 changes: 38 additions & 0 deletions src/Resource/Dossier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Antistatique\Pricehubble\Resource;

use Antistatique\Pricehubble\Pricehubble;

/**
* The Pricehubble Dossier API class.
*
* @see https://docs.pricehubble.com/international/dossier_creation/
* @see https://docs.pricehubble.com/international/dossier_read/
* @see https://docs.pricehubble.com/international/dossier_deletion/
* @see https://docs.pricehubble.com/international/dossier_images/
* @see https://docs.pricehubble.com/international/dossier_logos/
* @see https://docs.pricehubble.com/international/dossier_search/
* @see https://docs.pricehubble.com/international/dossier_sharing/
* @see https://docs.pricehubble.com/international/dossier_update/
*/
final class Dossier extends AbstractResource
{
/**
* Creates a new dossier. The dossier can then be shared using the Dossier Sharing endpoint.
*
* @param array $args
* Assoc array of arguments (usually your data)
* @param int $timeout
* Timeout limit for request in seconds
*
* @throws \Exception
*
* @return array|bool
* A decoded array of result or a boolean on unattended response
*/
public function create(array $args = [], int $timeout = Pricehubble::TIMEOUT)
{
return $this->getPricehubble()->makeRequest('post', Pricehubble::BASE_URL.'/dossiers', $args, $timeout);
}
}
90 changes: 90 additions & 0 deletions tests/Unit/DossierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Antistatique\Pricehubble\Tests\Unit;

use Antistatique\Pricehubble\Pricehubble;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \Antistatique\Pricehubble\Resource\Dossier
*
* @group pricehubble
* @group pricehubble_unit
*/
class DossierTest extends TestCase
{
/**
* @covers ::create
*/
public function testCreateReturnsExpected(): void
{
$response = json_decode(file_get_contents(__DIR__.'/../responses/dossier/create.json'), true, 512, JSON_THROW_ON_ERROR);

$pricehubble_mock = $this->getMockBuilder(Pricehubble::class)
->onlyMethods(['makeRequest'])
->getMock();

$pricehubble_mock->expects($this->once())
->method('makeRequest')
->willReturn($response);

$pricehubble_mock->dossier()->create([
'title' => 'My dossier',
'description' => 'My description',
'dealType' => 'sale',
'property' => [
'location' => [
'address' => [
'postCode' => '8037',
'city' => 'Zurich',
'street' => 'Nordstrasse',
'houseNumber' => '391',
],
'coordinates' => [
'latitude' => 47.3968601,
'longitude' => 8.5153549,
],
],
'propertyType' => [
'code' => 'house',
'subcode' => 'house_detached',
],
'buildingYear' => 1990,
'livingArea' => 100.00,
'landArea' => 900.00,
'volume' => 900.00,
'numberOfRooms' => 3,
'numberOfBathrooms' => 1,
'numberOfIndoorParkingSpaces' => 0,
'numberOfOutdoorParkingSpaces' => 0,
'hasPool' => true,
'condition' => [
'bathrooms' => 'renovation_needed',
'kitchen' => 'renovation_needed',
'flooring' => 'well_maintained',
'windows' => 'new_or_recently_renovated',
],
'quality' => [
'bathrooms' => 'simple',
'kitchen' => 'normal',
'flooring' => 'high_quality',
'windows' => 'luxury',
],
],
'userDefinedFields' => [
[
'label' => 'Extra garage',
'value' => 'Yes',
],
],
'images' => [
[
'filename' => '633390e8-0455-4520-87ba-3c5c8c234cb3.jpg',
'caption' => 'Front view',
],
],
'logo' => 'b7219677-f4d5-4e99-9d7f-7cf1dee68900.png',
'countryCode' => 'CH',
]);
}
}
27 changes: 27 additions & 0 deletions tests/Unit/Resource/DossierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Antistatique\Pricehubble\Tests\Unit;

use Antistatique\Pricehubble\Pricehubble;
use Antistatique\Pricehubble\Resource\AbstractResource;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \Antistatique\Pricehubble\Resource\Dossier
*
* @group pricehubble
* @group pricehubble_unit
*/
class DossierTest extends TestCase
{
/**
* @covers \Antistatique\Pricehubble\Pricehubble::__call
*/
public function testCallReturnsExpected(): void
{
$pricehubble = new Pricehubble();
$resource = $pricehubble->dossier();
self::assertInstanceOf(AbstractResource::class, $resource);
}

}
3 changes: 3 additions & 0 deletions tests/responses/dossier/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "119a6ead-4ac4-4b4b-b264-195a2895618e"
}