Skip to content

Commit 62f9be6

Browse files
committed
🐛 Trended valuations payload.
1 parent fb43ce9 commit 62f9be6

4 files changed

+100
-65
lines changed

src/Api/Builders/TrendedValuationDateRequestBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function toArray(): array
6868

6969
return $this->filterPrepareOutput([
7070
'odometerReading' => $this->odometerReadingMiles,
71-
'date' => $this->date,
71+
'date' => $this->date->format('Y-m-d'),
7272
]);
7373
}
7474
}

src/Api/Builders/TrendedValuationRequestBuilder.php

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
class TrendedValuationRequestBuilder extends AbstractBuilder
88
{
9-
protected $derivativeId;
10-
11-
protected $firstRegistrationDate;
9+
protected $vehicle;
1210

1311
protected $features;
1412

@@ -18,13 +16,20 @@ class TrendedValuationRequestBuilder extends AbstractBuilder
1816

1917
public function __construct(array $attributes = [])
2018
{
19+
$this->vehicle = new TrendedValuationVehicleRequestBuilder($this->dataGet($attributes, 'vehicle', []));
20+
2121
$this->features = new VehicleFeatureInfoBuilder($this->dataGet($attributes, 'features', []));
2222

2323
$this->valuations = new TrendedValuationValuationsRequestBuilder($this->dataGet($attributes, 'valuations', []));
2424

2525
parent::__construct($attributes);
2626
}
2727

28+
public function vehicle(): TrendedValuationVehicleRequestBuilder
29+
{
30+
return $this->vehicle;
31+
}
32+
2833
public function features(): VehicleFeatureInfoBuilder
2934
{
3035
return $this->features;
@@ -58,53 +63,6 @@ public function getCondition(): ?float
5863
return $this->condition;
5964
}
6065

61-
public function setDerivativeId(string $id): TrendedValuationRequestBuilder
62-
{
63-
$this->derivativeId = $id;
64-
65-
return $this;
66-
}
67-
68-
public function getDerivativeId(): ?string
69-
{
70-
return $this->derivativeId;
71-
}
72-
73-
public function setFirstRegistrationDate($date): TrendedValuationRequestBuilder
74-
{
75-
if (!($date instanceof \DateTime)) {
76-
$date = new \DateTime($date);
77-
}
78-
79-
$this->firstRegistrationDate = $date;
80-
81-
return $this;
82-
}
83-
84-
public function getFirstRegistrationDate(): ?\DateTime
85-
{
86-
return $this->firstRegistrationDate;
87-
}
88-
89-
public function validate(): bool
90-
{
91-
parent::validate();
92-
93-
if (empty($this->derivativeId)) {
94-
throw new ValidationException(
95-
'derivativeId must not be empty.'
96-
);
97-
}
98-
99-
if (empty($this->firstRegistrationDate)) {
100-
throw new ValidationException(
101-
'firstRegistrationDate must not be empty.'
102-
);
103-
}
104-
105-
return true;
106-
}
107-
10866
/**
10967
* @throws ValidationException
11068
*/
@@ -113,10 +71,7 @@ public function toArray(): array
11371
$this->validate();
11472

11573
return $this->filterPrepareOutput([
116-
'vehicle' => [
117-
'derivativeId' => $this->derivativeId,
118-
'firstRegistrationDate' => $this->firstRegistrationDate->format('Y-m-d'),
119-
],
74+
'vehicle' => $this->vehicle->toArray(),
12075
'features' => $this->features->toArray(),
12176
'condition' => $this->condition,
12277
'valuations' => $this->valuations->toArray(),
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Olsgreen\AutoTrader\Api\Builders;
4+
5+
class TrendedValuationVehicleRequestBuilder extends AbstractBuilder
6+
{
7+
protected $derivativeId;
8+
9+
protected $firstRegistrationDate;
10+
11+
public function setDerivativeId(string $id): TrendedValuationVehicleRequestBuilder
12+
{
13+
$this->derivativeId = $id;
14+
15+
return $this;
16+
}
17+
18+
public function getDerivativeId(): ?string
19+
{
20+
return $this->derivativeId;
21+
}
22+
23+
public function setFirstRegistrationDate($date): TrendedValuationVehicleRequestBuilder
24+
{
25+
if (!($date instanceof \DateTime)) {
26+
$date = new \DateTime($date);
27+
}
28+
29+
$this->firstRegistrationDate = $date;
30+
31+
return $this;
32+
}
33+
34+
public function getFirstRegistrationDate(): ?\DateTime
35+
{
36+
return $this->firstRegistrationDate;
37+
}
38+
39+
public function validate(): bool
40+
{
41+
parent::validate();
42+
43+
if (empty($this->derivativeId)) {
44+
throw new ValidationException(
45+
'derivativeId must not be empty.'
46+
);
47+
}
48+
49+
if (empty($this->firstRegistrationDate)) {
50+
throw new ValidationException(
51+
'firstRegistrationDate must not be empty.'
52+
);
53+
}
54+
55+
return true;
56+
}
57+
58+
public function toArray(): array
59+
{
60+
return [
61+
'derivativeId' => $this->derivativeId,
62+
'firstRegistrationDate' => $this->firstRegistrationDate->format('Y-m-d'),
63+
];
64+
}
65+
}

src/Api/Valuations.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,31 @@ public function value(string $advertiserId, ValuationRequestBuilder $builder)
4444
*
4545
* @example
4646
* $request = TrendedValuationRequestBuilder::create([
47-
* [
48-
* 'derivativeId' => '40a80ca0d16541789f2514ebadca3d66',
49-
* 'firstRegistrationDate' => '2022-11-10',
50-
* 'valuations' => [
51-
* 'markets' => ['retail'],
52-
* 'frequency' => 'month',
53-
* 'start' => ['date' => '2023-09-01', 'odometerReadingMiles' => 40000],
54-
* 'end' => ['date' => '2024-08-01', 'odometerReadingMiles' => 52000]
55-
* ]
56-
* ]
47+
* "vehicle" => [
48+
* "derivativeId" => "76744a390e0b44649f718894fec53569",
49+
* "firstRegistrationDate" => "2021-07-29",
50+
* ],
51+
* "features" => [
52+
* [
53+
* "name" => "CarPlay",
54+
* "type" => "Optional",
55+
* ],
56+
* ],
57+
* "conditionRating" => "GOOD",
58+
* "valuations" => [
59+
* "markets" => [
60+
* "retail",
61+
* ],
62+
* "frequency" => "month",
63+
* "start" => [
64+
* "date" => "2023-09-01",
65+
* "odometerReadingMiles" => 40000,
66+
* ],
67+
* "end" => [
68+
* "date" => "2024-03-01",
69+
* "odometerReadingMiles" => 52000,
70+
* ],
71+
* ],
5772
* ]);
5873
*
5974
* $valuation = $api->valuations()->trends($request)

0 commit comments

Comments
 (0)