aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/update-all-reports4
-rw-r--r--cpanfile8
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm5
-rw-r--r--perllib/FixMyStreet/Script/Reports.pm3
-rw-r--r--perllib/Utils/OpenStreetMap.pm44
-rw-r--r--t/Mock/Facebook.pm2
-rw-r--r--t/Mock/MapIt.pm2
-rw-r--r--t/Mock/Nominatim.pm2
-rw-r--r--t/cobrand/seesomething.t1
-rw-r--r--t/cobrand/zurich.t1
-rw-r--r--t/open311/endpoint.t9
-rw-r--r--t/open311/endpoint/mysociety.t5
-rw-r--r--t/open311/endpoint/spark.t2
-rw-r--r--t/open311/endpoint/warwick.t5
-rw-r--r--templates/email/default/submit.txt2
-rw-r--r--templates/email/fixmystreet/submit-oxfordshire.txt2
-rw-r--r--templates/email/fixmystreet/submit.txt2
17 files changed, 71 insertions, 28 deletions
diff --git a/bin/update-all-reports b/bin/update-all-reports
index 60da837e9..d951756e4 100755
--- a/bin/update-all-reports
+++ b/bin/update-all-reports
@@ -22,7 +22,7 @@ use FixMyStreet::DB;
use File::Path ();
use File::Slurp;
-use JSON;
+use JSON::MaybeXS;
use List::MoreUtils qw(zip);
my $fourweeks = 4*7*24*60*60;
@@ -89,7 +89,7 @@ if ( FixMyStreet->config('BASE_URL') =~ /emptyhomes/ ) {
}
}
-my $body = JSON->new->utf8(1)->encode( {
+my $body = encode_json( {
fixed => \%fixed,
open => \%open,
} );
diff --git a/cpanfile b/cpanfile
index a8592917d..e0a125a29 100644
--- a/cpanfile
+++ b/cpanfile
@@ -101,7 +101,6 @@ feature 'open311-endpoint', 'Open311::Endpoint specific requirements' => sub {
requires 'Data::Rx';
requires 'MooX::HandlesVia';
requires 'Types::Standard';
- requires 'LWP::Protocol::PSGI'; # for testing end-to-end
requires 'DateTime::Format::Oracle'; # for EXOR
};
@@ -118,14 +117,12 @@ requires 'File::ChangeNotify';
requires 'Path::Tiny';
requires 'File::Find::Rule';
-feature 'run-tests', 'Spin up a test database and config to run tests' => sub {
- requires 'Test::PostgreSQL';
-};
-
# Modules used by the test suite
+requires 'Test::PostgreSQL';
requires 'CGI::Simple';
requires 'HTTP::Headers';
requires 'HTTP::Response';
+requires 'LWP::Protocol::PSGI';
requires 'Sort::Key';
requires 'Sub::Override';
requires 'Test::Exception';
@@ -135,6 +132,7 @@ requires 'Test::More', '0.88';
requires 'Test::Warn';
requires 'Test::WWW::Mechanize::Catalyst';
requires 'Web::Scraper';
+requires 'Web::Simple';
#################################################################
#
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index df4cab2d8..bfb1c5535 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -4,7 +4,7 @@ use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
-use JSON;
+use JSON::MaybeXS;
use File::Path;
use File::Slurp;
use FixMyStreet::App::Model::PhotoSet;
@@ -112,9 +112,8 @@ sub upload : Local {
$out = { id => $fileid };
}
- my $body = JSON->new->utf8(1)->encode($out);
$c->res->content_type('application/json; charset=utf-8');
- $c->res->body($body);
+ $c->res->body(encode_json($out));
}
=head2 process_photo
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index 55b1bb21c..d26e0fa70 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -7,6 +7,7 @@ use CronFns;
use DateTime::Format::Pg;
use Utils;
+use Utils::OpenStreetMap;
use mySociety::MaPit;
use FixMyStreet;
@@ -91,8 +92,10 @@ sub send(;$) {
: _('The user could not locate the problem on a map, but to see the area around the location they entered');
$h{closest_address} = '';
+ $h{osm_url} = Utils::OpenStreetMap::short_url($h{latitude}, $h{longitude});
if ( $row->used_map ) {
$h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row );
+ $h{osm_url} .= '?m';
}
if ( $cobrand->allow_anonymous_reports &&
diff --git a/perllib/Utils/OpenStreetMap.pm b/perllib/Utils/OpenStreetMap.pm
new file mode 100644
index 000000000..900569a77
--- /dev/null
+++ b/perllib/Utils/OpenStreetMap.pm
@@ -0,0 +1,44 @@
+package Utils::OpenStreetMap;
+
+use strict;
+use warnings;
+use Exporter 'import';
+use POSIX qw(ceil);
+
+our @EXPORT_OK = qw(short_url);
+
+my $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
+
+sub short_url {
+ my ($lat, $lon, $zoom) = @_;
+ $zoom ||= 16;
+ my $x = ($lon + 180) * 2**32 / 360;
+ my $y = ($lat + 90) * 2**32 / 180;
+ my $code = _interleave($x, $y);
+
+ my $str = '';
+ # add eight to the zoom level, which approximates an accuracy of
+ # one pixel in a tile
+ my $n = ceil(($zoom + 8) / 3) - 1;
+ for my $i (0..$n) {
+ my $digit = ($code >> (58 - 6 * $i)) & 0x3f;
+ $str .= substr($chars, $digit, 1);
+ }
+ # append characters onto the end of the string to represent
+ # partial zoom levels (characters themselves have a granularity
+ # of 3 zoom levels).
+ $str .= "-" x (($zoom + 8) % 3);
+ return "http://osm.org/go/$str";
+}
+
+sub _interleave {
+ my ($x, $y) = @_;
+ my $c = 0;
+ for (my $i=31; $i>=0; $i--) {
+ $c = ($c << 1) | (($x >> $i) & 1);
+ $c = ($c << 1) | (($y >> $i) & 1);
+ }
+ return $c;
+}
+
+1;
diff --git a/t/Mock/Facebook.pm b/t/Mock/Facebook.pm
index 68c63f2d5..eb882af21 100644
--- a/t/Mock/Facebook.pm
+++ b/t/Mock/Facebook.pm
@@ -1,6 +1,6 @@
package t::Mock::Facebook;
-use JSON;
+use JSON::MaybeXS;
use Web::Simple;
use MooX::Types::MooseLike::Base qw(:all);
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index a3bfb10d4..754cc327e 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -1,6 +1,6 @@
package t::Mock::MapIt;
-use JSON;
+use JSON::MaybeXS;
use Web::Simple;
use mySociety::Locale;
diff --git a/t/Mock/Nominatim.pm b/t/Mock/Nominatim.pm
index 3f3cef69a..5c8c549d1 100644
--- a/t/Mock/Nominatim.pm
+++ b/t/Mock/Nominatim.pm
@@ -1,6 +1,6 @@
package t::Mock::Nominatim;
-use JSON;
+use JSON::MaybeXS;
use Web::Simple;
has json => (
diff --git a/t/cobrand/seesomething.t b/t/cobrand/seesomething.t
index 09114f6f9..4da1c9c6e 100644
--- a/t/cobrand/seesomething.t
+++ b/t/cobrand/seesomething.t
@@ -2,7 +2,6 @@ use strict;
use warnings;
use DateTime;
use Test::More;
-use JSON;
use FixMyStreet;
use FixMyStreet::TestMech;
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index b686f78ae..777e9735f 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -6,7 +6,6 @@ use warnings;
use DateTime;
use Test::More;
use Test::LongString;
-use JSON;
use Path::Tiny;
# Check that you have the required locale installed - the following
diff --git a/t/open311/endpoint.t b/t/open311/endpoint.t
index 7e684c491..38314f079 100644
--- a/t/open311/endpoint.t
+++ b/t/open311/endpoint.t
@@ -6,12 +6,11 @@ use Test::MockTime ':all';
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
use t::open311::endpoint::Endpoint1;
my $endpoint = t::open311::endpoint::Endpoint1->new;
-my $json = JSON->new;
subtest "GET Service List" => sub {
my $res = $endpoint->run_test_request( GET => '/services.xml' );
@@ -43,7 +42,7 @@ CONTENT
$res = $endpoint->run_test_request( GET => '/services.json' );
ok $res->is_success, 'json success';
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"keywords" => "deep,hole,wow",
"group" => "highways",
@@ -111,7 +110,7 @@ CONTENT
$res = $endpoint->run_test_request( GET => '/services/POT.json' );
ok $res->is_success, 'json success';
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
{
"service_code" => "POT",
"attributes" => [
@@ -209,7 +208,7 @@ subtest "POST Service Request valid test" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "This is a test service",
"service_request_id" => 0
diff --git a/t/open311/endpoint/mysociety.t b/t/open311/endpoint/mysociety.t
index c63e03e43..d0ad60602 100644
--- a/t/open311/endpoint/mysociety.t
+++ b/t/open311/endpoint/mysociety.t
@@ -6,12 +6,11 @@ use Test::MockTime ':all';
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
use t::open311::endpoint::Endpoint2;
my $endpoint = t::open311::endpoint::Endpoint2->new;
-my $json = JSON->new;
subtest "POST OK" => sub {
diag "Serves as sanity test of subclassing, as well as preparing our data";
@@ -31,7 +30,7 @@ subtest "POST OK" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "This is a test service",
"service_request_id" => 0
diff --git a/t/open311/endpoint/spark.t b/t/open311/endpoint/spark.t
index 589f39baf..015876c94 100644
--- a/t/open311/endpoint/spark.t
+++ b/t/open311/endpoint/spark.t
@@ -4,10 +4,8 @@ use Test::More;
use Open311::Endpoint;
use Data::Dumper;
-use JSON;
my $endpoint = Open311::Endpoint->new;
-my $json = JSON->new;
subtest "Spark test" => sub {
my $spark = $endpoint->spark;
diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t
index 5c47cd529..e5f124c8d 100644
--- a/t/open311/endpoint/warwick.t
+++ b/t/open311/endpoint/warwick.t
@@ -5,7 +5,7 @@ use Test::LongString;
use Test::MockTime ':all';
use Data::Dumper;
-use JSON;
+use JSON::MaybeXS;
use FixMyStreet::DB;
@@ -19,7 +19,6 @@ use Open311::PopulateServiceList;
use Open311::GetServiceRequestUpdates;
my $endpoint = t::open311::endpoint::Endpoint_Warwick->new;
-my $json = JSON->new;
subtest "GET Service List" => sub {
my $res = $endpoint->run_test_request( GET => '/services.xml' );
@@ -59,7 +58,7 @@ subtest "POST OK" => sub {
ok $res->is_success, 'valid request'
or diag $res->content;
- is_deeply $json->decode($res->content),
+ is_deeply decode_json($res->content),
[ {
"service_notice" => "Warwickshire Open311 Endpoint",
"service_request_id" => 1001
diff --git a/templates/email/default/submit.txt b/templates/email/default/submit.txt
index 0ab29e412..52d52669b 100644
--- a/templates/email/default/submit.txt
+++ b/templates/email/default/submit.txt
@@ -25,6 +25,8 @@ Details: <?=$values['detail']?>
Longitude: <?=$values['longitude']?>
+View OpenStreetMap of this location: <?=$values['osm_url']?>
+
<?=$values['closest_address']?>----------
Replies to this email will go to the user who submitted the problem.
diff --git a/templates/email/fixmystreet/submit-oxfordshire.txt b/templates/email/fixmystreet/submit-oxfordshire.txt
index 23a8504ee..9e5efb608 100644
--- a/templates/email/fixmystreet/submit-oxfordshire.txt
+++ b/templates/email/fixmystreet/submit-oxfordshire.txt
@@ -25,6 +25,8 @@ Details: <?=$values['detail']?>
Longitude: <?=$values['longitude']?>
+View OpenStreetMap of this location: <?=$values['osm_url']?>
+
<?=$values['closest_address']?>----------
Replies to this email will go to the user who submitted the problem.
diff --git a/templates/email/fixmystreet/submit.txt b/templates/email/fixmystreet/submit.txt
index 315411fb4..7abed7b50 100644
--- a/templates/email/fixmystreet/submit.txt
+++ b/templates/email/fixmystreet/submit.txt
@@ -25,6 +25,8 @@ Details: <?=$values['detail']?>
Longitude: <?=$values['longitude']?>
+View OpenStreetMap of this location: <?=$values['osm_url']?>
+
<?=$values['closest_address']?>----------
Replies to this email will go to the user who submitted the problem.