Version produccion
This commit is contained in:
37
src/UF/Handler.php
Normal file
37
src/UF/Handler.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Aldarien\Money\UF;
|
||||
|
||||
use Aldarien\Money\Common\Implementation\Handler as BaseHandler;
|
||||
|
||||
class Handler extends BaseHandler {
|
||||
protected $history;
|
||||
public function get(\DateTime $date) {
|
||||
if ($this->history === null or !isset($this->history[$date->format('Y-m-d')])) {
|
||||
$response = $this->client->request('GET', implode('/', [
|
||||
$this->url,
|
||||
$date->format('d-m-Y')
|
||||
]), ['verify' => false]);
|
||||
/*
|
||||
{
|
||||
"version": "1.6.0",
|
||||
"autor": "mindicador.cl",
|
||||
"codigo": "uf",
|
||||
"nombre": "Unidad de fomento (UF)",
|
||||
"unidad_medida": "Pesos",
|
||||
"serie": [
|
||||
{
|
||||
"fecha": "2020-04-08T04:00:00.000Z",
|
||||
"valor": 28626.94
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
if ($response->getStatusCode() < 200 or $response->getStatusCode() >= 300) {
|
||||
$this->history[$date->format('Y-m-d')] = false;
|
||||
return false;
|
||||
}
|
||||
$this->history[$date->format('Y-m-d')] = json_decode($response->getBody())->serie[0]->valor;
|
||||
}
|
||||
return $this->history[$date->format('Y-m-d')];
|
||||
}
|
||||
}
|
||||
21
src/UF/Model.php
Normal file
21
src/UF/Model.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Aldarien\Money\UF;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Aldarien\Common\Alias\Model as ModelAlias;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property \DateTime $date
|
||||
* @property double $value
|
||||
*/
|
||||
class Model extends ModelAlias {
|
||||
public static $_table = 'ufs';
|
||||
|
||||
public function date(\DateTime $date = null) {
|
||||
if ($date === null) {
|
||||
return Carbon::parse($this->date);
|
||||
}
|
||||
$this->date = $date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user