about summary refs log tree commit diff stats
path: root/ara.pl
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-10 17:15:08 +0530
committerAndinus <andinus@nand.sh>2020-06-10 17:15:08 +0530
commit0ff1f3d221ad52608ccfeb0e470b196a23395823 (patch)
tree12eaa17198d5336bedf687135a8ccb5167582fec /ara.pl
parentb4e3aa288325e8541caaa30b53c9e6ced25273a4 (diff)
downloadara-0ff1f3d221ad52608ccfeb0e470b196a23395823.tar.gz
Switch to HTTP::Tiny, add to cpanfile
HTTP::Tiny has more options.
Diffstat (limited to 'ara.pl')
-rwxr-xr-xara.pl15
1 files changed, 10 insertions, 5 deletions
diff --git a/ara.pl b/ara.pl
index 963720d..4f5170a 100755
--- a/ara.pl
+++ b/ara.pl
@@ -76,15 +76,20 @@ if ( -e $file ) {
 if ( not -e $file
          or $file_mtime < Time::Moment->now_utc->minus_minutes(8)
          or $get_latest ) {
-    require File::Fetch;
+    require HTTP::Tiny;
 
     # Fetch latest data from api.
     my $url = 'https://api.covid19india.org/data.json';
-    my $ff = File::Fetch->new(uri => $url);
 
-    # Save the api response under /tmp.
-    $file = $ff->fetch( to => '/tmp' )
-        or die $ff->error;
+    my $response = HTTP::Tiny
+        ->new( verify_SSL => 1 )
+        ->mirror($url, $file);
+
+    die "Failed to fetch latest data...
+Reason: $response->{reason}\n
+Content: $response->{content}
+Status: $response->{status}\n"
+        unless $response->{success};
 }
 
 # Slurp api response to $file_data.