aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA/Mirrors/Controller/Api.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MGA/Mirrors/Controller/Api.pm')
-rw-r--r--lib/MGA/Mirrors/Controller/Api.pm79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/MGA/Mirrors/Controller/Api.pm b/lib/MGA/Mirrors/Controller/Api.pm
new file mode 100644
index 0000000..91846dc
--- /dev/null
+++ b/lib/MGA/Mirrors/Controller/Api.pm
@@ -0,0 +1,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 ($product, $version, $arch) = $arg =~ m/^([^\.]+)\.(.+)\.([^\.]+)\.list$/;
+
+ $c->log->debug("$product, $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;