App-SpreadRevolutionaryDate
view release on metacpan or search on metacpan
lib/App/SpreadRevolutionaryDate/BlueskyLite.pm view on Meta::CPAN
}
if ($content =~ /<meta\s+property="og:image"\s+content="([^"]+)"/) {
my $img_url = $1;
unless ($img_url =~ m!://!) {
$url = "$url/" unless $url =~ m!/$!;
$img_url = $url . $img_url;
}
my $img_response = $ua->get($img_url);
return unless $img_response->is_success;
my $blob_req = HTTP::Request->new('POST', 'https://bsky.social/xrpc/com.atproto.repo.uploadBlob');
$blob_req->header('Content-Type' => $img_response->header('Content-Type'));
$blob_req->content($img_response->content);
my $blob_response = $self->{ua}->request($blob_req);
return unless $blob_response->is_success;
my $blob_content = decode_json($blob_response->decoded_content);
($card->{thumb}) = $blob_content->{blob};
}
return $card;
lib/App/SpreadRevolutionaryDate/BlueskyLite.pm view on Meta::CPAN
my %self;
$self{ua} = LWP::UserAgent->new(env_proxy => 1, timeout => 10, agent =>'App::SpreadRevolutionaryDate bot');
$self{ua}->default_header('Accept' => 'application/json');
my %payload = (
identifier => $args{'identifier'},
password => $args{'password'},
);
my $json = encode_json(\%payload);
my $req = HTTP::Request->new('POST', 'https://bsky.social/xrpc/com.atproto.server.createSession');
$req->header('Content-Type' => 'application/json');
$req->content($json);
my $response = $self{ua}->request($req);
if ($response->is_success) {
my $content = decode_json($response->decoded_content);
my $did = $content->{did};
my $access_jwt = $content->{accessJwt};
$self{ua}->default_header('Authorization' => 'Bearer ' . $access_jwt);
$self{did} = $did;
lib/App/SpreadRevolutionaryDate/BlueskyLite.pm view on Meta::CPAN
my $img_alt = $img->{alt} // ucfirst(fileparse($img->{path}, qr/\.[^.]*/));
my $img_bytes;
open my $fh, '<', $img->{path} or die "Cannot read $img->{path}: $!\n";
{
local $/;
$img_bytes = <$fh>;
}
close $fh;
my $blob_req = HTTP::Request->new('POST', 'https://bsky.social/xrpc/com.atproto.repo.uploadBlob');
$blob_req->header('Content-Type' => $mime_type);
$blob_req->content($img_bytes);
my $blob_response = $self->{ua}->request($blob_req);
return unless $blob_response->is_success;
my $blob_content = decode_json($blob_response->decoded_content);
$payload->{record}->{embed} = {
'$type' => 'app.bsky.embed.images',
images => [
{
lib/App/SpreadRevolutionaryDate/BlueskyLite.pm view on Meta::CPAN
},
],
};
}
if ($reply) {
$payload->{record}->{reply} = $reply;
}
my $json = encode_json($payload);
my $req = HTTP::Request->new('POST', 'https://bsky.social/xrpc/com.atproto.repo.createRecord');
$req->header('Content-Type' => 'application/json');
$req->content($json);
my $response = $self->{ua}->request($req);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
return $response;
}
}
lib/App/SpreadRevolutionaryDate/MsgMaker/Gemini.pm view on Meta::CPAN
},
];
}
my $json = JSON->new->utf8;
my $args_json = $json->encode($payload);
my $ua = LWP::UserAgent->new(env_proxy => 1, timeout => 10, agent =>'App::SpreadRevolutionaryDate bot');
$ua->default_header('Accept' => 'application/json');
$ua->default_header('Content-Type' => 'application/json');
my $req = HTTP::Request->new('POST', $url);
$req->content($args_json);
my $resp = $ua->request($req);
my $msg;
if ($resp && $resp->is_success) {
my $content;
eval { $content = $json->decode($resp->content) };
unless ($@) {
if ($content->{candidates} && scalar(@{$content->{candidates}}) == 1 && $content->{candidates}->[0]->{content} && $content->{candidates}->[0]->{content}->{parts} && scalar(@{$content->{candidates}->[0]->{content}->{parts}}) >= 1 && $content->{c...
$msg = $content->{candidates}->[0]->{content}->{parts}->[0]->{text};
( run in 0.420 second using v1.01-cache-2.11-cpan-de7293f3b23 )