Skip to content

Commit 07386f7

Browse files
authored
Merge pull request #63 from programmatordev/OPA-58-weather-overview-resource
Weather overview endpoint
2 parents b2ef43e + 1a6205f commit 07386f7

File tree

17 files changed

+147
-17
lines changed

17 files changed

+147
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": ">=8.1",
1616
"myclabs/deep-copy": "^1.13",
17-
"programmatordev/php-api-sdk": "^2.0",
17+
"programmatordev/php-api-sdk": "^2.1",
1818
"symfony/options-resolver": "^6.4|^7.3"
1919
},
2020
"require-dev": {

docs/03-supported-apis.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [getWeather](#getweather)
66
- [getWeatherByDate](#getweatherbydate)
77
- [getWeatherSummaryByDate](#getweathersummarybydate)
8+
- [getWeatherOverviewByDate](#getweatheroverviewbydate)
89
- [Weather](#weather)
910
- [getCurrent](#getcurrent)
1011
- [getForecast](#getforecast)
@@ -68,6 +69,21 @@ Returns a [`WeatherSummary`](05-entities.md#weathersummary) object:
6869
$weatherSummary = $api->oneCall()->getWeatherSummaryByDate(50, 50, new \DateTime('1985-07-19'));
6970
```
7071

72+
#### `getWeatherOverviewByDate`
73+
74+
```php
75+
getWeatherOverviewByDate(float $latitude, float $longitude, \DateTimeInterface $date): WeatherOverview
76+
```
77+
78+
Get the weather overview with a human-readable summary for today and tomorrow's forecast,
79+
using OpenWeather AI.
80+
81+
Returns a [`WeatherOverview`](05-entities.md#weatheroverview) object:
82+
83+
```php
84+
$weatherOverview = $api->oneCall()->getWeatherOverviewByDate(50, 50, new \DateTime('today'));
85+
```
86+
7187
### Weather
7288

7389
#### `getCurrent`

docs/05-entities.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@
7878
- `getAtmosphericPressure()`: `int`
7979
- `getWind()`: [`Wind`](#wind)
8080

81+
### WeatherOverview
82+
83+
- `getCoordinate()`: [`Coordinate`](#coordinate)
84+
- `getTimezone()`: [`Timezone`](#timezone)
85+
- `getDateTime()`: `\DateTimeImmutable`
86+
- `getOverview()`: `string`
87+
8188
### WeatherData
8289

8390
- `getDateTime()`: `\DateTimeImmutable`

src/Entity/AirPollution/AirPollutionCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AirPollutionCollection
1818

1919
public function __construct(array $data)
2020
{
21-
$this->numResults = \count($data['list']);
21+
$this->numResults = count($data['list']);
2222
$this->coordinate = new Coordinate($data['coord']);
2323
$this->data = $this->createEntityList(AirPollutionData::class, $data['list']);
2424
}

src/Entity/AirPollution/AirQuality.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ private function findQualitativeName(int $index): string
2828
{
2929
// levels based on https://openweathermap.org/api/air-pollution
3030
return match ($index) {
31-
0 => 'Undefined',
3231
1 => 'Good',
3332
2 => 'Fair',
3433
3 => 'Moderate',
3534
4 => 'Poor',
36-
5 => 'Very Poor'
35+
5 => 'Very Poor',
36+
default => 'Undefined'
3737
};
3838
}
3939
}

src/Entity/OneCall/DayData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(array $data)
2828

2929
$this->temperature = new Temperature($data['temp']);
3030
$this->temperatureFeelsLike = new Temperature($data['feels_like']);
31-
$this->precipitationProbability = \round($data['pop'] * 100);
31+
$this->precipitationProbability = round($data['pop'] * 100);
3232
$this->summary = $data['summary'];
3333
$this->moonPhase = new MoonPhase($data);
3434
$this->moonriseAt = \DateTimeImmutable::createFromFormat('U', $data['moonrise']);

src/Entity/OneCall/HourData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(array $data)
1919
$this->temperature = $data['temp'];
2020
$this->temperatureFeelsLike = $data['feels_like'];
2121
$this->visibility = $data['visibility'];
22-
$this->precipitationProbability = \round($data['pop'] * 100);
22+
$this->precipitationProbability = round($data['pop'] * 100);
2323
}
2424

2525
public function getTemperature(): float

src/Entity/OneCall/MoonPhase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(array $data)
2323
{
2424
$this->value = $data['moon_phase'];
2525
$this->systemName = $this->findSystemName($this->value);
26-
$this->name = \ucwords(\strtolower(\str_replace('_', ' ', $this->systemName)));
26+
$this->name = ucwords(strtolower(str_replace('_', ' ', $this->systemName)));
2727
}
2828

2929
public function getValue(): float
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Entity\OneCall;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\Timezone;
7+
8+
class WeatherOverview
9+
{
10+
private Coordinate $coordinate;
11+
12+
private Timezone $timezone;
13+
14+
private \DateTimeImmutable $dateTime;
15+
16+
private string $overview;
17+
18+
public function __construct(array $data)
19+
{
20+
$this->coordinate = new Coordinate($data);
21+
22+
$this->timezone = new Timezone([
23+
'timezone_offset' => \DateTimeImmutable::createFromFormat('P', $data['tz'])->getOffset()
24+
]);
25+
26+
$this->dateTime = \DateTimeImmutable::createFromFormat(
27+
'Y-m-d H:i:s P',
28+
sprintf('%s 00:00:00 %s', $data['date'], $data['tz'])
29+
);
30+
31+
$this->overview = $data['weather_overview'];
32+
}
33+
34+
public function getCoordinate(): Coordinate
35+
{
36+
return $this->coordinate;
37+
}
38+
39+
public function getTimezone(): Timezone
40+
{
41+
return $this->timezone;
42+
}
43+
44+
public function getDateTime(): \DateTimeImmutable
45+
{
46+
return $this->dateTime;
47+
}
48+
49+
public function getOverview(): string
50+
{
51+
return $this->overview;
52+
}
53+
}

src/Entity/OneCall/WeatherSummary.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(array $data)
3636

3737
$this->dateTime = \DateTimeImmutable::createFromFormat(
3838
'Y-m-d H:i:s P',
39-
\sprintf('%s 00:00:00 %s', $data['date'], $data['tz'])
39+
sprintf('%s 00:00:00 %s', $data['date'], $data['tz'])
4040
);
4141

4242
$this->cloudiness = \round($data['cloud_cover']['afternoon']);
@@ -52,11 +52,11 @@ public function __construct(array $data)
5252
'max' => $data['temperature']['max']
5353
]);
5454

55-
$this->atmosphericPressure = \round($data['pressure']['afternoon']);
55+
$this->atmosphericPressure = round($data['pressure']['afternoon']);
5656

5757
$this->wind = new Wind([
5858
'speed' => $data['wind']['max']['speed'],
59-
'deg' => \round($data['wind']['max']['direction'])
59+
'deg' => round($data['wind']['max']['direction'])
6060
]);
6161
}
6262

@@ -70,9 +70,6 @@ public function getTimezone(): Timezone
7070
return $this->timezone;
7171
}
7272

73-
/**
74-
* DateTime in UTC
75-
*/
7673
public function getDateTime(): \DateTimeImmutable
7774
{
7875
return $this->dateTime;

0 commit comments

Comments
 (0)