Apertur-SDK
view release on metacpan or search on metacpan
my $client = Apertur::SDK->new(
api_key => 'aptr_live_...',
base_url => 'https://sandbox.api.aptr.ca',
);
```
Keys prefixed with `aptr_test_` automatically target the sandbox environment.
## Sessions
Upload sessions scope every image upload. You can create a session with optional settings, retrieve it, protect it with a password, and check delivery status. See [Sessions documentation](https://docs.apertur.ca/upload-sessions).
```perl
use Apertur::SDK;
my $client = Apertur::SDK->new(api_key => 'aptr_live_...');
# Create a session
my $session = $client->sessions->create(
label => 'Wedding reception',
password => 's3cr3t',
maxImages => 200,
);
# Retrieve session details
my $details = $client->sessions->get($session->{uuid});
# Verify a password-protected session before uploading
my $result = $client->sessions->verify_password($session->{uuid}, 's3cr3t');
# Check per-destination delivery status. Returns:
# { status => 'pending|active|completed|expired',
# files => [...], lastChanged => '<ISO 8601>' }
my $status = $client->sessions->delivery_status($session->{uuid});
# Long-poll: server holds the response up to 5 min until something changes.
# Passing poll_from automatically widens the per-request timeout to 360 s.
$status = $client->sessions->delivery_status(
$session->{uuid},
my $image = $client->upload->image($uuid, '/tmp/photo.jpg',
filename => 'photo.jpg',
mimeType => 'image/jpeg',
source => 'my-app',
);
# Upload from raw bytes
my $bytes = read_file_bytes('/tmp/photo.jpg');
my $image = $client->upload->image($uuid, \$bytes);
# Upload to a password-protected session
my $image = $client->upload->image($uuid, '/tmp/photo.jpg',
password => 's3cr3t',
);
# Encrypted upload
my $server_key = $client->encryption->get_server_key();
my $image = $client->upload->image_encrypted(
$uuid, '/tmp/photo.jpg', $server_key->{publicKey},
filename => 'photo.jpg',
mimeType => 'image/jpeg',
);
```
lib/Apertur/SDK/Resource/Sessions.pm view on Meta::CPAN
my $qs = _build_query_string(%params);
return $self->{http}->request('GET', "/api/v1/sessions/recent$qs");
}
sub qr {
my ($self, $uuid, %options) = @_;
my $qs = _build_query_string(%options);
return $self->{http}->request_raw('GET', "/api/v1/upload-sessions/$uuid/qr$qs");
}
sub verify_password {
my ($self, $uuid, $password) = @_;
return $self->{http}->request(
'POST', "/api/v1/upload/$uuid/verify-password",
body => encode_json({ password => $password }),
);
}
sub delivery_status {
my ($self, $uuid, %opts) = @_;
my $path = "/api/v1/upload-sessions/$uuid/delivery-status";
my %req_opts;
if (defined $opts{poll_from}) {
$path .= '?pollFrom=' . uri_escape($opts{poll_from});
# Long-poll: server holds up to 5 min; give the request 6 min so the
lib/Apertur/SDK/Resource/Sessions.pm view on Meta::CPAN
__END__
=head1 NAME
Apertur::SDK::Resource::Sessions - Upload session management
=head1 DESCRIPTION
Provides methods to create, retrieve, update, and list upload sessions,
as well as password verification, QR code generation, and delivery status
checking.
=head1 METHODS
=over 4
=item B<create(%options)>
Creates a new upload session. Returns the session hashref including C<uuid>.
lib/Apertur/SDK/Resource/Sessions.pm view on Meta::CPAN
=item B<recent(%params)>
Returns recently created sessions with optional C<limit>.
=item B<qr($uuid, %options)>
Returns the QR code image as raw bytes. Options: C<format>, C<size>,
C<style>, C<fg>, C<bg>, C<borderSize>, C<borderColor>.
=item B<verify_password($uuid, $password)>
Verifies a password for a protected session.
=item B<delivery_status($uuid, %opts)>
Returns the delivery status snapshot for a session as a hashref:
{
status => 'pending' | 'active' | 'completed' | 'expired',
files => [ { record_id => ..., filename => ..., size_bytes => ...,
destinations => [ { destination_id => ..., status => ..., ... } ] } ],
lastChanged => '<ISO 8601>',
lib/Apertur/SDK/Resource/Upload.pm view on Meta::CPAN
'Content-Type' => $mime_type,
Content => $data,
],
);
if ($options{source}) {
push @multipart, source => $options{source};
}
my %headers;
if ($options{password}) {
$headers{'x-session-password'} = $options{password};
}
return $self->{http}->request(
'POST', "/api/v1/upload/$uuid/images",
multipart => \@multipart,
headers => \%headers,
);
}
sub image_encrypted {
lib/Apertur/SDK/Resource/Upload.pm view on Meta::CPAN
],
);
if ($options{source}) {
push @multipart, source => $options{source};
}
my %headers = (
'X-Aptr-Encrypted' => 'default',
);
if ($options{password}) {
$headers{'x-session-password'} = $options{password};
}
return $self->{http}->request(
'POST', "/api/v1/upload/$uuid/images",
multipart => \@multipart,
headers => \%headers,
);
}
1;
lib/Apertur/SDK/Resource/Upload.pm view on Meta::CPAN
and end-to-end encrypted.
=head1 METHODS
=over 4
=item B<image($uuid, $file, %options)>
Uploads an image via multipart POST. C<$file> can be a file path string
or a scalar reference containing raw bytes. Options: C<filename>,
C<mimeType> (or C<mime_type>), C<source>, C<password>.
=item B<image_encrypted($uuid, $file, $public_key, %options)>
Encrypts an image with AES-256-GCM (key wrapped with RSA-OAEP) and
uploads it as a JSON payload. Requires C<Crypt::OpenSSL::RSA> and
C<CryptX>. Options: same as C<image>.
=back
=cut
( run in 2.154 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )