Apertur-SDK

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# 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},
);

$client->webhooks->delete($project_id, $webhook->{id});
```

## Encryption

Apertur supports end-to-end encrypted uploads using RSA-OAEP + AES-256-GCM. Requires optional dependencies `Crypt::OpenSSL::RSA` and `CryptX`. See [Encryption documentation](https://docs.apertur.ca/encryption).

```perl
use Apertur::SDK;

my $client = Apertur::SDK->new(api_key => 'aptr_live_...');

my $server_key = $client->encryption->get_server_key();

my $image = $client->upload->image_encrypted(
    'session-uuid-here',
    '/tmp/photo.jpg',
    $server_key->{publicKey},
    filename => 'photo.jpg',
    mimeType => 'image/jpeg',
);

print "Uploaded: $image->{id}\n";
```

## Error Handling

All API errors throw typed exceptions that inherit from `Apertur::SDK::Error`. Catch the specific subclass you care about, or catch the base class as a fallback. See [Error Handling documentation](https://docs.apertur.ca/errors).

```perl
use Apertur::SDK;



( run in 1.512 second using v1.01-cache-2.11-cpan-7fcb06a456a )