App-bsky

 view release on metacpan or  search on metacpan

Changes.md  view on Meta::CPAN

- Improved `show-session` command with detailed diagnostic output.

## [0.04] - 2024-02-13

### Changed
- Update to fit current API of At.pm

## [0.03] - 2024-01-27

### Added
- Commands for app passwords, likes, reposts, invite codes, threads, etc.

## [0.02] - 2024-01-26

### Fixed
- Less broken session management

## [0.01] - 2024-01-26

### Added
- original version

README.md  view on Meta::CPAN

```

## stream

```
bsky stream
```

Stream posts from the firehose. Note that this requires [Mojo::UserAgent](https://metacpan.org/pod/Mojo%3A%3AUserAgent) to be installed.

## thread

```
thread at://did:plc:pwqewimhd3rxc4hg6ztwrcyj/app.bsky.feed.post/3kjyoh75qne2w
```

Show a thread.

### Options

```
--json      boolean flag; content is printed as JSON objects if given
-n   value  number of items
```

## post

lib/App/bsky.pm  view on Meta::CPAN

                $self->say( 'Handle: ' . $session->handle );
                $self->say( 'Email:  ' . ( $session->email // 'N/A' ) );
                $self->say( 'Type:   ' . $session->token_type );
                $self->say( 'Scopes: ' . ( $session->scope // 'N/A' ) );
            }
            return 1;
        }

        method _dump_post ( $depth, $post ) {
            if ( builtin::blessed $post ) {
                if ( $post->isa('At::Lexicon::app::bsky::feed::threadViewPost') && builtin::blessed $post->parent ) {
                    $self->_dump_post( $depth++, $post->parent );
                    $post = $post->post;
                }
                elsif ( $post->isa('At::Lexicon::app::bsky::feed::threadViewPost') ) {
                    $self->_dump_post( $depth++, $post->post );
                    my $replies = $post->replies // [];
                    $self->_dump_post( $depth + 2, $_->post ) for @$replies;
                    return;
                }
            }

            #~ warn ref $post;
            #~ use Data::Dump;
            #~ ddx $post;

lib/App/bsky.pm  view on Meta::CPAN

                            warn "Error processing firehose event: $e";
                        }
                    }
                );
                $fh->start();
            };
            $start_stream->();
            Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
        }

        method cmd_thread (@args) {
            GetOptionsFromArray( \@args, 'json!' => \my $json, 'n=i' => \my $number );
            $number //= ();
            my ($id) = @args;
            $id // return $self->cmd_help('thread');
            my $res = $bsky->getPostThread( uri => $id, depth => $number, parentHeight => $number );    # $uri, depth, $parentHeight
            return unless $res->{thread};
            return $self->say( JSON::Tiny::to_json $res->{thread} ) if $json;
            $self->_dump_post( 0, $res->{thread} );
        }

        method cmd_post ($text) {
            my $res = $bsky->createPost( text => $text );
            defined $res ? $self->say( $res->{uri} ) : 0;
        }

        method cmd_delete ($uri) {
            $uri = At::Protocol::URI->new($uri) unless builtin::blessed $uri;
            $bsky->at->delete_record( $uri->collection, $uri->rkey );

script/bsky  view on Meta::CPAN

=head3 Options

    --json      boolean flag; content is printed as JSON objects if given

=head2 stream

    bsky stream

Stream posts from the firehose. Note that this requires L<Mojo::UserAgent> to be installed.

=head2 thread

    thread at://did:plc:pwqewimhd3rxc4hg6ztwrcyj/app.bsky.feed.post/3kjyoh75qne2w

Show a thread.

=head3 Options

    --json      boolean flag; content is printed as JSON objects if given
    -n   value  number of items

=head2 post

    post "This is a test"

t/00_compile.t  view on Meta::CPAN

use App::bsky;
#
my $temp = Path::Tiny->tempfile('.bsky.XXXXX');
isa_ok my $cli = App::bsky::CLI->new( config_file => $temp ), ['App::bsky::CLI'];
subtest 'commands' => sub {
    can_ok $cli, $_ for sort qw[
        cmd_showprofile cmd_updateprofile
        cmd_showsession
        cmd_timeline    cmd_tl
        cmd_stream
        cmd_thread
        cmd_post    cmd_delete
        cmd_like    cmd_unlike      cmd_likes
        cmd_repost  cmd_reposts
        cmd_follow  cmd_unfollow    cmd_follows cmd_followers
        cmd_block   cmd_unblock     cmd_blocks
        cmd_login   cmd_oauth
        cmd_notifications       cmd_notif
        cmd_listapppasswords    cmd_addapppassword  cmd_revokeapppassword
        cmd_config
        cmd_help

t/01_client.t  view on Meta::CPAN

            sleep 1;
            ok client->run( 'like', $uri ), 'like at://...';
            sleep 1;
            like my $repost = is_say { client->run( 'repost', $uri ) }, qr[at://did:plc:pwqewimhd3rxc4hg6ztwrcyj/app.bsky.feed.repost],
                'repost at://';
            sleep 1;
            like is_say { client->run( 'reposts', $uri, '--json' ) }, qr[atperl.bsky.social], 'reposts at://... --json';
            ok client->run( 'delete', $repost ), 'delete at://... [delete repost]';
            ok client->run( 'delete', $uri ),    'delete at://... [delete post]';
        };
        like is_say { client->run(qw[thread at://did:plc:qdvyf5jhuxqx667ay7k7nagl/app.bsky.feed.post/3kju327qezs2n]) },
            qr[did:plc:qvzn322kmcvd7xtnips5xaun], 'thread at://...';
        like is_say { client->run(qw[thread at://did:plc:qdvyf5jhuxqx667ay7k7nagl/app.bsky.feed.post/3kju327qezs2n --json]) }, qr[^{],
            'thread --json at://...';
        like is_say { client->run(qw[list-app-passwords]) },        qr[Test Suite - bsky],                'list-app-passwords';
        like is_say { client->run(qw[list-app-passwords --json]) }, qr[^\[\{],                            'list-app-passwords --json';
        like is_say { client->run(qw[notifications]) },             qr[did:plc:],                         'notifications';
        like is_say { client->run(qw[notifications --json]) },      qr[^\[\{],                            'notifications --json';
        like is_say { client->run(qw[show-session]) },              qr[did:plc:pwqewimhd3rxc4hg6ztwrcyj], 'show-session';
        like is_say { client->run(qw[show-session --json]) },       qr[^{],                               'show-session --json';
    }
};
done_testing;
__END__



( run in 1.302 second using v1.01-cache-2.11-cpan-39bf76dae61 )