Skip to content

Commit c1aeacb

Browse files
committed
feat(vehicles): Support looking up vehicles by VIN
1 parent 47c939a commit c1aeacb

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/Api/Builders/LookupRequestBuilder.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class LookupRequestBuilder extends AbstractBuilder implements BuilderInterface
1515
*/
1616
protected $registration;
1717

18+
/**
19+
* VIN
20+
*
21+
* @var string
22+
*/
23+
protected $vin;
24+
1825
protected $flagsEnum = VehicleLookupFlags::class;
1926

2027
/**
@@ -24,7 +31,7 @@ class LookupRequestBuilder extends AbstractBuilder implements BuilderInterface
2431
*/
2532
protected $odometerReadingMiles;
2633

27-
protected $requiredAttributes = ['registration'];
34+
protected $requiredAttributes = [];
2835

2936
/**
3037
* Get the registration.
@@ -50,6 +57,20 @@ public function setRegistration(string $registration): LookupRequestBuilder
5057
return $this;
5158
}
5259

60+
/**
61+
* Set the VIN.
62+
*
63+
* @param string $vin
64+
*
65+
* @return $this
66+
*/
67+
public function setVin(string $vin): LookupRequestBuilder
68+
{
69+
$this->vin = $vin;
70+
71+
return $this;
72+
}
73+
5374
/**
5475
* Get the mileage.
5576
*
@@ -85,6 +106,11 @@ public function validate(): bool
85106
{
86107
parent::validate();
87108

109+
// Require a registration or VIN
110+
if (empty($this->registration) && empty($this->vin)) {
111+
throw new ValidationException('A registration or VIN must be set.');
112+
}
113+
88114
// Validate the odometer status.
89115
$requiresOdometerReading = !empty(array_intersect(
90116
[VehicleLookupFlags::VALUATIONS, VehicleLookupFlags::VEHICLE_METRICS],
@@ -114,7 +140,8 @@ public function toArray(): array
114140
$this->validate();
115141

116142
return $this->filterPrepareOutput([
117-
'registration' => preg_replace('/\s/', '', $this->registration),
143+
'registration' => !empty($this->registration) ? preg_replace('/\s/', '', $this->registration) : null,
144+
'vin' => !empty($this->vin) ? preg_replace('/\s/', '', $this->vin) : null,
118145
'odometerReadingMiles' => $this->odometerReadingMiles,
119146
] + $this->transformFlags($this->flags));
120147
}

0 commit comments

Comments
 (0)