aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2016-06-15 12:43:54 +0100
committerMatthew Somerville <matthew@mysociety.org>2016-06-15 13:47:53 +0100
commit8d428f9c8fd9e25821560a20d00d444d9fb67e08 (patch)
tree52b75a1f922b589a151acccc0ee38c2ac9a90f59 /perllib/Open311
parent96c72fa72e547a2ce5b435db3cae8c3c45efafc1 (diff)
Tidy up Open311 XML handling.
Parse the XML in such a way other parts of the code do not have to worry about single-value folding or the like.
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm3
-rw-r--r--perllib/Open311/GetUpdates.pm19
-rw-r--r--perllib/Open311/PopulateServiceList.pm12
3 files changed, 7 insertions, 27 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index daa5fb64d..921b2996d 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -122,8 +122,7 @@ sub update_comments {
}
);
- # ref test as XML::Simple will have returned an empty hashref for empty element
- if ($request->{media_url} && !ref $request->{media_url}) {
+ if ($request->{media_url}) {
my $ua = LWP::UserAgent->new;
my $res = $ua->get($request->{media_url});
if ( $res->is_success && $res->content_type eq 'image/jpeg' ) {
diff --git a/perllib/Open311/GetUpdates.pm b/perllib/Open311/GetUpdates.pm
index 901e78809..1b1e339e3 100644
--- a/perllib/Open311/GetUpdates.pm
+++ b/perllib/Open311/GetUpdates.pm
@@ -42,23 +42,12 @@ sub update_reports {
my ( $self, $report_ids, $open311, $body ) = @_;
my $service_requests = $open311->get_service_requests( $report_ids );
-
- my $requests;
-
- # XML::Simple is a bit inconsistent in how it structures
- # things depending on the number of children an element has :(
- if ( ref $service_requests->{request} eq 'ARRAY' ) {
- $requests = $service_requests->{request};
- }
- else {
- $requests = [ $service_requests->{request} ];
- }
+ my $requests = $service_requests->{request};
for my $request (@$requests) {
- # if it's a ref that means it's an empty element
- # however, if there's no updated date then we can't
- # tell if it's newer that what we have so we should skip it
- next if ref $request->{updated_datetime} || ! exists $request->{updated_datetime};
+ # if there's no updated date then we can't
+ # tell if it's newer than what we have so we should skip it
+ next unless $request->{updated_datetime};
my $request_id = $request->{service_request_id};
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 3236f3798..dd3bd65d6 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -71,8 +71,6 @@ sub process_services {
$self->found_contacts( [] );
my $services = $list->{service};
- # XML might only have one result and then squashed the 'array'-ness
- $services = [ $services ] unless ref $services eq 'ARRAY';
foreach my $service ( @$services ) {
$self->_current_service( $service );
$self->process_service;
@@ -205,13 +203,7 @@ sub _add_meta_to_contact {
print "Fetching meta data for " . $self->_current_service->{service_code} . "\n" if $self->verbose >= 2;
my $meta_data = $self->_current_open311->get_service_meta_info( $self->_current_service->{service_code} );
- if ( ref $meta_data->{ attributes }->{ attribute } eq 'HASH' ) {
- $meta_data->{ attributes }->{ attribute } = [
- $meta_data->{ attributes }->{ attribute }
- ];
- }
-
- if ( ! $meta_data->{attributes}->{attribute} ) {
+ unless ($meta_data->{attributes}) {
warn sprintf( "Empty meta data for %s at %s",
$self->_current_service->{service_code},
$self->_current_body->endpoint )
@@ -225,7 +217,7 @@ sub _add_meta_to_contact {
map { $_->{description} =~ s/:\s*//; $_ }
# there is a display order and we only want to sort once
sort { $a->{order} <=> $b->{order} }
- @{ $meta_data->{attributes}->{attribute} };
+ @{ $meta_data->{attributes} };
# Some Open311 endpoints, such as Bromley and Warwickshire send <metadata>
# for attributes which we *don't* want to display to the user (e.g. as