diff options
author | dakkar <dakkar@thenautilus.net> | 2013-05-16 21:32:22 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2013-05-16 21:32:22 +0100 |
commit | f8b6b87de36e471fb8f094904e10bd65e5346a61 (patch) | |
tree | d4ab350e2579432f318baeebac4b0b0abda8b154 /lib | |
parent | modularise forceast client (diff) | |
download | HomePanel-f8b6b87de36e471fb8f094904e10bd65e5346a61.tar.gz HomePanel-f8b6b87de36e471fb8f094904e10bd65e5346a61.tar.bz2 HomePanel-f8b6b87de36e471fb8f094904e10bd65e5346a61.zip |
"time" support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WebService/ForecastIo.pm | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/WebService/ForecastIo.pm b/lib/WebService/ForecastIo.pm index fd6bcb8..45e7802 100644 --- a/lib/WebService/ForecastIo.pm +++ b/lib/WebService/ForecastIo.pm @@ -1,8 +1,10 @@ package WebService::ForecastIo; use Moose; use MooseX::Types::URI 'Uri'; +use MooseX::Types::DateTime; use MooseX::Params::Validate; use Moose::Util::TypeConstraints; +use DateTime::Format::ISO8601; has base_uri => ( is => 'ro', @@ -39,12 +41,25 @@ sub _make_request_uri { my ($lat,$lon,$time) = delete @opts{qw(latitude longitude time)}; my $req_uri = $self->base_uri->clone; + + my $time_str; + if ($time) { + $time_str = $time->iso8601; + my $tz = $time->time_zone; + if ($tz->is_utc) { $time_str .= 'Z' } + elsif (not $tz->is_floating) { + $time_str .= DateTime::TimeZone->offset_as_string( + $tz->offset_for_datetime($time) + ); + } + } + $req_uri->path_segments( grep { length($_)>0 } $req_uri->path_segments, $self->api_key, "$lat,$lon", - ( defined $time ? $time : () ), + $time_str, ); if ($opts{exclude}) { @@ -61,12 +76,18 @@ enum my $units_type=__PACKAGE__.'::units', enum my $block_type=__PACKAGE__.'::block', [qw(currently minutely hourly daily alerts flags)]; +coerce 'DateTime', from 'Str', + via { + s{([+-])(\d\d)(\d\d)\z}{$1$2:$3}; + DateTime::Format::ISO8601->new->parse_datetime($_) + }; + sub request { my ($self,%opts) = validated_hash( \@_, latitude => { isa => 'Num' }, longitude => { isa => 'Num' }, - time => { isa => 'Num|Str', optional => 1 }, + time => { isa => 'DateTime', optional => 1, coerce => 1 }, units => { isa => $units_type, default => 'si' }, exclude => { isa => "ArrayRef[$block_type]", default => sub { [] } }, ); |