aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-02 14:39:19 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-02 14:39:19 +0100
commit8ac0fceb6c34a626d97eab2a667a18550204aef8 (patch)
treed14aa9e75533e4874e10d0c9cbfdb70ea5782932
parent2a12a44e391ba026d0e7460d0b503ba5dcb41e03 (diff)
report submission via open311
-rwxr-xr-xbin/send-reports29
1 files changed, 29 insertions, 0 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 1af3ba1ea..c74a796c5 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -28,6 +28,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');
@@ -136,6 +138,8 @@ 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 ( FixMyStreet::App->model("DB::Open311conf")->find( { area_id => $council } ) ) {
+ $send_web = 'open311';
} else {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
@@ -248,6 +252,31 @@ while (my $row = $unsent->next) {
if (!$nomail) {
$result *= post_london_report( $row, %h );
}
+ } elsif ($send_web eq 'open311') {
+ # FIXME - looking this up twice :(
+ my $conf = FixMyStreet::App->model('DB::Open311conf')->find( { area_id => $row->council } );
+
+ # FIXME - doesn't deal with multiple recipients
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ deleted => 0,
+ area_id => $row->council,
+ category => $row->category
+ } );
+
+ my $open311 = Open311->new(
+ jurisdiction => $conf->jurisdiction,
+ endpoint => $conf->endpoint,
+ api_key => $conf->api_key,
+ );
+
+ my $resp = $open311->send_service_request( $row, $contact->email );
+
+ if ( $resp ) {
+ $row->external_id( $resp );
+ $result = 0;
+ } else {
+ $result = 1;
+ }
}
if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) {