Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Vidal committed Sep 7, 2016
0 parents commit a591449
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "tecactus/reniec-php",
"description": "RENIEC package for PHP",
"keywords": [
"reniec",
"php",
"dni",
"validar",
"validate",
"consultar",
"consulta dni",
"consulta dni sin codigo captcha",
"captcha"
],
"license": "MIT",
"authors": [
{
"name": "Paul Vidal",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.2"
},
"autoload": {
"psr-4": {
"Tecactus\\Reniec\\": "src/"
}
}
}
51 changes: 51 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# RENIEC-PHP

## Instalación

Instalar usando composer:

```bash
composer require tecactus/reniec-php

```

O agregar la siguiente línea a tu archivo composer.json:

```json
"require": {
...
"tecactus/reniec-php": "1.*"
...
}
```

## Uso

```php
// incluir el autoloader de vendor
require 'vendor/autoload.php';

//crea un objeto de la clase DNI
$reniecDni = new Tecactus\Reniec\DNI('tu-token-de-acceso-personal');

print_r($reniecDni->get('12345678'));

// para devolver el resultado como un array pasar 'true' como segundo argumento.
print_r($reniecDni->get('20131312955', true));

```

## Token de Acceso Personal

Para crear tokens de acceso personal debes de iniciar sesión en Tecactus:

[https://tecactus.com/auth/login](https://tecactus.com/auth/login)

Si no estas registrado aún, puedes hacerlo en:

[https://tecactus.com/auth/register](https://tecactus.com/auth/register)

Debes de activar tu cuenta si aún no lo has hecho.
Luego ver el panel de gestión de Tokens de acceso en:

[https://tecactus.com/developers/configuracion/tokens](https://tecactus.com/developers/configuracion/tokens)
40 changes: 40 additions & 0 deletions src/DNI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tecactus\Reniec;


use GuzzleHttp\Client;
use Tecactus\Reniec\Exception\InvalidDniException;

class DNI
{
protected $client;
protected $baseUri;
protected $apiToken;

public function __construct($apiToken)
{
$this->baseUri = "https://tecactus.com/";
$this->apiToken = $apiToken;
$this->client = new Client(['base_uri' => $this->baseUri, 'headers' => ['Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->apiToken]]);
}

public function get($dni, $asArray = false)
{
if (!$this->validate($dni)) {
throw new InvalidDniException('DNI number seems not to be valid.');
}
$response = $this->client->request('POST', 'api/reniec/dni', ['query' => [
'dni' => $dni
]]);
return json_decode($response->getBody()->getContents(), $asArray);
}

protected function validate($value)
{
if (is_numeric($value)) {
return strlen($value) == 8;
}
return false;
}
}
8 changes: 8 additions & 0 deletions src/Exception/InvalidDniException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Tecactus\Reniec\Exception;

class InvalidDniException extends \Exception
{
//
}

0 comments on commit a591449

Please sign in to comment.