aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-02-27 15:21:41 +0000
committerStruan Donald <struan@exo.org.uk>2012-02-27 15:21:41 +0000
commit21b82d30b9348c3de50f711d8b7c80bcdaf2c756 (patch)
tree51d2551231255e558dc6d630cb576d7716be7a62
parent6b5a40f54eb4ef87724ecbd53513cf707b00d106 (diff)
put something in the base class and make things inherit from it
-rw-r--r--perllib/FixMyStreet/SendReport.pm17
-rw-r--r--perllib/FixMyStreet/SendReport/EastHants.pm23
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm21
-rw-r--r--perllib/FixMyStreet/SendReport/London.pm19
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm25
5 files changed, 40 insertions, 65 deletions
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
index 3a79bd82a..f2ebdd3d7 100644
--- a/perllib/FixMyStreet/SendReport.pm
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -2,6 +2,23 @@ package FixMyStreet::SendReport;
use Moose;
+has 'councils' => (is => 'rw', isa => 'HashRef', default => sub { {} } );
+has 'to' => (is => 'rw', isa => 'ArrayRef', default => sub { [] } );
+
+sub reset {
+ my $self = shift;
+
+ $self->councils( {} );
+ $self->to( [] );
+}
+
+sub add_council {
+ my $self = shift;
+ my $council = shift;
+ my $name = shift;
+
+ $self->councils->{ $council } = $name;
+}
1;
diff --git a/perllib/FixMyStreet/SendReport/EastHants.pm b/perllib/FixMyStreet/SendReport/EastHants.pm
index 0e9944b18..aa290742e 100644
--- a/perllib/FixMyStreet/SendReport/EastHants.pm
+++ b/perllib/FixMyStreet/SendReport/EastHants.pm
@@ -1,25 +1,15 @@
package FixMyStreet::SendReport::Email;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
use Error qw(:try);
use Encode;
use mySociety::Web qw(ent);
use EastHantsWSDL;
-my %councils = ();
-my @to;
-
-sub reset {
- %councils = ();
- @to = ();
-}
-
-sub add_council {
- my $council = shift;
- my $name = shift;
-
- $councils{ $council } = $name;
-}
-
sub construct_message {
my %h = @_;
my $message = '';
@@ -44,6 +34,9 @@ sub send {
my ( $row, $h, $to, $template, $recips, $nomail ) = @_;
+ # FIXME: should not recreate this each time
+ my $eh_service;
+
$h->{category} = 'Customer Services' if $h->{category} eq 'Other';
$h->{message} = construct_message( %$h );
my $return = 1;
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index ab9d7edcc..c231a6b61 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -5,27 +5,6 @@ use namespace::autoclean;
BEGIN { extends 'FixMyStreet::SendReport'; }
-has 'councils' => (is => 'rw', isa => 'HashRef', default => sub { {} } );
-has 'to' => (is => 'rw', isa => 'ArrayRef', default => sub { [] } );
-
-my %councils = ();
-my @to;
-
-sub reset {
- my $self = shift;
-
- $self->councils( {} );
- $self->to( [] );
-}
-
-sub add_council {
- my $self = shift;
- my $council = shift;
- my $name = shift;
-
- $self->councils->{ $council } = $name;
-}
-
sub build_recipient_list {
my $self = shift;
my $row = shift;
diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm
index cb76c7a24..29368314f 100644
--- a/perllib/FixMyStreet/SendReport/London.pm
+++ b/perllib/FixMyStreet/SendReport/London.pm
@@ -1,25 +1,16 @@
package FixMyStreet::SendReport::Email;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
use Digest::MD5;
use LWP::UserAgent;
use LWP::Simple;
use Utils;
-my %councils = ();
-my @to;
-
-sub reset {
- %councils = ();
- @to = ();
-}
-
-sub add_council {
- my $council = shift;
- my $name = shift;
-
- $councils{ $council } = $name;
-}
sub construct_message {
my %h = @_;
return <<EOF,
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index a76c44cce..cb41de336 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -1,28 +1,21 @@
package FixMyStreet::SendReport::Open311;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
use FixMyStreet::App;
use mySociety::Config;
use Open311;
-my %councils = ();
-my @to;
-
-sub reset {
- %councils = ();
- @to = ();
-}
-
-sub add_council {
- my $council = shift;
- my $name = shift;
-
- $councils{ $council } = $name;
-}
-
sub send {
return if mySociety::Config::get('STAGING_SITE');
my $self = shift;
my ( $row, $h, $to, $template, $recips, $nomail ) = @_;
+
+ my $result = -1;
+
foreach my $council ( keys %{ $self->councils } ) {
my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $self->councils->{ $council }, endpoint => { '!=', '' } } )->first;
#print 'posting to end point for ' . $conf->area_id . "\n" if $verbose;
@@ -69,6 +62,8 @@ sub send {
}
}
}
+
+ return $result;
}
1;