public function update($urlApi = null)
{
if (is_null($urlApi)) {
$urlApi = 'http://api.openweathermap.org/data/2.5/weather?q=Sao_Paulo,br&units=metric&APPID=' . getenv('WEATHER_APPID');
}
$json = file_get_contents($urlApi);
$response = json_decode($json);
$data = $response->main;
$data->updated_at = Carbon::now()->toDateTimeString();
Cache::forever('Weather.reads', $data);
return $data;
}
public function testCache() { $json_test = basename(dirname(__DIR__)) . '/_data/weather_test.json'; $api = new WeatherApi(); $api->update($json_test); $update_date1 = $api->data()->updated_at; $api2 = new WeatherApi(); $update_date2 = $api2->data()->updated_at; $this->assertEquals($update_date1, $update_date2); }