Acme-Free-Public-APIs

 view release on metacpan or  search on metacpan

lib/Acme/Free/Public/APIs.pm  view on Meta::CPAN

use strict;
use warnings;

our $VERSION = '0.9.10';

use HTTP::Tiny;
use JSON            qw/decode_json/;
use Util::H2O::More qw/baptise d2o HTTPTiny2h2o/;

use constant {
    BASEURL => "https://www.freepublicapis.com/api/",
};

sub new {
    my $pkg  = shift;
    my $self = baptise { ua => HTTP::Tiny->new }, $pkg;
    return $self;
}

# https://www.freepublicapis.com/api/apis
# https://www.freepublicapis.com/api/apis/275

sub apis {
    my $self   = shift;
    my $params = d2o -autoundef, { @_ };
    my $URL    = sprintf "%s/apis", BASEURL;

    my $ret = [];
    if ($params->id) {
      $URL = sprintf "%s/%d", $URL, $params->id;
      my $resp = HTTPTiny2h2o $self->ua->get($URL);

lib/Acme/Free/Public/APIs.pm  view on Meta::CPAN

    }
    else {
      my $resp = HTTPTiny2h2o $self->ua->get($URL);
      $ret = $resp->content;
    }

    return $ret;
}


# https://www.freepublicapis.com/api/random

sub random {
    my $self = shift;
    my $URL  = sprintf "%s/random", BASEURL;
    my $resp = HTTPTiny2h2o $self->ua->get($URL);
    return $resp->content;
}

1;

lib/Acme/Free/Public/APIs.pm  view on Meta::CPAN

=head2 C<freeapis> Commandline Client

After installing this module, simply run the command C<freeapis> without
any arguments, and it will print information regarding a randomly selected
free API that is listed on its site. Below you may see a project familiar
to some in the Perl community, the L<https://world.openfoodfacts.org/> Project.

  shell> freeapis
  id:            174
  title:         (🍲) OpenFoodFacts
  site URL:      https://freepublicapis.com/openfoodfacts
  methods:       1
  health:        84
  documentation: https://world.openfoodfacts.org/data
  description:   Open Food Facts is a food products database made by everyone, for everyone. You can use it to make better food choices, and as it is open data, anyone can re-use it for any purpose.
  shell>

=head1 DESCRIPTION

This is the Perl API for the Dog API, profiled at L<https://www.freepublicapis.com/api>.

Contributed as part of the B<FreePublicPerlAPIs> Project described at,
L<https://github.com/oodler577/FreePublicPerlAPIs>.

This fun module is to demonstrate how to use L<Util::H2O::More> and
L<Dispatch::Fu> to make creating easily make API SaaS modules and
clients in a clean and idiomatic way. These kind of APIs tracked at
L<https://www.freepublicapis.com/> are really nice for fun and practice
because they don't require dealing with API keys in the vast majority of cases.

This module is the first one written using L<Util::H2O::More>'s C<HTTPTiny2h2o>
method that looks for C<JSON> in the C<content> key returned via L<HTTP::Tiny>'s
response C<HASH>.

=head1 METHODS

=over 4

lib/Acme/Free/Public/APIs.pm  view on Meta::CPAN

referened API.

  shell>freeapi apis --id 321
  321  100 Church Calendar API

When C<--details> is added, it shows the full amount of information:

  shell>freeapi apis --id 321 --details
  id:            321
  title:         (📅) Church Calendar API
  site URL:      https://freepublicapis.com/church-calendar-api
  methods:       2
  health:        100
  documentation: http://calapi.inadiutorium.cz/api-doc
  description:   The Church Calendar API provides access to calendar data for any day, allowing users to retrieve various liturgical celebrations and details. It supports multiple languages and enables specific queries for feast names and calendar de...
  Found 1 API

=item C<random>

This subcommand takes no arguments. When run it prints out to C<STDOUT> all
the information provided for it.

  shell>
  id:            320
  title:         (🌍) World Wonders
  site URL:      https://freepublicapis.com/world-wonders
  methods:       2
  health:        95
  documentation: https://www.world-wonders-api.org/v0/docs
  description:   Free and open source API providing information about world wonders
  shell>

=back

=head2 Internal Methods



( run in 0.330 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )