Skip to content

Commit b3b4bb5

Browse files
committedDec 21, 2021
Added two more endpoints and check ssl cert
1 parent 615aafd commit b3b4bb5

File tree

6 files changed

+159
-14
lines changed

6 files changed

+159
-14
lines changed
 

‎.phpunit.result.cache

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:37:"PHPUnit\Runner\DefaultTestResultCache":259:{a:2:{s:7:"defects";a:1:{s:58:"Codebyray\LaravelVehapi\Tests\EndpointTest::test_get_years";i:3;}s:5:"times";a:2:{s:55:"Codebyray\LaravelVehapi\Tests\ExampleTest::true_is_true";d:0.079;s:58:"Codebyray\LaravelVehapi\Tests\EndpointTest::test_get_years";d:0.105;}}}

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ All notable changes to `laravel-vehapi` will be documented in this file
55
## 1.0.0 - 2021-26-03
66

77
- initial release
8+
9+
## 1.1 - 2021-20-12
10+
11+
- Added option to bypass cURL certificate check (this is mainly for local development)
12+
- Added get vehicle wheel options
13+
- Added get vehicle options

‎LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) RJ
3+
Copyright (c) CodebyRay & Vehicle Info API
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎README.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ php artisan vendor:publish --provider="Codebyray\LaravelVehapi\LaravelVehapiServ
3535
```
3636

3737
## Setup .env file
38-
Add your API token & API version to your .env file:
38+
Add your API token, API version & API SSL check to your .env file:
3939
> NOTE: API version will default to v1, you DO NOT need to specify the version unless you are using a different
4040
> version of Vehicle Info API. API token is required. However, it can be entered in your .env file (recommended), or the published
4141
> config file.
4242
4343
```dotenv
4444
VEH_API_TOKEN=YOUR_VEH_API_TOKEN
4545
VEH_API_VERSION=v1
46+
VEH_CHECK_SSL_CERT=true // Defaults to true. Change to false if testing locally.
4647
```
4748
## Usage
4849

@@ -203,6 +204,52 @@ $vehEngines = LaravelVehapi::getEnginesByYearMakeModelTrimAndTransmission(2015,
203204
$vehEngines = json_encode(LaravelVehapi::getEnginesByYearMakeModelTrimAndTransmission(2015, 'Acura', 'MDX', 'FWD', '6-Speed Automatic'));
204205
```
205206

207+
Let's get all the wheel options available for a specific year, make, model, trim, transmission & engine
208+
```php
209+
/**
210+
* Return wheels available for the year, make, model, transmission & engine supplied.
211+
*
212+
* @param int $year
213+
* @param string $make
214+
* @param string $model
215+
* @param string $trim
216+
* @param string $transmission
217+
* @param string $engine
218+
*
219+
* @return mixed
220+
*/
221+
LaravelVehapi::getWheelsByYearMakeModelTrimTransmissionAndEngine($year, $make, $model, $trim, $transmission, $engine);
222+
223+
// Returns associative array
224+
$vehWheels = LaravelVehapi::getWheelsByYearMakeModelTrimTransmissionAndEngine(2021, 'Acura', 'TLX', 'FWD', '10-Speed Automatic', '2.0L 272 hp I4');
225+
226+
// Convert array to json format
227+
$vehWheels = json_encode(LaravelVehapi::getWheelsByYearMakeModelTrimTransmissionAndEngine(2021, 'Acura', 'TLX', 'FWD', '10-Speed Automatic', '2.0L 272 hp I4'));
228+
```
229+
230+
Let's get all the vehicle options available for a specific year, make, model, trim, transmission & engine
231+
```php
232+
/**
233+
* Return options available for the year, make, model, transmission & engine supplied.
234+
*
235+
* @param int $year
236+
* @param string $make
237+
* @param string $model
238+
* @param string $trim
239+
* @param string $transmission
240+
* @param string $engine
241+
*
242+
* @return mixed
243+
*/
244+
LaravelVehapi::getOptionsByYearMakeModelTrimTransmissionAndEngine($year, $make, $model, $trim, $transmission, $engine);
245+
246+
// Returns associative array
247+
$vehOptions = LaravelVehapi::getOptionsByYearMakeModelTrimTransmissionAndEngine(2021, 'Acura', 'TLX', 'FWD', '10-Speed Automatic', '2.0L 272 hp I4');
248+
249+
// Convert array to json format
250+
$vehOptions = json_encode(LaravelVehapi::getOptionsByYearMakeModelTrimTransmissionAndEngine(2021, 'Acura', 'TLX', 'FWD', '10-Speed Automatic', '2.0L 272 hp I4'));
251+
```
252+
206253
### Changelog
207254

