Skip to content

Commit 80c1d3b

Browse files
author
Mario Blazek
committed
Full implementation
1 parent 293839e commit 80c1d3b

8 files changed

Lines changed: 370 additions & 17 deletions

Controller/AirPollutionController.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\AirPollutionInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use DateTime;
78

89
/**
910
* Class AirPollutionController
1011
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1112
*/
12-
class AirPollutionController extends Controller
13+
class AirPollutionController
1314
{
1415
/**
1516
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\AirPollutionInterface
@@ -25,4 +26,54 @@ public function __construct(AirPollutionInterface $airPollution)
2526
{
2627
$this->airPollution = $airPollution;
2728
}
29+
30+
/**
31+
* Returns ozone data
32+
*
33+
* @param float $latitude
34+
* @param float $longitude
35+
* @param string $datetime ISO 8601 date string
36+
*
37+
* @return \Symfony\Component\HttpFoundation\Response
38+
*/
39+
public function getOzoneData($latitude, $longitude, $datetime = 'current')
40+
{
41+
if ($datetime !== 'current') {
42+
43+
$datetime = DateTime::createFromFormat('c', $datetime);
44+
45+
if ($datetime === false) {
46+
$datetime = 'current';
47+
}
48+
}
49+
50+
$data = $this->airPollution->fetchOzoneData($latitude, $longitude, $datetime);
51+
52+
return new Response($data);
53+
}
54+
55+
/**
56+
* Returns carbon monoxide data
57+
*
58+
* @param float $latitude
59+
* @param float $longitude
60+
* @param string $datetime ISO 8601 date string
61+
*
62+
* @return \Symfony\Component\HttpFoundation\Response
63+
*/
64+
public function getCarbonMonoxideData($latitude, $longitude, $datetime = 'current')
65+
{
66+
if ($datetime !== 'current') {
67+
68+
$datetime = DateTime::createFromFormat('c', $datetime);
69+
70+
if ($datetime === false) {
71+
$datetime = 'current';
72+
}
73+
}
74+
75+
$data = $this->airPollution->fetchCarbonMonoxideData($latitude, $longitude, $datetime);
76+
77+
return new Response($data);
78+
}
2879
}

Controller/DailyForecastController.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\DailyForecastInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
77

88
/**
99
* Class DailyForecastController
1010
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1111
*/
12-
class DailyForecastController extends Controller
12+
class DailyForecastController
1313
{
1414
/**
1515
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\DailyForecastInterface
@@ -25,4 +25,51 @@ public function __construct(DailyForecastInterface $dailyForecast)
2525
{
2626
$this->dailyForecast = $dailyForecast;
2727
}
28+
29+
/**
30+
* Returns daily forecast by city name
31+
*
32+
* @param string $cityName
33+
* @param int $numberOfDays
34+
* @param string $countryCode
35+
*
36+
* @return \Symfony\Component\HttpFoundation\Response
37+
*/
38+
public function getForecastByCityName($cityName, $numberOfDays = 16, $countryCode = '')
39+
{
40+
$data = $this->dailyForecast->fetchForecastByCityName($cityName, $countryCode, $numberOfDays);
41+
42+
return new Response($data);
43+
}
44+
45+
/**
46+
* Returns daily forecast by city id
47+
*
48+
* @param int $cityId
49+
* @param int $numberOfDays
50+
*
51+
* @return \Symfony\Component\HttpFoundation\Response
52+
*/
53+
public function getForecastByCityId($cityId, $numberOfDays = 16)
54+
{
55+
$data = $this->dailyForecast->fetchForecastByCityId($cityId, $numberOfDays);
56+
57+
return new Response($data);
58+
}
59+
60+
/**
61+
* Returns daily forecast by geographic coordinates
62+
*
63+
* @param float $latitude
64+
* @param float $longitude
65+
* @param int $numberOfDays
66+
*
67+
* @return \Symfony\Component\HttpFoundation\Response
68+
*/
69+
public function getForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays = 16)
70+
{
71+
$data = $this->dailyForecast->fetchForecastByCityGeographicCoordinates($latitude, $longitude, $numberOfDays);
72+
73+
return new Response($data);
74+
}
2875
}

Controller/HourForecastController.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\HourForecastInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
77

88
/**
99
* Class HourForecastController
1010
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1111
*/
12-
class HourForecastController extends Controller
12+
class HourForecastController
1313
{
1414
/**
1515
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\HourForecastInterface
@@ -25,4 +25,48 @@ public function __construct(HourForecastInterface $hourForecast)
2525
{
2626
$this->hourForecast = $hourForecast;
2727
}
28+
29+
/**
30+
* Returns hour forecast by city name
31+
*
32+
* @param string $cityName
33+
* @param string $countryCode
34+
*
35+
* @return \Symfony\Component\HttpFoundation\Response
36+
*/
37+
public function getForecastByCityName($cityName, $countryCode = '')
38+
{
39+
$data = $this->hourForecast->fetchForecastByCityName($cityName, $countryCode);
40+
41+
return new Response($data);
42+
}
43+
44+
/**
45+
* Returns hour forecast by city id
46+
*
47+
* @param int $cityId
48+
*
49+
* @return \Symfony\Component\HttpFoundation\Response
50+
*/
51+
public function getForecastByCityId($cityId)
52+
{
53+
$data = $this->hourForecast->fetchForecastByCityId($cityId);
54+
55+
return new Response($data);
56+
}
57+
58+
/**
59+
* Returns hour forecast by geographic coordinates
60+
*
61+
* @param float $latitude
62+
* @param float $longitude
63+
*
64+
* @return \Symfony\Component\HttpFoundation\Response
65+
*/
66+
public function getForecastByCityGeographicCoordinates($latitude, $longitude)
67+
{
68+
$data = $this->hourForecast->fetchForecastByCityName($latitude, $longitude);
69+
70+
return new Response($data);
71+
}
2872
}

