#!/usr/bin/env perl
# AP-Client: CLI-based client / toolbox for ActivityPub
# Copyright © 2020-2023 AP-Client Authors <https://hacktivis.me/git/ap-client/>
# SPDX-License-Identifier: BSD-3-Clause
use strict;
use utf8;
our $VERSION = 'v0.1.1_01';

use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;

=head1 NAME

webfinger - Fetch account over WebFinger

=head1 SYNOPSIS

B<webfinger> <user@host>
=cut

my $ua = LWP::UserAgent->new;
$ua->agent("AP-Client fetch <https://hacktivis.me/git/ap-client/>");

if ($#ARGV != 0) {
	print "usage: nodeinfo <hostname>\n";
	exit 1;
}

my $host = $ARGV[0];
my $wk_req = HTTP::Request->new(GET => "$host/.well-known/nodeinfo");
$req->header('Accept' => 'application/json');
my $wk_res = $ua->request($wk_req);

$wk_res->is_success or die 'nodeinfo: Failed to get endpoint: ' . $wk_res->status_line;
$wk_res->header("Content-Type") eq 'application/json' or die 'nodeinfo: Got ' . $wk_res->content_type . ' instead of application/json';

my $well_known = json_decode($wk_res->content);

$well_known->{'links'}

nodeinfo_url=$(curl -sSL -H "${accept_header}" "${url}/.well-known/nodeinfo" | jq '.links[].href' -r | sort | tail -1)

curl -sSL -H "${accept_header}" ${nodeinfo_url} | jq .
