Apertur-SDK
view release on metacpan or search on metacpan
open my $fh, '>:raw', "/tmp/$image->{id}.jpg" or die $!;
print $fh $data;
close $fh;
$client->polling->ack($uuid, $image->{id});
}
# Automatic loop with 60-second timeout and 3-second interval
$client->polling->poll_and_process(
$uuid,
sub {
my ($image, $data) = @_;
open my $fh, '>:raw', "/tmp/$image->{id}.jpg" or die $!;
print $fh $data;
close $fh;
print "Saved $image->{id}\n";
},
interval => 3,
timeout => 60,
);
```
## Receiving Webhooks
Apertur signs every webhook payload so you can verify it was not tampered with. Three verification methods are available. See [Webhooks documentation](https://docs.apertur.ca/webhooks).
```perl
use Apertur::SDK::Signature qw(
verify_webhook_signature
verify_event_signature
verify_svix_signature
);
# Image delivery webhook
my $valid = verify_webhook_signature($body, $signature, $secret);
# Event webhook (HMAC method)
my $valid = verify_event_signature($body, $timestamp, $signature, $secret);
# Event webhook (Svix method)
my $valid = verify_svix_signature($body, $svix_id, $timestamp, $signature, $secret);
```
## Destinations
Destinations define where uploaded images are delivered. See [Destinations documentation](https://docs.apertur.ca/destinations).
```perl
use Apertur::SDK;
my $client = Apertur::SDK->new(api_key => 'aptr_live_...');
my $project_id = 'proj_...';
my $list = $client->destinations->list($project_id);
my $dest = $client->destinations->create($project_id,
type => 's3',
label => 'Primary S3 bucket',
config => { bucket => 'my-bucket', region => 'us-east-1' },
);
my $updated = $client->destinations->update($project_id, $dest->{id},
label => 'Primary S3 bucket (updated)',
);
my $test_result = $client->destinations->test($project_id, $dest->{id});
$client->destinations->delete($project_id, $dest->{id});
```
## API Keys
API keys are scoped to a project and optionally restricted to specific destinations. See [API Keys documentation](https://docs.apertur.ca/api-keys).
```perl
use Apertur::SDK;
my $client = Apertur::SDK->new(api_key => 'aptr_live_...');
my $project_id = 'proj_...';
my $keys = $client->keys->list($project_id);
my $key = $client->keys->create($project_id, label => 'Mobile app key');
$client->keys->update($project_id, $key->{id}, label => 'Mobile app key v2');
$client->keys->set_destinations($key->{id}, ['dest_abc', 'dest_def'], 1);
$client->keys->delete($project_id, $key->{id});
```
## Event Webhooks
Event webhooks push real-time notifications to your endpoint. See [Event Webhooks documentation](https://docs.apertur.ca/event-webhooks).
```perl
use Apertur::SDK;
my $client = Apertur::SDK->new(api_key => 'aptr_live_...');
my $project_id = 'proj_...';
my $webhooks = $client->webhooks->list($project_id);
my $webhook = $client->webhooks->create($project_id,
url => 'https://example.com/webhooks/apertur',
events => ['image.uploaded', 'session.completed'],
);
$client->webhooks->update($project_id, $webhook->{id},
events => ['image.uploaded'],
);
$client->webhooks->test($project_id, $webhook->{id});
my $deliveries = $client->webhooks->deliveries($project_id, $webhook->{id},
page => 1,
limit => 25,
);
$client->webhooks->retry_delivery($project_id, $webhook->{id},
$deliveries->{data}[0]{id},
);
( run in 1.015 second using v1.01-cache-2.11-cpan-98e64b0badf )