aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Open311.pm')
-rw-r--r--perllib/Open311.pm57
1 files changed, 39 insertions, 18 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index a34677a38..dee985fca 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -15,15 +15,16 @@ has test_mode => ( is => 'ro', isa => 'Bool' );
has test_uri_used => ( is => 'rw', 'isa' => 'Str' );
has test_req_used => ( is => 'rw' );
has test_get_returns => ( is => 'rw' );
-has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml', service_request_updates => 'update.xml', update => 'update.xml' } } );
+has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml', service_request_updates => 'servicerequestupdates.xml', update => 'servicerequestupdates.xml' } } );
has debug => ( is => 'ro', isa => 'Bool', default => 0 );
has debug_details => ( is => 'rw', 'isa' => 'Str', default => '' );
has success => ( is => 'rw', 'isa' => 'Bool', default => 0 );
has error => ( is => 'rw', 'isa' => 'Str', default => '' );
has always_send_latlong => ( is => 'ro', isa => 'Bool', default => 1 );
has send_notpinpointed => ( is => 'ro', isa => 'Bool', default => 0 );
-has basic_description => ( is => 'ro', isa => 'Bool', default => 0 );
+has extended_description => ( is => 'ro', isa => 'Str', default => 1 );
has use_service_as_deviceid => ( is => 'ro', isa => 'Bool', default => 0 );
+has use_extended_updates => ( is => 'ro', isa => 'Bool', default => 0 );
has extended_statuses => ( is => 'ro', isa => 'Bool', default => 0 );
before [
@@ -79,9 +80,13 @@ sub send_service_request {
}
}
- warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details );
- return 0;
+ warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details )
+ unless $problem->send_fail_count;
+ } else {
+ warn sprintf( "Failed to submit problem %s over Open311, details:\n%s", $problem->id, $self->error)
+ unless $problem->send_fail_count;
}
+ return 0;
}
sub _populate_service_request_params {
@@ -91,12 +96,12 @@ sub _populate_service_request_params {
my $service_code = shift;
my $description;
- if ( $self->basic_description ) {
- $description = $problem->detail;
- } else {
+ if ( $self->extended_description ) {
$description = $self->_generate_service_request_description(
$problem, $extra
);
+ } else {
+ $description = $problem->detail;
}
my ( $firstname, $lastname ) = ( $problem->user->name =~ /(\w+)\.?\s+(.+)/ );
@@ -164,8 +169,6 @@ sub _generate_service_request_description {
my $extra = shift;
my $description = <<EOT;
-title: @{[$problem->title()]}
-
detail: @{[$problem->detail()]}
url: $extra->{url}
@@ -173,6 +176,12 @@ url: $extra->{url}
Submitted via FixMyStreet
EOT
;
+ if ($self->extended_description ne 'oxfordshire') {
+ $description = <<EOT . $description;
+title: @{[$problem->title()]}
+
+EOT
+ }
return $description;
}
@@ -263,9 +272,13 @@ sub post_service_request_update {
}
}
- warn sprintf( "Failed to submit comment %s over Open311, response - %s\n%s\n", $comment->id, $response, $self->debug_details );
- return 0;
+ warn sprintf( "Failed to submit comment %s over Open311, response - %s\n%s\n", $comment->id, $response, $self->debug_details )
+ unless $comment->send_fail_count;
+ } else {
+ warn sprintf( "Failed to submit comment %s over Open311, details\n%s\n", $comment->id, $self->error)
+ unless $comment->send_fail_count;
}
+ return 0;
}
sub _populate_service_request_update_params {
@@ -303,18 +316,23 @@ sub _populate_service_request_update_params {
}
my $params = {
- update_id_ext => $comment->id,
updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)),
service_request_id => $comment->problem->external_id,
- service_request_id_ext => $comment->problem->id,
status => $status,
email => $comment->user->email,
description => $comment->text,
- public_anonymity_required => $comment->anonymous ? 'TRUE' : 'FALSE',
last_name => $lastname,
first_name => $firstname,
};
+ if ( $self->use_extended_updates ) {
+ $params->{public_anonymity_required} = $comment->anonymous ? 'TRUE' : 'FALSE',
+ $params->{update_id_ext} = $comment->id;
+ $params->{service_request_id_ext} = $comment->problem->id;
+ } else {
+ $params->{update_id} = $comment->id;
+ }
+
if ( $comment->photo ) {
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($comment->cobrand)->new();
my $email_base_url = $cobrand->base_url($comment->cobrand_data);
@@ -366,7 +384,11 @@ sub _get {
$self->success(1);
} else {
$self->success(0);
- $self->error( $res->status_line );
+ $self->error( sprintf(
+ "request failed: %s\n%s\n",
+ $res->status_line,
+ $uri->as_string
+ ) );
}
}
@@ -405,13 +427,12 @@ sub _post {
return $res->decoded_content;
} else {
$self->success(0);
- $self->error( sprintf(
+ $self->error( sprintf(
"request failed: %s\nerror: %s\n%s\n",
$res->status_line,
$self->_process_error( $res->decoded_content ),
$self->debug_details
) );
- warn $self->error;
return 0;
}
}
@@ -440,7 +461,7 @@ sub _get_xml_object {
my $obj;
eval {
- $obj = $simple ->XMLin( $xml );
+ $obj = $simple ->parse_string( $xml, ForceArray => [ qr/^key$/, qr/^name$/ ] );
};
return $obj;