aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA/Mirrors/Controller/Api.pm
blob: 6f85a80b32b5bf19d631766e96078d1857ca9985 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package MGA::Mirrors::Controller::Api;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

MGA::Mirrors::Controller::Api - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->response->body('Matched MGA::Mirrors::Controller::Api in Api.');
}

sub list :Path :Args(1) {
    my ( $self, $c, $arg ) = @_;

    my ($type, $version, $arch) = $arg =~ m/^([^\.]+)\.(.+)\.([^\.]+)\.list$/;

    $c->log->debug("$type, $version, $arch");

    my $list = $c->model('Mirrors')->find_distributions(
        {
        version => $version,
        arch => $arch,
        exists => 1,
        public => 1,
        }
    );

    $c->stash->{current_view} = '';
    $c->response->body(join("\n",
        map {
            my @tags;
            push(@tags, 'continent=' . $_->{ccode}) if ($_->{ccode});
            push(@tags, 'zone=' . $_->{code}) if ($_->{code});
            push(@tags, 'country=' . $_->{country}) if ($_->{country});
            push(@tags, 'city=' . $_->{city}) if ($_->{city});
            push(@tags, 'latitude=' . $_->{latitude}) if ($_->{latitude});
            push(@tags, 'longitude=' . $_->{longitude}) if ($_->{longitude});
            push(@tags, 'version=' . $version);
            push(@tags, 'version=' . $arch);
            push(@tags, 'type=' . 'distrib');
            push(@tags, 'url=' . $_->{url}) if ($_->{url});
            join(',', @tags);
        } @$list
    ) . "\n");
}


=head1 AUTHOR

Olivier Thauvin

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;