diff options
Diffstat (limited to 'bin/send-reports')
-rwxr-xr-x | bin/send-reports | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/bin/send-reports b/bin/send-reports index 9ab6f8274..1ca0b51f0 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -27,6 +27,8 @@ use mySociety::EmailUtil; use mySociety::MaPit; use mySociety::Web qw(ent); +use Open311; + # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); my $base_url = mySociety::Config::get('BASE_URL'); @@ -93,7 +95,7 @@ while (my $row = $unsent->next) { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude} ); } - my (@to, @recips, $template, $areas_info); + my (@to, @recips, $template, $areas_info, @open311_councils); if ($site eq 'emptyhomes') { my $council = $row->council; @@ -135,6 +137,9 @@ while (my $row = $unsent->next) { $h{category} = 'Customer Services' if $h{category} eq 'Other'; } elsif ($areas_info->{$council}->{type} eq 'LBO') { # London $send_web = 'london'; + } elsif ( my $endpoint = FixMyStreet::App->model("DB::Open311conf")->find( { area_id => $council } ) ) { + push @open311_councils, $endpoint; + $send_web = 'open311'; } else { my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, @@ -247,6 +252,38 @@ while (my $row = $unsent->next) { if (!$nomail) { $result *= post_london_report( $row, %h ); } + } elsif ($send_web eq 'open311') { + # FIXME - looking this up twice :( + foreach my $conf ( @open311_councils ) { + # my $conf = FixMyStreet::App->model('DB::Open311conf')->find( { area_id => $row->council } ); + print 'posting to end point for ' . $conf->area_id . "\n"; + + # FIXME - doesn't deal with multiple recipients + my $contact = FixMyStreet::App->model("DB::Contact")->find( { + deleted => 0, + area_id => $conf->area_id, + category => $row->category + } ); + + my $open311 = Open311->new( + jurisdiction => $conf->jurisdiction, + endpoint => $conf->endpoint, + api_key => $conf->api_key, + ); + + # non standard west berks end points + if ( $row->council == 2619 ) { + $open311->endpoints( { services => 'Services', requests => 'Requests' } ); + } + + my $resp = $open311->send_service_request( $row, \%h, $contact->email ); + + if ( $resp ) { + $row->external_id( $resp ); + $result = 0; + } else { + $result = 1; + } } if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { |