aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/GetServiceRequests.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-04-05 16:37:32 +0100
committerStruan Donald <struan@exo.org.uk>2018-04-11 10:42:52 +0100
commit80754df967ceee0180679ffcdde55d22aad4ac21 (patch)
treed40c848a59ee932f77714dffbb12ac44b846092f /perllib/Open311/GetServiceRequests.pm
parent1d25da206d2e1ed2d2f841d65461e4a9449dd751 (diff)
[Open311] fetch_all option for open311 problem fetching
If a body has a `fetch_all_reports` setting in the extra metadata then all reports are fetched over Open311 and processed regardless of age. This is useful for bodies where the API endpoint always returns all the reports as it suppresses the error messages you would otherwise get about reports with invalid dates.
Diffstat (limited to 'perllib/Open311/GetServiceRequests.pm')
-rw-r--r--perllib/Open311/GetServiceRequests.pm24
1 files changed, 17 insertions, 7 deletions
diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm
index 78e9647fa..48e35acab 100644
--- a/perllib/Open311/GetServiceRequests.pm
+++ b/perllib/Open311/GetServiceRequests.pm
@@ -9,6 +9,7 @@ use DateTime::Format::W3CDTF;
has system_user => ( is => 'rw' );
has start_date => ( is => 'ro', default => sub { undef } );
has end_date => ( is => 'ro', default => sub { undef } );
+has fetch_all => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
has convert_latlong => ( is => 'rw', default => 0 );
@@ -26,19 +27,28 @@ sub fetch {
);
while ( my $body = $bodies->next ) {
-
- my $o = Open311->new(
- endpoint => $body->endpoint,
- api_key => $body->api_key,
- jurisdiction => $body->jurisdiction,
- );
+ my $o = $self->create_open311_object( $body );
$self->system_user( $body->comment_user );
$self->convert_latlong( $body->convert_latlong );
+ $self->fetch_all( $body->get_extra_metadata('fetch_all_problems') );
$self->create_problems( $o, $body );
}
}
+# this is so we can test
+sub create_open311_object {
+ my ($self, $body) = @_;
+
+ my $o = Open311->new(
+ endpoint => $body->endpoint,
+ api_key => $body->api_key,
+ jurisdiction => $body->jurisdiction,
+ );
+
+ return $o;
+}
+
sub create_problems {
my ( $self, $open311, $body ) = @_;
@@ -49,7 +59,7 @@ sub create_problems {
$args->{start_date} = DateTime::Format::W3CDTF->format_datetime( $self->start_date );
$args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $self->end_date );
- } else {
+ } elsif ( !$self->fetch_all ) {
my $end_dt = DateTime->now();
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -1 );