Skip to content

Commit 898b88b

Browse files
committed
feat: added one call resource
1 parent fd3b159 commit 898b88b

18 files changed

+463
-688
lines changed

Diff for: docs/05-entities.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Objects
1+
# Entities
22

33
- [One Call](#one-call)
44
- [Alert](#alert)

Diff for: src/Endpoint/OneCallEndpoint.php

-93
This file was deleted.

Diff for: src/Entity/OneCall/Alert.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class Alert
1818

1919
public function __construct(array $data)
2020
{
21-
$timezoneUtc = new \DateTimeZone('UTC');
22-
2321
$this->senderName = $data['sender_name'];
2422
$this->eventName = $data['event'];
25-
$this->startsAt = \DateTimeImmutable::createFromFormat('U', $data['start'], $timezoneUtc);
26-
$this->endsAt = \DateTimeImmutable::createFromFormat('U', $data['end'], $timezoneUtc);
23+
$this->startsAt = \DateTimeImmutable::createFromFormat('U', $data['start']);
24+
$this->endsAt = \DateTimeImmutable::createFromFormat('U', $data['end']);
2725
$this->description = $data['description'];
2826
$this->tags = $data['tags'];
2927
}

Diff for: src/Entity/OneCall/BaseWeather.php

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Entity\OneCall;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\Condition;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\Wind;
7+
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
8+
9+
class BaseWeather
10+
{
11+
use EntityTrait;
12+
13+
private \DateTimeImmutable $dateTime;
14+
15+
private int $atmosphericPressure;
16+
17+
private int $humidity;
18+
19+
private float $dewPoint;
20+
21+
private ?float $ultraVioletIndex;
22+
23+
private int $cloudiness;
24+
25+
private Wind $wind;
26+
27+
/** @var Condition[] */
28+
private array $conditions;
29+
30+
private ?float $rainVolume;
31+
32+
private ?float $snowVolume;
33+
34+
public function __construct(array $data)
35+
{
36+
$this->dateTime = \DateTimeImmutable::createFromFormat('U', $data['dt']);
37+
$this->atmosphericPressure = $data['pressure'];
38+
$this->humidity = $data['humidity'];
39+
$this->dewPoint = $data['dew_point'];
40+
$this->ultraVioletIndex = $data['uvi'] ?? null;
41+
$this->cloudiness = $data['clouds'];
42+
43+
$this->wind = new Wind([
44+
'speed' => $data['wind_speed'],
45+
'deg' => $data['wind_deg'],
46+
'gust' => $data['wind_gust'] ?? null
47+
]);
48+
49+
$this->conditions = $this->createEntityList(Condition::class, $data['weather']);
50+
$this->rainVolume = $data['rain']['1h'] ?? $data['rain']['3h'] ?? $data['rain'] ?? null;
51+
$this->snowVolume = $data['snow']['1h'] ?? $data['snow']['3h'] ?? $data['snow'] ?? null;
52+
}
53+
54+
public function getDateTime(): \DateTimeImmutable
55+
{
56+
return $this->dateTime;
57+
}
58+
59+
public function getAtmosphericPressure(): int
60+
{
61+
return $this->atmosphericPressure;
62+
}
63+
64+
public function getHumidity(): int
65+
{
66+
return $this->humidity;
67+
}
68+
69+
public function getDewPoint(): float
70+
{
71+
return $this->dewPoint;
72+
}
73+
74+
public function getUltraVioletIndex(): ?float
75+
{
76+
return $this->ultraVioletIndex;
77+
}
78+
79+
public function getCloudiness(): int
80+
{
81+
return $this->cloudiness;
82+
}
83+
84+
public function getWind(): Wind
85+
{
86+
return $this->wind;
87+
}
88+
89+
public function getConditions(): array
90+
{
91+
return $this->conditions;
92+
}
93+
94+
public function getRainVolume(): ?float
95+
{
96+
return $this->rainVolume;
97+
}
98+
99+
public function getSnowVolume(): ?float
100+
{
101+
return $this->snowVolume;
102+
}
103+
}

Diff for: src/Entity/OneCall/DayData.php

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Entity\OneCall;
4+
5+
class DayData extends BaseWeather
6+
{
7+
private Temperature $temperature;
8+
9+
private Temperature $temperatureFeelsLike;
10+
11+
private int $precipitationProbability;
12+
13+
private string $summary;
14+
15+
private MoonPhase $moonPhase;
16+
17+
private \DateTimeImmutable $moonriseAt;
18+
19+
private \DateTimeImmutable $moonsetAt;
20+
21+
private \DateTimeImmutable $sunriseAt;
22+
23+
private \DateTimeImmutable $sunsetAt;
24+
25+
public function __construct(array $data)
26+
{
27+
parent::__construct($data);
28+
29+
$this->temperature = new Temperature($data['temp']);
30+
$this->temperatureFeelsLike = new Temperature($data['feels_like']);
31+
$this->precipitationProbability = \round($data['pop'] * 100);
32+
$this->summary = $data['summary'];
33+
$this->moonPhase = new MoonPhase($data);
34+
$this->moonriseAt = \DateTimeImmutable::createFromFormat('U', $data['moonrise']);
35+
$this->moonsetAt = \DateTimeImmutable::createFromFormat('U', $data['moonset']);
36+
$this->sunriseAt = \DateTimeImmutable::createFromFormat('U', $data['sunrise']);
37+
$this->sunsetAt = \DateTimeImmutable::createFromFormat('U', $data['sunset']);
38+
}
39+
40+
public function getTemperature(): Temperature
41+
{
42+
return $this->temperature;
43+
}
44+
45+
public function getTemperatureFeelsLike(): Temperature
46+
{
47+
return $this->temperatureFeelsLike;
48+
}
49+
50+
public function getPrecipitationProbability(): int
51+
{
52+
return $this->precipitationProbability;
53+
}
54+
55+
public function getSummary(): string
56+
{
57+
return $this->summary;
58+
}
59+
60+
public function getMoonPhase(): MoonPhase
61+
{
62+
return $this->moonPhase;
63+
}
64+
65+
public function getMoonriseAt(): \DateTimeImmutable
66+
{
67+
return $this->moonriseAt;
68+
}
69+
70+
public function getMoonsetAt(): \DateTimeImmutable
71+
{
72+
return $this->moonsetAt;
73+
}
74+
75+
public function getSunriseAt(): \DateTimeImmutable
76+
{
77+
return $this->sunriseAt;
78+
}
79+
80+
public function getSunsetAt(): \DateTimeImmutable
81+
{
82+
return $this->sunsetAt;
83+
}
84+
}

Diff for: src/Entity/OneCall/HourData.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Entity\OneCall;
4+
5+
class HourData extends BaseWeather
6+
{
7+
private float $temperature;
8+
9+
private float $temperatureFeelsLike;
10+
11+
private int $visibility;
12+
13+
private int $precipitationProbability;
14+
15+
public function __construct(array $data)
16+
{
17+
parent::__construct($data);
18+
19+
$this->temperature = $data['temp'];
20+
$this->temperatureFeelsLike = $data['feels_like'];
21+
$this->visibility = $data['visibility'];
22+
$this->precipitationProbability = \round($data['pop'] * 100);
23+
}
24+
25+
public function getTemperature(): float
26+
{
27+
return $this->temperature;
28+
}
29+
30+
public function getTemperatureFeelsLike(): float
31+
{
32+
return $this->temperatureFeelsLike;
33+
}
34+
35+
public function getVisibility(): int
36+
{
37+
return $this->visibility;
38+
}
39+
40+
public function getPrecipitationProbability(): int
41+
{
42+
return $this->precipitationProbability;
43+
}
44+
}

Diff for: src/Entity/OneCall/MinuteForecast.php renamed to src/Entity/OneCall/MinuteData.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Entity\OneCall;
44

5-
class MinuteForecast
5+
class MinuteData
66
{
77
private \DateTimeImmutable $dateTime;
88

99
private float $precipitation;
1010

1111
public function __construct(array $data)
1212
{
13-
$this->dateTime = \DateTimeImmutable::createFromFormat('U', $data['dt'], new \DateTimeZone('UTC'));
13+
$this->dateTime = \DateTimeImmutable::createFromFormat('U', $data['dt']);
1414
$this->precipitation = $data['precipitation'];
1515
}
1616

0 commit comments

Comments
 (0)