35 lines
795 B
PHP
35 lines
795 B
PHP
<?php
|
|
namespace ProVM\KI\Common\Service;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
class Indicadores {
|
|
//protected $cliente;
|
|
protected $base_uri;
|
|
|
|
public function __construct(string $indicadores_url) {
|
|
$this->base_uri = $indicadores_url;
|
|
}
|
|
public function get(string $indicador, \DateTime $fecha) {
|
|
$url = implode('/', [
|
|
$this->base_uri,
|
|
$indicador,
|
|
$fecha->format('d-m-Y')
|
|
]);
|
|
if ( ini_get('allow_url_fopen') ) {
|
|
$json = file_get_contents($url);
|
|
} else {
|
|
$curl = curl_init($url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
$json = curl_exec($curl);
|
|
curl_close($curl);
|
|
}
|
|
$data = json_decode($json);
|
|
$valor = 0;
|
|
if (isset($data->serie[0])) {
|
|
$valor = $data->serie[0]->valor;
|
|
}
|
|
return $valor;
|
|
}
|
|
}
|