diff options
author | Dave Arter <davea@mysociety.org> | 2018-01-24 18:01:56 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-02-12 16:17:25 +0000 |
commit | 7ec0d3f67766764967a8bb92099c582f8bd6aaf5 (patch) | |
tree | 2e9da126c8a3ea7994e43c1c693e5aa489b687c6 /t/Mock | |
parent | 27027ad882f5e1ddb8f2445e3b63972524ba82aa (diff) |
Cobrands can pass `components` to Google Geocoder.
This allows more fine grained control over the geocoder search, e.g. to
specify the administrative area or town. See the geocoder api docs:
https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
Diffstat (limited to 't/Mock')
-rw-r--r-- | t/Mock/GoogleGeocoder.pm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/t/Mock/GoogleGeocoder.pm b/t/Mock/GoogleGeocoder.pm new file mode 100644 index 000000000..fd741c00e --- /dev/null +++ b/t/Mock/GoogleGeocoder.pm @@ -0,0 +1,36 @@ +package t::Mock::GoogleGeocoder; + +use JSON::MaybeXS; +use Web::Simple; +use LWP::Protocol::PSGI; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->utf8->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /maps/api/geocode/json + ?*) { + my ($self, $args) = @_; + my $response = {}; + if ($args->{address} =~ /result/) { + $response->{status} = 'OK'; + push @{$response->{results}}, { formatted_address => 'High Street, Old Town, City of Edinburgh, Scotland', geometry => { location => { lng => -3.1858425, lat => 55.9504009 } } }; + } + if ($args->{address} eq 'two results') { + push @{$response->{results}}, { geometry => { location => { lat => "55.8596449", "lng" => "-4.240377" } }, formatted_address => "High Street, Collegelands, Merchant City, Glasgow, Scotland" }; + } + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode($response); + }; + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +LWP::Protocol::PSGI->register(t::Mock::GoogleGeocoder->to_psgi_app, host => 'maps.googleapis.com'); + +__PACKAGE__->run_if_script; |