API-Mathpix
view release on metacpan or search on metacpan
lib/API/Mathpix.pm view on Meta::CPAN
if (-f $opt->{src}) {
my $contents = do {
open my $fh, $opt->{src} or die '...';
local $/;
<$fh>;
};
$opt->{src} = "data:image/jpeg;base64,'".encode_base64($contents)."'";
}
my $url = 'https://api.mathpix.com/v3/text';
my $headers = [
'Content-Type' => 'application/json',
':app_id' => $self->app_id,
':app_key' => $self->app_key,
];
my $encoded_data = encode_json($opt);
my $r = HTTP::Request->new('POST', $url, $headers, $encoded_data);
my $response;
if ($self->_bucket->tick) {
$response = $self->_ua->request($r);
}
else {
warn 'Rate limiting !';
}
if ($response->is_success) {
my $data = decode_json($response->decoded_content);
return API::Mathpix::Response->new($data);
}
else {
warn $response->status_line;
}
}
=head1 AUTHOR
( run in 0.255 second using v1.01-cache-2.11-cpan-496ff517765 )