Skip to content

Commit

Permalink
Se agregó la consulta vehicular
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Vidal committed Sep 22, 2020
2 parents e574d90 + 548d768 commit c79db46
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"consultar",
"consulta dni",
"consulta ruc",
"consulta sunarp",
"consulta vehicular",
"consulta dni sin codigo captcha",
"consulta ruc sin codigo captcha",
"captcha",
Expand Down
9 changes: 9 additions & 0 deletions src/Consulta.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Consulta\Laravel\Exceptions\UndefinedErrorException;
use Consulta\Laravel\Lib\DNI;
use Consulta\Laravel\Lib\RUC;
use Consulta\Laravel\Lib\Vehicle;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Config\Repository;
Expand Down Expand Up @@ -34,6 +35,14 @@ public static function reniec(): DNI
return new DNI();
}

/**
* @return Vehicle
*/
public static function vehicle(): Vehicle
{
return new Vehicle();
}

/**
* @return Repository|mixed
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Exceptions/InvalidPlateException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Consulta\Laravel\Exceptions;

/**
* Class InvalidPlateException
* @package Consulta\Laravel\Exceptions
*/
class InvalidPlateException extends \Exception
{
protected $message = 'Plate number seems not to be valid.';
}
43 changes: 43 additions & 0 deletions src/Lib/Vehicle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Consulta\Laravel\Lib;

use Consulta\Laravel\Consulta;
use Consulta\Laravel\Exceptions\InvalidPlateException;
use Illuminate\Support\Facades\Validator;

/**
* Class Vehicle
* @package Consulta\Laravel
*/
class Vehicle extends Consulta
{

/**
* @param $plate
* @return mixed
* @throws InvalidPlateException
* @throws \Consulta\Laravel\Exceptions\ServerErrorException
* @throws \Consulta\Laravel\Exceptions\UnauthenticatedException
* @throws \Consulta\Laravel\Exceptions\UndefinedErrorException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function find($plate)
{
if (!$this->validatePlate($plate)) {
throw new InvalidPlateException();
}

return $this->execute('api/sunarp/vehicle', ['plate' => $plate]);
}

/**
* @param $plate
* @return bool
*/
public function validatePlate($plate)
{
$validator = Validator::make(['plate' => $plate], ['plate' => 'required|alpha|size:6']);
return !$validator->fails();
}
}

0 comments on commit c79db46

Please sign in to comment.