208255
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
@@ -216,7 +263,6 @@ If you discover any security related issues, please email dev@codebyray.com inst
216263
## Credits
217264

218265
- [CodebyRay](https://github.com/codebyray)
219-
- [All Contributors](../../contributors)
220266

221267
## License
222268

‎config/config.php

+5
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
* Changing versions is easy, just change the version number below to switch between versions.
1616
*/
1717
'veh_api_version' => env('VEH_API_VERSION', 'v1'),
18+
19+
/**
20+
* Verify SSL cert. You should keep this as false if you are developing and testing locally.
21+
*/
22+
'veh_check_ssl_cert' => env('VEH_CHECK_SSL_CERT', true),
1823
];

‎src/LaravelVehapi.php

+98-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __construct()
2323
{
2424
$this->vehApiToken = config('laravel-vehapi.veh_api_token', null);
2525
$this->vehApiVersion = config('laravel-vehapi.veh_api_version', null);
26+
$this->vehCheckSslCert = config('laravel-vehapi.veh_check_ssl_cert', true);
2627
}
2728

2829
/**
@@ -34,7 +35,11 @@ public function __construct()
3435
*/
3536
public function getAllYears($sort = 'asc')
3637
{
37-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/years/'.$sort), true);
38+
return json_decode(Http::withOptions([
39+
'verify' => $this->vehCheckSslCert
40+
])
41+
->withToken($this->vehApiToken)
42+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/years/'.$sort), true);
3843
}
3944

4045
/**
@@ -48,7 +53,11 @@ public function getAllYears($sort = 'asc')
4853
*/
4954
public function getYearsRange(int $minYear, int $maxYear, $sort = 'asc')
5055
{
51-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/range/years/'.$minYear.'/'.$maxYear.'/'.$sort), true);
56+
return json_decode(Http::withOptions([
57+
'verify' => $this->vehCheckSslCert
58+
])
59+
->withToken($this->vehApiToken)
60+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/range/years/'.$minYear.'/'.$maxYear.'/'.$sort), true);
5261
}
5362

5463
/**
@@ -60,7 +69,11 @@ public function getYearsRange(int $minYear, int $maxYear, $sort = 'asc')
6069
*/
6170
public function getAllMakes($sort = 'asc')
6271
{
63-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/all/car/makes/'.$sort), true);
72+
return json_decode(Http::withOptions([
73+
'verify' => $this->vehCheckSslCert
74+
])
75+
->withToken($this->vehApiToken)
76+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/all/car/makes/'.$sort), true);
6477
}
6578

6679
/**
@@ -73,7 +86,11 @@ public function getAllMakes($sort = 'asc')
7386
*/
7487
public function getMakesByYear(int $year, $sort = 'asc')
7588
{
76-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/makes/'.$year.'/'.$sort), true);
89+
return json_decode(Http::withOptions([
90+
'verify' => $this->vehCheckSslCert
91+
])
92+
->withToken($this->vehApiToken)
93+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/makes/'.$year.'/'.$sort), true);
7794
}
7895

7996
/**
@@ -87,7 +104,11 @@ public function getMakesByYear(int $year, $sort = 'asc')
87104
*/
88105
public function getMakesByYearsRange(int $minYear, int $maxYear, $sort = 'asc')
89106
{
90-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/makes/in-range/'.$minYear.'/'.$maxYear.'/'.$sort), true);
107+
return json_decode(Http::withOptions([
108+
'verify' => $this->vehCheckSslCert
109+
])
110+
->withToken($this->vehApiToken)
111+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/makes/in-range/'.$minYear.'/'.$maxYear.'/'.$sort), true);
91112
}
92113

93114
/**
@@ -100,7 +121,11 @@ public function getMakesByYearsRange(int $minYear, int $maxYear, $sort = 'asc')
100121
*/
101122
public function getAllModelsByMake(string $make, $sort = 'asc')
102123
{
103-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/all/car/models/'.$make.'/'.$sort), true);
124+
return json_decode(Http::withOptions([
125+
'verify' => $this->vehCheckSslCert
126+
])
127+
->withToken($this->vehApiToken)
128+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/all/car/models/'.$make.'/'.$sort), true);
104129
}
105130

106131
/**
@@ -114,7 +139,11 @@ public function getAllModelsByMake(string $make, $sort = 'asc')
114139
*/
115140
public function getModelsByYearAndMake(int $year, string $make, $sort = 'asc')
116141
{
117-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/models/'.$year.'/'.$make.'/'.$sort), true);
142+
return json_decode(Http::withOptions([
143+
'verify' => $this->vehCheckSslCert
144+
])
145+
->withToken($this->vehApiToken)
146+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/models/'.$year.'/'.$make.'/'.$sort), true);
118147
}
119148

120149
/**
@@ -128,7 +157,11 @@ public function getModelsByYearAndMake(int $year, string $make, $sort = 'asc')
128157
*/
129158
public function getTrimsByYearMakeAndModel(int $year, string $make, string $model)
130159
{
131-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/trims/'.$year.'/'.$make.'/'.$model), true);
160+
return json_decode(Http::withOptions([
161+
'verify' => $this->vehCheckSslCert
162+
])
163+
->withToken($this->vehApiToken)
164+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/trims/'.$year.'/'.$make.'/'.$model), true);
132165
}
133166

134167
/**
@@ -143,7 +176,11 @@ public function getTrimsByYearMakeAndModel(int $year, string $make, string $mode
143176
*/
144177
public function getTransmissionsByYearMakeModelAndTrim(int $year, string $make, string $model, string $trim)
145178
{
146-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/transmissions/'.$year.'/'.$make.'/'.$model.'/'.$trim), true);
179+
return json_decode(Http::withOptions([
180+
'verify' => $this->vehCheckSslCert
181+
])
182+
->withToken($this->vehApiToken)
183+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/transmissions/'.$year.'/'.$make.'/'.$model.'/'.$trim), true);
147184
}
148185

149186
/**
@@ -159,7 +196,53 @@ public function getTransmissionsByYearMakeModelAndTrim(int $year, string $make,
159196
*/
160197
public function getEnginesByYearMakeModelTrimAndTransmission(int $year, string $make, string $model, string $trim, string $transmission)
161198
{
162-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/engines/'.$year.'/'.$make.'/'.$model.'/'.$trim.'/'.$transmission), true);
199+
return json_decode(Http::withOptions([
200+
'verify' => $this->vehCheckSslCert
201+
])
202+
->withToken($this->vehApiToken)
203+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/engines/'.$year.'/'.$make.'/'.$model.'/'.$trim.'/'.$transmission), true);
204+
}
205+
206+
/**
207+
* Return options available for the year, make, model, transmission & engine supplied.
208+
*
209+
* @param int $year
210+
* @param string $make
211+
* @param string $model
212+
* @param string $trim
213+
* @param string $transmission
214+
* @param string $engine
215+
*
216+
* @return mixed
217+
*/
218+
public function getOptionsByYearMakeModelTrimTransmissionAndEngine(int $year, string $make, string $model, string $trim, string $transmission, string $engine)
219+
{
220+
return json_decode(Http::withOptions([
221+
'verify' => $this->vehCheckSslCert
222+
])
223+
->withToken($this->vehApiToken)
224+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/options/'.$year.'/'.$make.'/'.$model.'/'.$trim.'/'.$transmission.'/'.$engine), true);
225+
}
226+
227+
/**
228+
* Return wheels available for the year, make, model, transmission & engine supplied.
229+
*
230+
* @param int $year
231+
* @param string $make
232+
* @param string $model
233+
* @param string $trim
234+
* @param string $transmission
235+
* @param string $engine
236+
*
237+
* @return mixed
238+
*/
239+
public function getWheelsByYearMakeModelTrimTransmissionAndEngine(int $year, string $make, string $model, string $trim, string $transmission, string $engine)
240+
{
241+
return json_decode(Http::withOptions([
242+
'verify' => $this->vehCheckSslCert
243+
])
244+
->withToken($this->vehApiToken)
245+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-lists/get/car/wheels/'.$year.'/'.$make.'/'.$model.'/'.$trim.'/'.$transmission.'/'.$engine), true);
163246
}
164247

165248
/**
@@ -171,6 +254,10 @@ public function getEnginesByYearMakeModelTrimAndTransmission(int $year, string $
171254
*/
172255
public function getMakeLogo(string $make)
173256
{
174-
return json_decode(Http::withToken($this->vehApiToken)->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-logos/img/'.$make), true);
257+
return json_decode(Http::withOptions([
258+
'verify' => $this->vehCheckSslCert
259+
])
260+
->withToken($this->vehApiToken)
261+
->get('https://vehapi.com/api/'.$this->vehApiVersion.'/car-logos/img/'.$make), true);
175262
}
176263
}

0 commit comments

Comments
 (0)
Please sign in to comment.