summary refs log tree commit diff
path: root/lib/jitterbug/WebService.pm
blob: c8be8fd6dadb6d71d39d3244a3f439d8c3732b6c (plain) (blame)
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
package jitterbug::WebService;

use Dancer ':syntax';
use jitterbug::Plugin::Redis;

use File::Spec;

set serializer => 'JSON';

get '/build/:project/:commit/:version' => sub {
    my $project = params->{project};
    my $commit  = params->{commit};
    my $version = params->{version};

    my $conf = setting 'jitterbug';

    my $file = File::Spec->catfile( $conf->{reports}->{dir},
        $project, $commit, $version . '.txt' );

    if ( -f $file ) {
        open my $fh, '<', $file;
        my @content = <$fh>;
        close $fh;

        if ( request->accept =~ m!application/json! ) {
            return {
                commit  => $commit,
                version => $version,
                content => join( '', @content ),
            };
        }
        else {
            content_type 'text/plain';
            return join( '', @content );
        }
    }
};

1;