Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Blazek committed Jun 2, 2016
1 parent f1090f8 commit 04d5e7b
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 64 deletions.
10 changes: 8 additions & 2 deletions API/OpenWeatherMap/Weather/AirPollutionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ interface AirPollutionInterface
* @param float $longitude
* @param \DateTime|string $datetime
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchOzoneData($latitude, $longitude, $datetime = 'current');

Expand All @@ -31,7 +34,10 @@ public function fetchOzoneData($latitude, $longitude, $datetime = 'current');
* @param float $longitude
* @param \DateTime|string $datetime
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchCarbonMonoxideData($latitude, $longitude, $datetime = 'current');
}
15 changes: 12 additions & 3 deletions API/OpenWeatherMap/Weather/DailyForecastInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ interface DailyForecastInterface
* @param string $countryCode
* @param int $numberOfDays
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityName($cityName, $countryCode = '', $numberOfDays = 16);

Expand All @@ -30,7 +33,10 @@ public function fetchForecastByCityName($cityName, $countryCode = '', $numberOfD
* @param int $cityId
* @param int $numberOfDays
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityId($cityId, $numberOfDays = 16);

Expand All @@ -41,7 +47,10 @@ public function fetchForecastByCityId($cityId, $numberOfDays = 16);
* @param float $longitude
* @param int $numberOfDays
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays = 16);
}
15 changes: 12 additions & 3 deletions API/OpenWeatherMap/Weather/HourForecastInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ interface HourForecastInterface
* @param string $cityName
* @param string $countryCode
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityName($cityName, $countryCode = '');

Expand All @@ -28,7 +31,10 @@ public function fetchForecastByCityName($cityName, $countryCode = '');
*
* @param int $cityId
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityId($cityId);

Expand All @@ -38,7 +44,10 @@ public function fetchForecastByCityId($cityId);
* @param float $latitude
* @param float $longitude
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchForecastByCityGeographicCoordinates($latitude, $longitude);
}
5 changes: 4 additions & 1 deletion API/OpenWeatherMap/Weather/UltravioletIndexInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ interface UltravioletIndexInterface
* @param float $longitude
* @param \Datetime|string $datetime
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchUltraviletIndex($latitude, $longitude, $datetime = 'current');
}
39 changes: 30 additions & 9 deletions API/OpenWeatherMap/Weather/WeatherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ interface WeatherInterface
* @param string $cityName
* @param string $countryCode
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataByCityName($cityName, $countryCode = '');

Expand All @@ -28,17 +31,23 @@ public function fetchWeatherDataByCityName($cityName, $countryCode = '');
*
* @param int $cityId
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataByCityId($cityId);

/**
* Call current weather data for one location by geographic coordinates
*
* @param int $latitude
* @param int $longitude
* @param float $latitude
* @param float $longitude
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataByGeographicCoordinates($latitude, $longitude);

Expand All @@ -49,7 +58,10 @@ public function fetchWeatherDataByGeographicCoordinates($latitude, $longitude);
* @param int $zipCode
* @param string $countryCode
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataByZipCode($zipCode, $countryCode = '');

Expand All @@ -59,7 +71,10 @@ public function fetchWeatherDataByZipCode($zipCode, $countryCode = '');
* @param array $boundingBox Longitude-left,latitude-bottom,longitude-right,latitude-top
* @param string $cluster
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataForCitiesWithinRectangleZone(array $boundingBox, $cluster = 'yes');

Expand All @@ -71,7 +86,10 @@ public function fetchWeatherDataForCitiesWithinRectangleZone(array $boundingBox,
* @param string $cluster
* @param int $numberOfCities
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataForCitiesInCycle($latitude, $longitude, $cluster = 'yes', $numberOfCities = 10);

Expand All @@ -80,7 +98,10 @@ public function fetchWeatherDataForCitiesInCycle($latitude, $longitude, $cluster
*
* @param array $cities
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchWeatherDataForSeveralCityIds(array $cities);
}
15 changes: 12 additions & 3 deletions API/OpenWeatherMap/Weather/WeatherStationsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ interface WeatherStationsInterface
*
* @param int $stationId
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchFromOnStationById($stationId);

Expand All @@ -29,7 +32,10 @@ public function fetchFromOnStationById($stationId);
* @param string $cluster
* @param int $numberOfStations
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchFromSeveralByRectangleZone(array $boundingBox, $cluster = 'yes', $numberOfStations = 10);

Expand All @@ -40,7 +46,10 @@ public function fetchFromSeveralByRectangleZone(array $boundingBox, $cluster = '
* @param float $longitude
* @param int $numberOfStations
*
* @return mixed
* @return string
*
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException
* @throws \Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException
*/
public function fetchFromSeveralByGeoPoint($latitude, $longitude, $numberOfStations = 10);
}
28 changes: 24 additions & 4 deletions Controller/AirPollutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;

