From fa77e6c1b2eb526ab79a708ed8d04824c28f7445 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 16 May 2013 21:01:28 +0100 Subject: modularise forceast client --- forecast.pl | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'forecast.pl') diff --git a/forecast.pl b/forecast.pl index a3dd7d6..5d78906 100644 --- a/forecast.pl +++ b/forecast.pl @@ -2,30 +2,21 @@ use strict; use warnings; use 5.014; -use LWP::Simple; -use URI; +use WebService::ForecastIo; use JSON; use Data::Printer; my $key=$ARGV[0]; -my $base = URI->new('https://api.forecast.io/forecast'); - -sub URI::path_segments_push { - my ($uri,@segments) = @_; - $uri->path_segments($uri->path_segments,@segments); -} - -# home -$base->path_segments_push( - $key,"51.54,-0.37", -); -$base->query_form({ - units => 'si', - exclude => 'minutely,flags', +my $fio = WebService::ForecastIo->new({ + api_key => $key, }); -my $content = get($base); +my $response = $fio->request({ + latitude => 51.54, + longitude => -0.37, + exclude => ['minutely','flags'], +}); -my $output = decode_json($content); +my $output = decode_json($response); p $output; -- cgit v1.2.3