Skip to content

Commit

Permalink
MetaCPAN broke their old API
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 2, 2017
1 parent 5ab8c76 commit d35caf6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

7.33 2017-06-01
7.33 2017-06-03
- Fixed version command to use the new MetaCPAN API, since the old one got
shut down.

7.32 2017-05-28
- Added -f option to get command.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/get.pm
Expand Up @@ -151,7 +151,7 @@ Mojolicious::Command::get - Get command
mojo get mojolicious.org a attr href
mojo get mojolicious.org '*' attr id
mojo get mojolicious.org 'h1, h2, h3' 3 text
mojo get https://api.metacpan.org/v0/author/SRI /name
mojo get https://fastapi.metacpan.org/v1/author/SRI /name
mojo get -H 'Host: example.com' http+unix://%2Ftmp%2Fmyapp.sock/index.html
Options:
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Command/version.pm
Expand Up @@ -33,7 +33,8 @@ EOF
# Check latest version on CPAN
my $latest = eval {
$self->app->ua->max_redirects(10)->tap(sub { $_->proxy->detect })
->get('api.metacpan.org/v0/release/Mojolicious')->result->json->{version};
->get('fastapi.metacpan.org/v1/release/Mojolicious')
->result->json->{version};
} or return;

my $msg = 'This version is up to date, have fun!';
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -505,7 +505,7 @@ latency backend web services.
# Search MetaCPAN for "mojolicious"
get '/' => sub {
my $c = shift;
$c->ua->get('api.metacpan.org/v0/module/_search?q=mojolicious' => sub {
$c->ua->get('fastapi.metacpan.org/v1/module/_search?q=mojolicious' => sub {
my ($ua, $tx) = @_;
$c->render('metacpan', hits => $tx->result->json->{hits}{hits});
});
Expand Down Expand Up @@ -549,7 +549,7 @@ style.
# Concurrent requests
sub {
my $delay = shift;
my $url = Mojo::URL->new('api.metacpan.org/v0/module/_search');
my $url = Mojo::URL->new('fastapi.metacpan.org/v1/module/_search');
$url->query({sort => 'date:desc'});
$c->ua->get($url->clone->query({q => 'mojo'}) => $delay->begin);
$c->ua->get($url->clone->query({q => 'minion'}) => $delay->begin);
Expand Down Expand Up @@ -977,7 +977,7 @@ Who actually controls the event loop backend is not important.
# Search MetaCPAN for "mojolicious"
my $cv = AE::cv;
my $ua = Mojo::UserAgent->new;
$ua->get('api.metacpan.org/v0/module/_search?q=mojolicious' => sub {
$ua->get('fastapi.metacpan.org/v1/module/_search?q=mojolicious' => sub {
my ($ua, $tx) = @_;
$cv->send($tx->result->json('/hits/hits/0/_source/release'));
});
Expand Down Expand Up @@ -1080,7 +1080,7 @@ L<Mojo::Message/"json">.
my $ua = Mojo::UserAgent->new;

# Search MetaCPAN for "mojolicious" and list latest releases
my $url = Mojo::URL->new('http://api.metacpan.org/v0/release/_search');
my $url = Mojo::URL->new('http://fastapi.metacpan.org/v1/release/_search');
$url->query({q => 'mojolicious', sort => 'date:desc'});
for my $hit (@{$ua->get($url)->result->json->{hits}{hits}}) {
say "$hit->{_source}{name} ($hit->{_source}{author})";
Expand Down Expand Up @@ -1475,7 +1475,7 @@ You can follow redirects and view the headers for all messages.

Extract just the information you really need from JSON data structures.

$ mojo get https://api.metacpan.org/v0/author/SRI /name
$ mojo get https://fastapi.metacpan.org/v1/author/SRI /name

This can be an invaluable tool for testing your applications.

Expand Down

0 comments on commit d35caf6

Please sign in to comment.