app\WeatherApi::update PHP 메소드

update() 공개 메소드

public update ( $urlApi = null )
    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;
    }

Usage Example

예제 #1
0
 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);
 }
All Usage Examples Of app\WeatherApi::update
WeatherApi