At
view release on metacpan or search on metacpan
lib/At/UserAgent.pm view on Meta::CPAN
# Keep-alive heartbeat every 20 seconds
my $id = Mojo::IOLoop->recurring(
20 => sub {
return unless $tx;
$tx->send( [ 1, 0, 0, 0, 9, '' ] ); # Raw Ping frame
}
);
# Activity watchdog: if we don't get a message for 10 seconds, close and reconnect
my $watchdog;
my $reset_watchdog = sub {
Mojo::IOLoop->remove($watchdog) if defined $watchdog;
$watchdog = Mojo::IOLoop->timer(
10 => sub {
$tx->finish( 4000, "Watchdog timeout" );
}
);
};
$reset_watchdog->();
$tx->on(
message => sub ( $tx, $msg ) {
$reset_watchdog->();
$cb->( $msg, undef );
}
);
$tx->on(
finish => sub ( $tx, $code, $reason ) {
Mojo::IOLoop->remove($id) if defined $id;
Mojo::IOLoop->remove($watchdog) if defined $watchdog;
$cb->( undef, At::Error->new( message => "WebSocket finished: $code " . ( $reason // '' ), fatal => 0 ) );
$tx = undef;
}
);
}
);
}
method _set_auth_header($token) { $self->auth($token); }
} 1;
__END__
=pod
=encoding utf-8
=head1 NAME
At::UserAgent - Abstract Base Class for AT Protocol User Agents
=head1 DESCRIPTION
C<At::UserAgent> defines the interface for HTTP clients used by L<At>. It handles DPoP proof generation, automatic
nonce management, and authentication headers.
=head1 Subclasses
=over
=item L<At::UserAgent::Mojo>
Uses L<Mojo::UserAgent>. Recommended for asynchronous or high-performance applications.
=item L<At::UserAgent::Tiny>
Uses L<HTTP::Tiny>. A lightweight, zero-dependency alternative. Does not support firehose/WebSockets.
=back
=head1 Attributes
=head2 C<accessJwt()>
The current access token.
=head2 C<token_type()>
The token type (e.g., 'DPoP' or 'Bearer').
=head2 C<dpop_key()>
The L<Crypt::PK::ECC> key used for DPoP signing.
=head1 Methods
=head2 C<set_tokens( $access, $refresh, $type, $key )>
Sets the current authentication tokens and keys.
=head2 C<get( $url, [ \%options ] )>
Performs an HTTP GET request.
=head2 C<post( $url, [ \%options ] )>
Performs an HTTP POST request.
=head1 LICENSE
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License
2. Other copyrights, terms, and conditions may apply to data transmitted through this module.
=head1 AUTHOR
Sanko Robinson E<lt>sanko@cpan.orgE<gt>
=begin stopwords
atproto Bluesky auth authed login
=end stopwords
=cut
( run in 0.542 second using v1.01-cache-2.11-cpan-39bf76dae61 )