Bluesky-Poster

 view release on metacpan or  search on metacpan

lib/Bluesky/Poster.pm  view on Meta::CPAN

    my $res = $ua->post(
        'https://bsky.social/xrpc/com.atproto.server.createSession',
        'Content-Type' => 'application/json',
        Content => $self->{json}->encode({
            identifier => $self->{handle},
            password   => $self->{app_password},
        }),
    );

    unless ($res->is_success) {
        croak "Login failed: " . $res->status_line . "\n" . $res->decoded_content;
    }

    $self->{session} = $self->{json}->decode($res->decoded_content);
}

sub post {
    my ($self, $text) = @_;
    croak "Text is required" unless defined $text;

    my $now = time();
    my $iso_timestamp = _iso8601($now);

    my $payload = {

lib/Bluesky/Poster.pm  view on Meta::CPAN

    };

    my $res = $self->{agent}->post(
        'https://bsky.social/xrpc/com.atproto.repo.createRecord',
        'Content-Type'  => 'application/json',
        'Authorization' => 'Bearer ' . $self->{session}{accessJwt},
        Content => $self->{json}->encode($payload),
    );

    unless ($res->is_success) {
        croak "Post failed: " . $res->status_line . "\n" . $res->decoded_content;
    }

    return $self->{json}->decode($res->decoded_content);
}

sub _iso8601 {
    my $t = shift;
    my @gmt = gmtime($t);
    return sprintf(
        "%04d-%02d-%02dT%02d:%02d:%02dZ",
        $gmt[5]+1900, $gmt[4]+1, $gmt[3],
        $gmt[2], $gmt[1], $gmt[0],
    );



( run in 1.449 second using v1.01-cache-2.11-cpan-211d0254c34 )