blob: 5127509888ccd0ec227fd6a49099ff89436c86ad (
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
|
#!/usr/bin/perl -w -I../perllib
# json.cgi:
# A small JSON API for FixMyStreet
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
# $Id: json.cgi,v 1.4 2010-01-20 11:31:26 matthew Exp $
use strict;
use Error qw(:try);
use JSON;
use Standard;
sub main {
my $q = shift;
my $problems;
my $type = $q->param('type') || '';
my $start_date = $q->param('start_date') || '';
my $end_date = $q->param('end_date') || '';
if ($start_date !~ /^\d{4}-\d\d-\d\d$/ || $end_date !~ /^\d{4}-\d\d-\d\d$/) {
$problems = { error => 'Invalid dates supplied' };
} elsif ($type eq 'new_problems') {
$problems = Problems::created_in_interval($start_date, $end_date);
} elsif ($type eq 'fixed_problems') {
$problems = Problems::fixed_in_interval($start_date, $end_date);
}
print $q->header( -type => 'application/json; charset=utf-8' );
print JSON::to_json($problems);
}
Page::do_fastcgi(\&main);
|