Controller/UltravioletIndexController.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\UltravioletIndexInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use DateTime;
78

89
/**
910
* Class UltravioletIndexController
1011
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1112
*/
12-
class UltravioletIndexController extends Controller
13+
class UltravioletIndexController
1314
{
1415
/**
1516
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\UltravioletIndexInterface
@@ -25,4 +26,29 @@ public function __construct(UltravioletIndexInterface $ultravioletIndex)
2526
{
2627
$this->ultravioletIndex = $ultravioletIndex;
2728
}
29+
30+
/**
31+
* Returns ultraviolet index
32+
*
33+
* @param float $latitude
34+
* @param float $longitude
35+
* @param string $datetime ISO 8601 date string
36+
*
37+
* @return \Symfony\Component\HttpFoundation\Response
38+
*/
39+
public function getUltravioletIndex($latitude, $longitude, $datetime = 'current')
40+
{
41+
if ($datetime !== 'current') {
42+
43+
$datetime = DateTime::createFromFormat('c', $datetime);
44+
45+
if ($datetime === false) {
46+
$datetime = 'current';
47+
}
48+
}
49+
50+
$data = $this->ultravioletIndex->fetchUltraviletIndex($latitude, $longitude, $datetime);
51+
52+
return new Response($data);
53+
}
2854
}

Controller/WeatherController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
76
use Symfony\Component\HttpFoundation\Request;
87
use Symfony\Component\HttpFoundation\Response;
98

109
/**
1110
* Class WeatherController
1211
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1312
*/
14-
class WeatherController extends Controller
13+
class WeatherController
1514
{
1615
/**
1716
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherInterface

Controller/WeatherStationsController.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Netgen\Bundle\OpenWeatherMapBundle\Controller;
44

55
use Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherStationsInterface;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
77

88
/**
99
* Class WeatherStationsController
1010
* @package Netgen\Bundle\OpenWeatherMapBundle\Controller
1111
*/
12-
class WeatherStationsController extends Controller
12+
class WeatherStationsController
1313
{
1414
/**
1515
* @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\WeatherStationsInterface
@@ -25,4 +25,58 @@ public function __construct(WeatherStationsInterface $weatherStations)
2525
{
2626
$this->weatherStations = $weatherStations;
2727
}
28+
29+
/**
30+
* Returns data from one stations by station id
31+
*
32+
* @param int $stationId
33+
*
34+
* @return \Symfony\Component\HttpFoundation\Response
35+
*/
36+
public function getFromOnStationById($stationId)
37+
{
38+
$data = $this->weatherStations->fetchFromOnStationById($stationId);
39+
40+
return new Response($data);
41+
}
42+
43+
/**
44+
* Returns data from several stations by rectangle zone
45+
*
46+
* @param float $longitudeTopLeft
47+
* @param float $latitudeTopLeft
48+
* @param float $longitudeBottomRight
49+
* @param float $latitudeBottomRight
50+
* @param int $mapZoom
51+
* @param string $cluster
52+
* @param int $numberOfStations
53+
*
54+
* @return \Symfony\Component\HttpFoundation\Response
55+
*/
56+
public function getFromSeveralByRectangleZone($longitudeTopLeft, $latitudeTopLeft, $longitudeBottomRight, $latitudeBottomRight, $mapZoom, $cluster = 'yes', $numberOfStations = 10)
57+
{
58+
$boundingBox = array(
59+
$longitudeTopLeft, $latitudeTopLeft, $longitudeBottomRight, $latitudeBottomRight, $mapZoom
60+
);
61+
62+
$data = $this->weatherStations->fetchFromSeveralByRectangleZone($boundingBox, $cluster, $numberOfStations);
63+
64+
return new Response($data);
65+
}
66+
67+
/**
68+
* Returns data from several stations by geo point
69+
*
70+
* @param float $latitude
71+
* @param float $longitude
72+
* @param int $numberOfStations
73+
*
74+
* @return \Symfony\Component\HttpFoundation\Response
75+
*/
76+
public function getFromSeveralByGeoPoint($latitude, $longitude, $numberOfStations = 10)
77+
{
78+
$data = $this->weatherStations->fetchFromSeveralByGeoPoint($latitude, $longitude, $numberOfStations);
79+
80+
return new Response($data);
81+
}
2882
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Implemented features
77
--------------------
88

99
* Current weather data
10-
* 5 day / 3 hour forecast (in progress)
11-
* 16 day / daily forecast (in progress)
12-
* UV Index (in progress)
13-
* Weather stations (in progress)
14-
* Air pollution (in progress)
10+
* 5 day / 3 hour forecast
11+
* 16 day / daily forecast
12+
* UV Index
13+
* Weather stations
14+
* Air pollution
1515

1616
License, docs and installation instructions
1717
-------------------------------------

0 commit comments

Comments
 (0)