aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/FakeMapit.pm
blob: 0ec13ebfa7de1f1432263ec0b5db8867b98e0200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package FixMyStreet::App::Controller::FakeMapit;
use Moose;
use namespace::autoclean;
use JSON::MaybeXS;
use LWP::Simple;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

FixMyStreet::App::Controller::FakeMapit - Catalyst Controller

=head1 DESCRIPTION

A controller to fake mapit when we don't have it. If you set MAPIT_URL to
.../fakemapit/ it should all just work, with a mapit that assumes the whole
world is one area, with ID 161 and name "Everywhere".

=head1 METHODS

=cut

my $area = { "name" => "Everywhere", "type" => "ZZZ", "id" => 161 };

# The user should have the web server proxying this,
# but for development we can also do it on the server.
sub proxy : Path('/mapit') {
    my ($self, $c) = @_;
    (my $path = $c->req->uri->path_query) =~ s{^/mapit/}{};
    my $url = FixMyStreet->config('MAPIT_URL') . $path;
    my $kml = LWP::Simple::get($url);
    $c->response->body($kml);
}

sub output : Private {
    my ( $self, $c, $data ) = @_;
    my $body = encode_json($data);
    $c->res->content_type('application/json; charset=utf-8');
    $c->res->body( $body );
}

sub point : Local {
    my ( $self, $c ) = @_;
    $c->detach( 'output', [ { 161 => $area } ] );
}

sub area : Local {
    my ( $self, $c ) = @_;
    $c->detach( 'output', [ $area ] );
}

sub areas : Local {
    my ( $self, $c ) = @_;
    $c->detach( 'output', [ { 161 => $area } ] );
}

sub children : Path('area/161/children') : Args(0) {
    my ( $self, $c ) = @_;
    $c->detach( 'output', [ {} ] );
}

__PACKAGE__->meta->make_immutable;

1;
owered_by.png', 'resourceSets' => [ { 'resources' => [ { 'geocodePoints' => [ { 'calculationMethod' => 'Interpolation', 'coordinates' => [ '55.9532357007265', '-3.18906001746655' ], 'usageTypes' => [ 'Display', 'Route' ], 'type' => 'Point' } ], 'entityType' => 'Address', 'name' => '18 N Bridge, Edinburgh EH1 1', 'point' => { 'coordinates' => [ '55.9532357007265', '-3.18906001746655' ], 'type' => 'Point' }, 'bbox' => [ '55.9493729831558', '-3.19825819222605', '55.9570984182972', '-3.17986184270704' ], 'matchCodes' => [ 'Good' ], 'address' => { 'countryRegion' => 'United Kingdom', 'adminDistrict2' => 'Edinburgh City', 'adminDistrict' => 'Scotland', 'addressLine' => '18 North Bridge', 'formattedAddress' => '18 N Bridge, Edinburgh EH1 1', 'postalCode' => 'EH1 1', 'locality' => 'Edinburgh' }, 'confidence' => 'Medium', '__type' => 'Location:http://schemas.microsoft.com/search/local/ws/rest/v1' } ], 'estimatedTotal' => 1 } ], 'copyright' => "Copyright \x{a9} 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.", 'statusCode' => 200, 'authenticationResultCode' => 'ValidCredentials' } ); $report->postcode('eh11bb'); $report->update(); $mech->get_ok("/rss/pc/EH11BB/2"); $mech->content_contains( "Testing, 10th October, EH1 1BB" ); $mech->content_contains( '18 North Bridge, Edinburgh' ); $report->postcode('Princes St, Edinburgh'); $report->update(); $mech->get_ok("/rss/pc/EH11BB/2"); $mech->content_contains( "Testing, 10th October, Princes St, Edinburgh" ); $report->delete(); $user1->delete(); done_testing();