use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\AirPollutionInterface;
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
use Symfony\Component\HttpFoundation\Response;
use DateTime;

Expand Down Expand Up @@ -47,9 +49,18 @@ public function getOzoneData($latitude, $longitude, $datetime = 'current')
}
}

$data = $this->airPollution->fetchOzoneData($latitude, $longitude, $datetime);
$response = new Response();

return new Response($data);
try {
$data = $this->airPollution->fetchOzoneData($latitude, $longitude, $datetime);
$response->setContent($data);
} catch (NotAuthorizedException $e) {
$response->setContent($e->getMessage());
} catch (NotFoundException $e) {
$response->setContent($e->getMessage());
}

return $response;
}

/**
Expand All @@ -71,9 +82,18 @@ public function getCarbonMonoxideData($latitude, $longitude, $datetime = 'curren
$datetime = 'current';
}
}

$response = new Response();

$data = $this->airPollution->fetchCarbonMonoxideData($latitude, $longitude, $datetime);
try {
$data = $this->airPollution->fetchCarbonMonoxideData($latitude, $longitude, $datetime);
$response->setContent($data);
} catch (NotAuthorizedException $e) {
$response->setContent($e->getMessage());
} catch (NotFoundException $e) {
$response->setContent($e->getMessage());
}

return new Response($data);
return $response;
}
}
41 changes: 35 additions & 6 deletions Controller/DailyForecastController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;

use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\DailyForecastInterface;
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -37,9 +39,18 @@ public function __construct(DailyForecastInterface $dailyForecast)
*/
public function getForecastByCityName($cityName, $numberOfDays = 16, $countryCode = '')
{
$data = $this->dailyForecast->fetchForecastByCityName($cityName, $countryCode, $numberOfDays);
$response = new Response();

return new Response($data);
try {
$data = $this->dailyForecast->fetchForecastByCityName($cityName, $countryCode, $numberOfDays);
$response->setContent($data);
} catch (NotAuthorizedException $e) {
$response->setContent($e->getMessage());
} catch (NotFoundException $e) {
$response->setContent($e->getMessage());
}

return $response;
}

/**
Expand All @@ -52,9 +63,18 @@ public function getForecastByCityName($cityName, $numberOfDays = 16, $countryCod
*/
public function getForecastByCityId($cityId, $numberOfDays = 16)
{
$data = $this->dailyForecast->fetchForecastByCityId($cityId, $numberOfDays);
$response = new Response();

try {
$data = $this->dailyForecast->fetchForecastByCityId($cityId, $numberOfDays);
$response->setContent($data);
} catch (NotAuthorizedException $e) {
$response->setContent($e->getMessage());
} catch (NotFoundException $e) {
$response->setContent($e->getMessage());
}

return new Response($data);
return $response;
}

/**
Expand All @@ -68,8 +88,17 @@ public function getForecastByCityId($cityId, $numberOfDays = 16)
*/
public function getForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays = 16)
{
$data = $this->dailyForecast->fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays);
$response = new Response();

try {
$data = $this->dailyForecast->fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays);
$response->setContent($data);
} catch (NotAuthorizedException $e) {
$response->setContent($e->getMessage());
} catch (NotFoundException $e) {
$response->setContent($e->getMessage());
}

return new Response($data);
return $response;
}
}
Loading

0 comments on commit 04d5e7b

Please sign in to comment.