Skip to content

Commit

Permalink
# Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Aagaard committed Jun 11, 2020
1 parent 2cd956d commit 9fd2463
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions routes/routes.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
<?php

use Illuminate\Support\Facades\Route;
use \aat2703\Weather\Weather;

Route::prefix('weather')->group(function() {

Route::get(
'',
function() {
return Weather::getWeather(request()->get('query'));
}
);
});
13 changes: 8 additions & 5 deletions src/Weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@

class Weather {

public static $owm;
protected static $owm;

public function __construct() {
self::$owm = new OpenWeatherMap(
config('weather.API_KEY'),
self::$owm = self::getOwm();
}

private static function getOwm() {
return self::$owm ? self::$owm : new OpenWeatherMap(
config('weather.api_key'),
GuzzleAdapter::createWithConfig([]),
new RequestFactory()
);
}

public static function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '') {
return self::$owm->getWeather($query, $units, $lang, $appid);
return self::getOwm()->getWeather($query, $units, $lang, $appid);
}

}

0 comments on commit 9fd2463

Please sign in to comment.