aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-06-01 10:08:55 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-06-03 16:58:25 +0100
commita7541a181013378da0090da53847c882881825d0 (patch)
tree9558f83fbac4712c4ca2711daff0ef9ea769dc10
parentf8859e29f5bcf75c1b2acb934bd4353f83c5a2c1 (diff)
Add user_country call that uses Gaze.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App.pm5
-rw-r--r--perllib/FixMyStreet/Gaze.pm8
3 files changed, 14 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a2466913..096c07bd8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- `#geolocate_link` is now easier to re-style. #3006
- Links inside `#front-main` can be customised using `$primary_link_*` Sass variables. #3007
- Add option to show front end testing code coverage. #3036
+ - Add function to fetch user's country from Gaze.
* v3.0.1 (6th May 2020)
- New features:
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 6a41d93a9..4ca6f23cb 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -536,6 +536,11 @@ sub check_2fa {
return 0;
}
+sub user_country {
+ my $c = shift;
+ return FixMyStreet::Gaze::get_country_from_ip($c->req->address);
+}
+
=head1 SEE ALSO
L<FixMyStreet::App::Controller::Root>, L<Catalyst>
diff --git a/perllib/FixMyStreet/Gaze.pm b/perllib/FixMyStreet/Gaze.pm
index bccc81d8c..e2b2e0e08 100644
--- a/perllib/FixMyStreet/Gaze.pm
+++ b/perllib/FixMyStreet/Gaze.pm
@@ -3,6 +3,7 @@ package FixMyStreet::Gaze;
use strict;
use warnings;
+use FixMyStreet;
use mySociety::Gaze;
sub get_radius_containing_population ($$) {
@@ -24,4 +25,11 @@ sub get_radius_containing_population ($$) {
return $dist;
}
+sub get_country_from_ip {
+ my ($ip) = @_;
+ return 'GB' if FixMyStreet->test_mode;
+ # uncoverable statement
+ return mySociety::Gaze::get_country_from_ip($ip);
+}
+
1;