2
2
3
3
Weather::WeatherKit - Apple WeatherKit REST API client
4
4
5
- =head1 VERSION
6
-
7
- Version 0.11
8
-
9
5
=head1 SYNOPSIS
10
6
11
7
use Weather::WeatherKit;
@@ -17,12 +13,31 @@ Version 0.11
17
13
key => $private_key # Encrypted private key (PEM)
18
14
);
19
15
16
+ # Request current weather:
20
17
my $report = $wk->get(
21
18
lat => $lat, # Latitude
22
19
lon => $lon, # Longitude
23
- dataSets => $datasets # e.g. currentWeather (comma-separated list)
20
+ dataSets => 'currentWeather'
21
+ );
22
+
23
+ # Request forecast for 8 days, use Weather::API::Base helper functions
24
+ # for ISO dates, and get full HTTP::Response object to check for success
25
+ use Weather::API::Base qw(:all);
26
+
27
+ my $response = $wk->get_response(
28
+ lat => $lat,
29
+ lon => $lon,
30
+ dataSets => 'forecastHourly',
31
+ hourlyStart => ts_to_iso_date(time()),
32
+ hourlyEnd => ts_to_iso_date(time()+8*24*3600)
24
33
);
25
34
35
+ if ($response->is_success) {
36
+ my $json = $response->decoded_content;
37
+ } else {
38
+ die $response->status_line;
39
+ }
40
+
26
41
=head1 DESCRIPTION
27
42
28
43
Weather::WeatherKit provides basic access to the Apple WeatherKit REST API (v1).
@@ -71,7 +86,7 @@ which you first need to convert to the PEM format. On a Mac you can convert it s
71
86
openssl pkcs8 -nocrypt -in AuthKey_<key_id>.p8 -out AuthKey_<key_id>.pem
72
87
73
88
=item * C<key> : Instead of the C<.pem> file, you can pass its contents directly
74
- as a string.
89
+ as a string. If both are provided C<key> takes precedence over C<key_file>.
75
90
76
91
=back
77
92
@@ -87,7 +102,8 @@ Optional parameters:
87
102
88
103
=item * C<curl> : If true, fall back to using the C<curl> command line program.
89
104
This is useful if you have issues adding http support to L<LWP::UserAgent>, which
90
- is the default method for the WeatherKit requests.
105
+ is the default method for the WeatherKit requests. It assumes the C<curl> program
106
+ is installed in C<$PATH>.
91
107
92
108
=item * C<expiration> : Token expiration time in seconds. Tokens are cached until
93
109
there are less than 10 minutes left to expiration. Default: C<7200>.
@@ -166,6 +182,49 @@ specified in the constructor).
166
182
167
183
=back
168
184
185
+ =head1 HELPER FUNCTIONS (from Weather::API::Base)
186
+
187
+ The parent class L<Weather::API::Base> contains some useful functions e.g.:
188
+
189
+ use Weather::API::Base qw(:all);
190
+
191
+ # Get time in ISO (YYYY-MM-DDTHH:mm:ss) format
192
+ my $datetime = ts_to_iso_date(time());
193
+
194
+ # Convert 30 degrees Celsius to Fahrenheit
195
+ my $result = convert_units('C', 'F', 30);
196
+
197
+ See the doc for that module for more details.
198
+
199
+ =head1 KNOWN ISSUES
200
+
201
+ =head2 400 errors on 10 day forecast
202
+
203
+ Although WeatherKit is supposed to provide 10 days of forecast, at some point users
204
+ started getting C<400> errors when requesting (e.g. with C<hourlyEnd>) more than 8 or 9
205
+ days of forecast. If you encounter this issue, limit your forecast request to 9 or
206
+ 8 days in the future.
207
+
208
+ =head1 OTHER PERL WEATHER MODULES
209
+
210
+ Some Perl modules for current weather and forecasts from other sources:
211
+
212
+ =head2 L<Weather::OWM>
213
+
214
+ OpenWeatherMap uses various weather sources combined with their own ML and offers
215
+ a couple of free endpoints (the v2.5 current weather and 5d/3h forecast) with generous
216
+ request limits. Their newer One Call 3.0 API also offers some free usage (1000 calls/day)
217
+ and the cost is per call above that. If you want access to history APIs, extended
218
+ hourly forecasts etc, there are monthly subscriptions. L<Weather::OWM> is from the
219
+ same author as this module and similar in use.
220
+
221
+ =head2 L<Weather::Astro7Timer>
222
+
223
+ The 7Timer! weather forecast is completely free and would be of extra interest if
224
+ you are interested in astronomy/stargazing. It uses the standard NOAA forecast,
225
+ but also calculates astronomical seeing and transparency. It can be accessed with
226
+ L<Weather::Astro7Timer>, which is another module similar to this (same author).
227
+
169
228
=head1 AUTHOR
170
229
171
230
Dimitrios Kechagias, C<< <dkechag at cpan.org> >>
0 commit comments