1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE file |
5
|
|
|
* that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare ( |
9
|
|
|
strict_types = 1 |
10
|
|
|
); |
11
|
|
|
|
12
|
|
|
namespace Component\Remote\BurzeDzisNet; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* BurzeDzisNetInterface represents remote client |
16
|
|
|
* |
17
|
|
|
* @author Krzysztof Piasecki <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class BurzeDzisNet implements BurzeDzisNetInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Soap client |
23
|
|
|
* |
24
|
|
|
* @var \SoapClient Soap client |
25
|
|
|
*/ |
26
|
|
|
private $client = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* API key |
30
|
|
|
* |
31
|
|
|
* @var string API key |
32
|
|
|
*/ |
33
|
|
|
private $apiKey = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Remote client |
37
|
|
|
* |
38
|
|
|
* @param EndpointInterface $endpoint entry point to burze.dzis.net |
39
|
|
|
*/ |
40
|
|
|
public function __construct(EndpointInterface $endpoint) |
41
|
|
|
{ |
42
|
|
|
$this->client = $endpoint->client(); |
43
|
|
|
$this->apiKey = $endpoint->apiKey(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Indicates whether given API key is valid |
48
|
|
|
* |
49
|
|
|
* @param string $apiKey API key |
50
|
|
|
* @return bool true if API key is valid; otherwise false |
51
|
|
|
* @throws \SoapFault soap error |
52
|
|
|
*/ |
53
|
|
|
public function verifyApiKey(string $apiKey): bool |
54
|
|
|
{ |
55
|
|
|
return $this->client->KeyApi($apiKey); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get Point representing location coordinates |
60
|
|
|
* |
61
|
|
|
* If no location returns Point with coordinates [0,0]. |
62
|
|
|
* |
63
|
|
|
* @see Point |
64
|
|
|
* @param string $name location name |
65
|
|
|
* @return Point location coordinates |
66
|
|
|
* @throws \SoapFault soap error |
67
|
|
|
*/ |
68
|
|
|
public function locate(string $name): Point |
69
|
|
|
{ |
70
|
|
|
$dto = $this->client->miejscowosc($name, $this->apiKey); |
71
|
|
|
return new Point( |
72
|
|
|
$dto->x, |
73
|
|
|
$dto->y |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get information about storm for the given locality and monitoring radius |
79
|
|
|
* |
80
|
|
|
* @see Storm |
81
|
|
|
* @param Point $point monitored location |
82
|
|
|
* @param int $radius radius of monitoring |
83
|
|
|
* @return Storm information about registered lightnings and more |
84
|
|
|
* @throws \SoapFault soap error |
85
|
|
|
*/ |
86
|
|
|
public function getStorm(Point $point, int $radius = 25): Storm |
87
|
|
|
{ |
88
|
|
|
$dto = $this->client->szukaj_burzy( |
89
|
|
|
$point->y(), |
90
|
|
|
$point->x(), |
91
|
|
|
$radius, |
92
|
|
|
$this->apiKey |
93
|
|
|
); |
94
|
|
|
return new Storm( |
95
|
|
|
$dto->liczba, |
96
|
|
|
$dto->odleglosc, |
97
|
|
|
$dto->kierunek, |
98
|
|
|
$dto->okres, |
99
|
|
|
$radius |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get set of weather alerts for the given Point |
105
|
|
|
* |
106
|
|
|
* <strong>Only Polish area</strong> |
107
|
|
|
* @param Point $point location coordinates |
108
|
|
|
* @return WeatherAlert set of weather alerts |
109
|
|
|
*/ |
110
|
|
|
public function getWeatherAlert(Point $point): WeatherAlert |
111
|
|
|
{ |
112
|
|
|
$dto = $this->client->ostrzezenia_pogodowe( |
113
|
|
|
$point->y(), |
114
|
|
|
$point->x(), |
115
|
|
|
$this->apiKey |
116
|
|
|
); |
117
|
|
|
return (new WeatherAlert()) |
118
|
|
|
->withAlert( |
119
|
|
|
'frost', |
120
|
|
|
new Alert( |
121
|
|
|
$dto->mroz, |
122
|
|
|
$dto->mroz_od_dnia, |
123
|
|
|
$dto->mroz_do_dnia |
124
|
|
|
) |
125
|
|
|
)->withAlert( |
126
|
|
|
'heat', |
127
|
|
|
new Alert( |
128
|
|
|
$dto->upal, |
129
|
|
|
$dto->upal_od_dnia, |
130
|
|
|
$dto->upal_do_dnia |
131
|
|
|
) |
132
|
|
|
)->withAlert( |
133
|
|
|
'wind', |
134
|
|
|
new Alert( |
135
|
|
|
$dto->wiatr, |
136
|
|
|
$dto->wiatr_od_dnia, |
137
|
|
|
$dto->wiatr_do_dnia |
138
|
|
|
) |
139
|
|
|
)->withAlert( |
140
|
|
|
'storm', |
141
|
|
|
new Alert( |
142
|
|
|
$dto->burza, |
143
|
|
|
$dto->burza_od_dnia, |
144
|
|
|
$dto->burza_do_dnia |
145
|
|
|
) |
146
|
|
|
)->withAlert( |
147
|
|
|
'tornado', |
148
|
|
|
new Alert( |
149
|
|
|
$dto->traba, |
150
|
|
|
$dto->traba_od_dnia, |
151
|
|
|
$dto->traba_do_dnia |
152
|
|
|
) |
153
|
|
|
)->withAlert( |
154
|
|
|
'precipitation', |
155
|
|
|
new Alert( |
156
|
|
|
$dto->opad, |
157
|
|
|
$dto->opad_od_dnia, |
158
|
|
|
$dto->opad_do_dnia |
159
|
|
|
) |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|