diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-01-27 11:38:59 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-01-29 15:08:18 +0000 |
commit | b4e69645bd2ff24fb603bf7461e2c80b316eaeaa (patch) | |
tree | 0b25ff4d36bfe3b9685c8d3818760ab3e41f2950 /perllib/Open311 | |
parent | 2679b30e530861ba7c2bef6f36a60242872bd6a7 (diff) |
Spot media_url in Open311 GetServiceRequestUpdate.
Fixes #1315.
Diffstat (limited to 'perllib/Open311')
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 6d846de42..4b6d56146 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -3,6 +3,7 @@ package Open311::GetServiceRequestUpdates; use Moo; use Open311; use FixMyStreet::DB; +use FixMyStreet::App::Model::PhotoSet; use DateTime::Format::W3CDTF; has system_user => ( is => 'rw' ); @@ -116,6 +117,19 @@ 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}) { + my $ua = LWP::UserAgent->new; + my $res = $ua->get($request->{media_url}); + if ( $res->is_success && $res->content_type eq 'image/jpeg' ) { + my $photoset = FixMyStreet::App::Model::PhotoSet->new({ + data_items => [ $res->decoded_content ], + }); + my $data = $photoset->get_raw_image_data(0); + $comment->photo($data->[0]); + } + } + # if the comment is older than the last update # do not change the status of the problem as it's # tricky to determine the right thing to do. |