- my $answer_content =
- $self->serialize({ batchid => $batchid, answers => \%answers });
- ($page, $response, %reply_headers) =
- $self->https_post('/batch/run', {
- login => $self->login,
- password => $self->password,
- content => $answer_content,
- });
- $page = $self->deserialize($page);
- die $page->{error} if $page->{error};
- return;
+ $self->https_post('/batch/run', { batch_id => $batch_id, answers => \%answers});
+}
+
+sub download {
+ my $self = shift;
+ warn "Fetching batch index...\n" if $self->debug;
+ my $result = $self->https_post('/batch/status');
+
+ my @batches_in_transit;
+ foreach (@{ $result->{batches} }) {
+ if ( $_->{status} eq 'received' ) {
+ push @batches_in_transit, $_->{batch_id};
+ }
+ }
+ return if scalar(@batches_in_transit) == 0;
+ $result = $self->https_post('/batch/receive',
+ { batch_id => \@batches_in_transit });
+ # this shouldn't contain errors, since the server just told us
+ # that the batches exist...
+ foreach (@$result) {
+ if ( $_->{error} ) {
+ die "Error receiving batch: ".$_->{error}."\n";
+ }
+ }
+# $self->https_post('/batch/close', {
+# login => $self->login,
+# password => $self->password,
+# batch_id => \@batches_in_transit,
+ @$result;