Skip to content

Commit ae377b2

Browse files
committed
Refactor to base on Weather::API::Base
1 parent e9c368e commit ae377b2

File tree

6 files changed

+190
-69
lines changed

6 files changed

+190
-69
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
perl-version:
14+
- '5.40'
1415
- '5.36'
1516
- '5.32'
1617
- '5.28'

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
MANIFEST.bak
3+
Makefile
4+
Makefile.old
5+
Build
6+
Build.bat
7+
META.*
8+
MYMETA.*
9+
.build/
10+
_build/
11+
cover_db/
12+
blib/
13+
inc/
14+
.lwpcookies
15+
.last_cover_stats
16+
nytprof.out
17+
pod2htm*.tmp
18+
pm_to_blib
19+
Weather-WeatherKit-*
20+
Weather-WeatherKit-*.tar.gz

Changes

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Revision history for Weather-WeatherKit
22

3-
0.1 2023-02-22
4-
First public release.
3+
0.12 2024-12-10
4+
Refactored to base on Weather::API::Base.
5+
Improved documantation.
56

67
0.11 2023-02-23
78
Changes for CPANTS.
9+
10+
0.1 2023-02-22
11+
First public release.

Makefile.PL

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ my %WriteMakefileArgs = (
2121
'JSON' => '0'
2222
},
2323
PREREQ_PM => {
24-
'Crypt::JWT' => '0',
24+
'Weather::API::Base' => '0.3',
25+
'Crypt::JWT' => '0',
2526
},
2627
META_MERGE => {
2728
"meta-spec" => { version => 2 },
29+
prereqs => {
30+
runtime => {
31+
suggests => {
32+
'JSON' => '0',
33+
}
34+
}
35+
},
2836
resources => {
2937
repository => {
3038
type => 'git',

README.pod

+66-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
Weather::WeatherKit - Apple WeatherKit REST API client
44

5-
=head1 VERSION
6-
7-
Version 0.11
8-
95
=head1 SYNOPSIS
106

117
use Weather::WeatherKit;
@@ -17,12 +13,31 @@ Version 0.11
1713
key => $private_key # Encrypted private key (PEM)
1814
);
1915

16+
# Request current weather:
2017
my $report = $wk->get(
2118
lat => $lat, # Latitude
2219
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)
2433
);
2534

35+
if ($response->is_success) {
36+
my $json = $response->decoded_content;
37+
} else {
38+
die $response->status_line;
39+
}
40+
2641
=head1 DESCRIPTION
2742

2843
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
7186
openssl pkcs8 -nocrypt -in AuthKey_<key_id>.p8 -out AuthKey_<key_id>.pem
7287

7388
=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>.
7590

7691
=back
7792

@@ -87,7 +102,8 @@ Optional parameters:
87102

88103
=item * C<curl> : If true, fall back to using the C<curl> command line program.
89104
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>.
91107

92108
=item * C<expiration> : Token expiration time in seconds. Tokens are cached until
93109
there are less than 10 minutes left to expiration. Default: C<7200>.
@@ -166,6 +182,49 @@ specified in the constructor).
166182

167183
=back
168184

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+
169228
=head1 AUTHOR
170229

171230
Dimitrios Kechagias, C<< <dkechag at cpan.org> >>

0 commit comments

Comments
 (0)