NAME

InternetData - the official Perl client for the InternetData API

SYNOPSIS

use InternetData;

my $client = InternetData->new(api_key => $ENV{INTERNETDATA_API_KEY});

for my $db (@{ $client->database->list }) {
    next unless $db->{standing} eq 'licensed';
    my $id = $db->{versions}[-1]{id};
    $client->database->download($id, 'csvgz', "./$id.csv.gz");
}

DESCRIPTION

Downloads InternetData's licensed IP and network databases, and reads what the API publishes about them: the catalog, per-database metadata, checksums, and your organization's recent download attempts.

Every endpoint published today needs a key carrying the db.download scope. "new" takes one as an option rather than requiring it: a client built without a key sends no Authorization header at all, which is what a database served without a licence would need.

METHODS

The seven calls live on InternetData::Database, reached as "database". Each has a _p twin returning a Mojo::Promise and takes a per-call retries option. Failures die with an InternetData::Error.

new

my $client = InternetData->new(api_key => '...', %options);
api_key

A console-issued key carrying the db.download scope. Keys are default-deny, so an existing key does not reach these endpoints until the scope is added to it. Optional: omit it, or pass an empty string, and no Authorization header is sent. Every endpoint published today answers 401 without one.

base_url

Defaults to https://internetdata.io.

retries

Attempts after a retryable failure. Defaults to 2, and is overridable per call.

timeout

Per-request timeout in seconds. Defaults to 30. It is lifted for a file transfer, which is not a request whose duration a caller can predict.

ua

Your own Mojo::UserAgent, for a proxy or custom TLS settings. The client sets max_redirects to 0 on whichever agent it is given: the download endpoint answers 302 and that redirect is the answer, so following it would pull a multi-gigabyte file into memory.

database

my $databases = $client->database->list;

The licensed database downloads, which is every call this API has. See InternetData::Database.

NON-BLOCKING USE

Every call has a _p twin returning a Mojo::Promise, so the library drops into a Mojolicious application without a worker. The blocking forms are those promises plus a wait, so nothing is duplicated and both paths retry identically.

$client->database->list_p
    ->then(sub { say $_->{base} for @{ shift() } })
    ->catch(sub { warn shift })
    ->wait;

Inside an already running Mojo::IOLoop the blocking forms cannot work and croak saying so. Use the _p forms there.

SEE ALSO

InternetData::Database, InternetData::Error.

LICENSE

MIT. Copyright Mslm Dev.