App-ActivityPubClient

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.perltidyrc
lib/App/ActivityPubClient.pm
Makefile.PL
MANIFEST                        This list of files
MANIFEST.SKIP
script/ap-backup
script/ap-fetch
script/ap-represent
script/webfinger
t/pleroma.t
t/pleroma_user.json
t/pleroma_user.out
META.yml                                 Module YAML meta-data (added by MakeMaker)
META.json                                Module JSON meta-data (added by MakeMaker)

Makefile.PL  view on Meta::CPAN

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
WriteMakefile(
        NAME      => 'App::ActivityPubClient',
        ABSTRACT  => 'CLI-based client / toolbox for ActivityPub Client-to-Server',
        AUTHOR    => 'Haelwenn (lanodan) Monnier <contact+ap-client@hacktivis.me>',
        LICENSE   => 'bsd',
        VERSION   => 'v0.1.4',
        EXE_FILES =>
          [ 'script/ap-fetch', 'script/ap-represent', 'script/ap-backup' ],
        MAN1PODS => {
                'script/ap-fetch' => 'blib/man1/ap-fetch.1',
                'script/ap-represent' => 'blib/man1/ap-represent.1',
                'script/ap-backup' => 'blib/man1/ap-backup.1',
        },
        PREREQ_PM => {
                'Exporter' => 0,
                'Getopt::Std' => 0,
                'HTTP::Request::Common' => 0,
                'JSON' => 0,
                'LWP::UserAgent' => 0,
                'MIME::Base64' => 0,
                'Scalar::Util' => 0,
        },

script/ap-backup  view on Meta::CPAN

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
our $VERSION = 'v0.1.4';
 
$Getopt::Std::STANDARD_HELP_VERSION = 1;
use JSON;
 
=head1 NAME
 
ap-backup - Backup an ActivityPub account
 
=head1 SYNOPSIS
 
B<ap-backup.pl> <-u user:password|-o OAuth-Bearer-Token> <url>
 
=head1 DESCRIPTION
 
ap-backup is used to backup an ActivityPub account, authentication is required.
 
=over 4
 
=item B<-u>
 
HTTP Basic Auth
 
=item B<-o>
 
OAuth2 Bearer Token

script/ap-backup  view on Meta::CPAN

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
                }
 
                #print "Saving ", $item->{"id"}, " to ", $filename, "\n";
 
                open(my $fh, '>', $filename) or die "couldn't open", $filename;
                print $fh encode_json($item);
                close $fh;
        }
}
 
sub apc2s_backup {
        my ($url) = @_;
 
        my $req = HTTP::Request->new(GET => $url);
        $req->header('Accept'        => 'application/activity+json');
        $req->header('Authorization' => $auth);
 
        my $res = $ua->request($req);
 
        if ($res->is_success) {
                print "Got $url\n";

script/ap-backup  view on Meta::CPAN

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
                my $content_match = /application\/([^+]*+)?json(; .*)?/;
                if ($content_type =~ $content_match) {
                        my $response = decode_json($res->content);
 
                        if ($response->{"type"} eq "OrderedCollection") {
                                if (not $response->{"first"}) {
                                        die "“first” property of OrderedCollection undefined";
                                }
 
                                print "Fetching first property: ", $response->{"first"}, "\n";
                                apc2s_backup($response->{"first"});
                        } elsif ($response->{"type"} eq "OrderedCollectionPage") {
                                if ($response->{"orderedItems"}) {
                                        save_collection($response->{"orderedItems"});
                                        print "next: ", $response->{"next"}, "\n"
                                          if $response->{"next"};
                                        print "prev: ", $response->{"prev"}, "\n"
                                          if $response->{"prev"};
 
                                        if ($response->{"next"}) {
                                                print "Fetching next property\n";
                                                apc2s_backup($response->{"next"});
                                        } else {
                                                print "No “next” property defined, done?\n";
                                        }
                                } else {
                                        die
"OrderedCollectionPage without “orderedItems” defined is unsupported";
                                }
                        } elsif ($response->{"type"} eq "Person") {
                                if ($response->{"outbox"}) {
                                        print "Fetching outbox property: ", $response->{"outbox"},
                                          "\n";
                                        apc2s_backup($response->{"outbox"});
                                } else {
                                        die "Person actor with no outbox";
                                }
                        } else {
                                die "Unknown type: ", $response->{"type"};
                        }
                } else {
                        die "Got ", $content_type, " instead of ", $content_match;
                }
        } else {
                die "Got ", $res->status_line, " instead of 2xx";
        }
}
 
getopts("u:o:", \%options);
 
if ($#ARGV != 0) {
        print "usage: ap-backup.pl <-u user:password|-o OAuth-Bearer-Token> <url>\n";
        exit 1;
}
 
if (defined $options{u}) {
        $auth = "Basic " . encode_base64($options{u});
}
if (defined $options{o}) {
        $auth = "Bearer " . $options{o};
}
 
print "Authorization: $auth";
print "Fetching: ", $ARGV[0], "\n";
apc2s_backup($ARGV[0]);



( run in 0.266 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )