aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport/London.pm
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
committerDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
commit67da8efc720d2d0bd22bd9fe8655b7e983b35bb4 (patch)
tree38b8570647124df06c637d4b923f6010211ef328 /perllib/FixMyStreet/SendReport/London.pm
parent40b3a51d33caefa8f5fb97ce9be18ef936c7e260 (diff)
parent131ff6e9bf3626d6a8fff6ae54669d250148a63a (diff)
Merge remote branch 'origin/master' into fmb-read-only
Conflicts: bin/send-reports perllib/FixMyStreet/Cobrand/Default.pm perllib/FixMyStreet/Cobrand/FixMyStreet.pm templates/web/fixmystreet/alert/index.html templates/web/fixmystreet/around/display_location.html web/cobrands/fixmystreet/_layout.scss web/js/map-OpenLayers.js
Diffstat (limited to 'perllib/FixMyStreet/SendReport/London.pm')
-rw-r--r--perllib/FixMyStreet/SendReport/London.pm113
1 files changed, 113 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm
new file mode 100644
index 000000000..58ecb2375
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/London.pm
@@ -0,0 +1,113 @@
+package FixMyStreet::SendReport::London;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+use Digest::MD5;
+use LWP::UserAgent;
+use LWP::Simple;
+
+use Utils;
+
+sub construct_message {
+ my %h = @_;
+ return <<EOF,
+A user of FixMyStreet has submitted the following report of a local
+problem that they believe might require your attention.
+
+Subject: $h{title}
+
+Details: $h{detail}
+
+$h{fuzzy}, or to provide an update on the problem, please visit the
+following link:
+
+$h{url}
+
+$h{closest_address}
+Yours,
+The FixMyStreet team
+EOF
+}
+
+sub send {
+ return if mySociety::Config::get('STAGING_SITE');
+ my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_;
+
+ $h->{message} = construct_message( %$h );
+ my $phone = $h->{phone};
+ my $mobile = '';
+ if ($phone && $phone =~ /^\s*07/) {
+ $mobile = $phone;
+ $phone = '';
+ }
+ my ($first, $last) = $h->{name} =~ /^(\S*)(?: (.*))?$/;
+ my %params = (
+ Key => mySociety::Config::get('LONDON_REPORTIT_KEY'),
+ Signature => Digest::MD5::md5_hex( $h->{confirmed} . mySociety::Config::get('LONDON_REPORTIT_SECRET') ),
+ Type => Utils::london_categories()->{$h->{category}},
+ RequestDate => $h->{confirmed},
+ RequestMethod => 'Web',
+ ExternalId => $h->{url},
+ 'Customer.Title' => '',
+ 'Customer.FirstName' => $first,
+ 'Customer.Surname' => $last,
+ 'Customer.Email' => $h->{email},
+ 'Customer.Phone' => $phone,
+ 'Customer.Mobile' => $mobile,
+ 'ProblemDescription' => $h->{message},
+ );
+ if ($h->{used_map}) {
+ $params{'Location.Latitude'} = $h->{latitude};
+ $params{'Location.Longitude'} = $h->{longitude};
+ } elsif (mySociety::PostcodeUtil::is_valid_postcode($h->{query})) {
+ # Didn't use map, and entered postcode, so use that.
+ $params{'Location.Postcode'} = $h->{query};
+ } else {
+ # Otherwise, lat/lon is all we have, even if it's wrong.
+ $params{'Location.Latitude'} = $h->{latitude};
+ $params{'Location.Longitude'} = $h->{longitude};
+ }
+ if ($h->{has_photo}) {
+ $params{'Document1.Name'} = 'Photograph';
+ $params{'Document1.MimeType'} = 'image/jpeg';
+ $params{'Document1.URL'} = $h->{image_url};
+ $params{'Document1.URLPublic'} = 'true';
+ }
+ my $browser = LWP::UserAgent->new;
+ my $response = $browser->post( mySociety::Config::get('LONDON_REPORTIT_URL'), \%params );
+ my $out = $response->content;
+ if ($response->code ne 200) {
+ print "Failed to post $h->{id} to London API, response was " . $response->code . " $out\n";
+ $self->error( "Failed to post $h->{id} to London API, response was " . $response->code . " $out" );
+ return 1;
+ }
+ my ($id) = $out =~ /<caseid>(.*?)<\/caseid>/;
+ my ($org) = $out =~ /<organisation>(.*?)<\/organisation>/;
+ my ($team) = $out =~ /<team>(.*?)<\/team>/;
+
+ $org = london_lookup($org);
+ $row->external_id( $id );
+ $row->external_body( $org );
+ $row->external_team( $team );
+ $self->success(1);
+ return 0;
+}
+
+sub london_lookup {
+ my $org = shift || '';
+ my $str = "Unknown ($org)";
+ open(FP, "$FindBin::Bin/../data/dft.csv");
+ while (<FP>) {
+ /^(.*?),(.*)/;
+ if ($org eq $1) {
+ $str = $2;
+ last;
+ }
+ }
+ close FP;
+ return $str;
+}
+
+1;