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; } }