#!/usr/bin/env perl

use warnings;
use strict;

use LWP::UserAgent;
use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
use XML::LibXML;
use File::Temp qw(tempfile);

my $batchName = undef;
my $file = undef;

GetOptions(
        'batch|b=s' => \$batchName,
        'file|f=s' => \$file,
        );

my $odmUrl = "http://web01.psps.ifa.hawaii.edu/a01/OdmWebService/OdmWebService.asmx/GetBatchStatus";
my $ua = LWP::UserAgent->new;
$ua->timeout(15);
$ua->env_proxy;

my $statusFilter = "*";

my $response = $ua->post($odmUrl,
        [batchNameFilter => "%".$batchName,
        statusFilter => $statusFilter,
        fromFilter => "2010-01-01",
        toFilter => "2099-01-01"]
        );

# '200' is the 'OK' response
if ($response->code != 200) {

    print "Problem connecting to web service for '$batchName', HTTP response status: ".$response->status_line."\n";
    exit(1);
}

open (DAT, ">".$file);
print DAT $response->content;


print "$file\n";

exit(0);



