@@ -33,7 +33,12 @@ class Client
3333 private static $ endpoints = [
3434 "decode " => "https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/%s?format=json " ,
3535 "recalls " => "https://api.nhtsa.gov/recalls/recallsByVehicle?modelYear=%d&make=%s&model=%s " ,
36+ "GetModelsForMakeYear " => "https://vpic.nhtsa.dot.gov/api/vehicles/getmodelsformakeyear/make/%s/modelyear/%d?format=json " ,
37+ "GetModelsForMakeIdYear " => "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeIdYear/makeId/%d/modelyear/%d?format=json " ,
38+ "GetModelsForMake " => "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMake/%s?format=json " ,
39+ "GetModelsForMakeId " => "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/%d?format=json " ,
3640 ];
41+
3742 private static $ minimum_year = 1950 ;
3843 private static $ minimum_make_length = 3 ;
3944 private static $ minimum_model_length = 3 ;
@@ -228,6 +233,88 @@ public static function parseRecalls(array $recalls = []): ?array
228233 return $ parsed_result ;
229234 }
230235
236+ /**
237+ * Get all available models for a make by year
238+ *
239+ * @note This is a free-text match. Recommend using `getModelsForMakeIdByYear`
240+ * @param int $year The model year
241+ * @param string $make The make
242+ */
243+ public static function getModelsForMakeByYear (int $ year , string $ make ): ?array
244+ {
245+ if (!$ year || $ year < self ::$ minimum_year ) {
246+ return null ;
247+ }
248+ if (!$ make || strlen ($ make ) < self ::$ minimum_make_length ) {
249+ return null ;
250+ }
251+
252+ // Fetch Data
253+ $ endpoint = sprintf (self ::$ endpoints ["GetModelsForMakeYear " ], rawurlencode (strtoupper ($ make )), $ year );
254+ $ result = json_decode (self ::http_get ($ endpoint ), true );
255+
256+ return $ result && isset ($ result ["Count " ]) && $ result ["Count " ] > 0 ? $ result ["Results " ] : null ;
257+ }
258+
259+ /**
260+ * Get all available models for a make Id by year
261+ *
262+ * @param int $year The model year
263+ * @param int $make_id The make id
264+ */
265+ public static function getModelsForMakeIdByYear (int $ year , int $ make_id ): ?array
266+ {
267+ if (!$ make_id ) {
268+ return null ;
269+ }
270+ if (!$ year || $ year < self ::$ minimum_year ) {
271+ return null ;
272+ }
273+
274+ // Fetch Data
275+ $ endpoint = sprintf (self ::$ endpoints ["GetModelsForMakeIdYear " ], $ make_id , $ year );
276+ $ result = json_decode (self ::http_get ($ endpoint ), true );
277+
278+ return $ result && isset ($ result ["Count " ]) && $ result ["Count " ] > 0 ? $ result ["Results " ] : null ;
279+ }
280+
281+ /**
282+ * Get all available models for a make
283+ *
284+ * @note This is a free-text match. Recommend using `getModelsForMakeId`
285+ * @param string $make
286+ */
287+ public static function GetModelsForMake (string $ make ): ?array
288+ {
289+ if (!$ make || strlen ($ make ) < self ::$ minimum_make_length ) {
290+ return null ;
291+ }
292+
293+ // Fetch Data
294+ $ endpoint = sprintf (self ::$ endpoints ["GetModelsForMake " ], rawurlencode (strtoupper ($ make )));
295+ $ result = json_decode (self ::http_get ($ endpoint ), true );
296+
297+ return $ result && isset ($ result ["Count " ]) && $ result ["Count " ] > 0 ? $ result ["Results " ] : null ;
298+ }
299+
300+ /**
301+ * Get all available models for a make Id
302+ *
303+ * @param int $make_id The make id
304+ */
305+ public static function GetModelsForMakeId (int $ make_id ): ?array
306+ {
307+ if (!$ make_id ) {
308+ return null ;
309+ }
310+
311+ // Fetch Data
312+ $ endpoint = sprintf (self ::$ endpoints ["GetModelsForMakeId " ], $ make_id );
313+ $ result = json_decode (self ::http_get ($ endpoint ), true );
314+
315+ return $ result && isset ($ result ["Count " ]) && $ result ["Count " ] > 0 ? $ result ["Results " ] : null ;
316+ }
317+
231318 /**
232319 * Parse Unix Timestamp (Miliseconds with offset)
233320 *
0 commit comments