Annotation of HOPE/Net-OpenAMD/script/test_server.pl, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/env perl
! 2:
! 3: use Mojolicious::Lite;
! 4:
! 5: use 5.010;
! 6:
! 7: my %Actions = (
! 8: location => [
! 9: { area => 'Engressia',
! 10: 'time' => '2387',
! 11: x => '46.7369918823242',
! 12: y => '83.1452331542969',
! 13: user => '12983',
! 14: button => 'False',
! 15: },
! 16: ],
! 17: speakers => [
! 18: { name => 'Johnny',
! 19: bio => 'Johnny\'s bio'
! 20: },
! 21: { name => 'Judas',
! 22: bio => 'Judas\'s bio'
! 23: },
! 24: ],
! 25: talks => [
! 26: { speakers => [ 'Judas', 'JohnnyX' ],
! 27: title => 'Ancient Egyptian Music and DRM',
! 28: abstract =>
! 29: 'A discussion of the development of musical notation, which was designed as a means of reproducing music while making it impossible for the general public to perform without permission.',
! 30: 'time' => '2008/7/18 13:00:00',
! 31: track => 'Hooper',
! 32: interests => [ 'media', 'crypto' ]
! 33: },
! 34: ],
! 35: interests => [
! 36: 'new tech', 'activism',
! 37: 'radio', 'lockpicking',
! 38: 'crypto', 'privacy',
! 39: 'ethics', 'telephones',
! 40: 'social engineering', 'hacker spaces',
! 41: 'hardware hacking', 'nostalgia',
! 42: 'communities', 'science',
! 43: 'government', 'network security',
! 44: 'malicious software', 'pen testing',
! 45: 'web', 'niche hacks',
! 46: 'media'
! 47: ],
! 48: users => [
! 49: { name => 'JohnnyX',
! 50: x => '32.54091324',
! 51: y => '54.10958384',
! 52: interests => [
! 53: 'new tech', 'radio',
! 54: 'lockpicking', 'crypto',
! 55: 'telephones', 'social engineering',
! 56: 'hacker spaces', 'hardware hacking',
! 57: 'nostalgia', 'communities',
! 58: 'science', 'network security',
! 59: 'malicious software', 'pen testing',
! 60: ],
! 61: },
! 62: { name => 'andrew',
! 63: x => '32',
! 64: y => '54',
! 65: interests => [
! 66: 'media',
! 67: 'lockpicking', 'crypto',
! 68: 'telephones', 'social engineering',
! 69: 'hacker spaces', 'hardware hacking',
! 70: 'science', 'network security',
! 71: 'malicious software', 'pen testing',
! 72: ],
! 73: },
! 74: { name => 'Judas',
! 75: x => '33',
! 76: y => '52',
! 77: interests => [
! 78: 'media',
! 79: 'lockpicking', 'crypto',
! 80: 'telephones', 'social engineering',
! 81: 'science', 'network security',
! 82: 'malicious software', 'pen testing',
! 83: ],
! 84: },
! 85: ],
! 86: );
! 87:
! 88: get '/' => 'index';
! 89:
! 90: get '/api/:action' => sub {
! 91: my $self = shift;
! 92: my $action = $self->stash('action');
! 93:
! 94: return if !exists $Actions{$action};
! 95:
! 96: my @data = @{ $Actions{$action} };
! 97: foreach my $param ( $self->param() ) {
! 98: next if $param eq 'callback';
! 99: next if $param eq 'action';
! 100:
! 101: my $value = $self->param($param);
! 102: @data = grep $value ~~ $_->{$param}, @data;
! 103: }
! 104: $self->render_json( \@data );
! 105: };
! 106:
! 107: app->start;
! 108: __DATA__
! 109:
! 110: @@ index.html.ep
! 111: % layout 'default';
! 112: Please try /api/action
! 113:
! 114: @@ layouts/default.html.ep
! 115: <!doctype html><html>
! 116: <head><title>Test OpenAMD API!</title></head>
! 117: <body><%== content %></body>
! 118: </html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>