# SDK Perl

`Tomba::Finder` è il client Perl ufficiale per l'[API Tomba](/introduction), pubblicato su CPAN nella distribuzione `Tomba-Finder`. Un unico oggetto `Tomba::Finder` espone tutti i metodi, e ogni metodo invia una richiesta.

## Requisiti

- Perl 5.26.1 o successivo, come dichiarato in `Makefile.PL`.
- `LWP::UserAgent`, `JSON` e `URI`, installati come dipendenze. Le richieste HTTPS richiedono anche `LWP::Protocol::https`.

## Installa

```bash
cpanm Tomba::Finder
```

## Autenticati

Crea una chiave API e copia il tuo secret nella pagina [API keys](https://app.tomba.io/api), poi esportali entrambi:

```bash
export TOMBA_API_KEY="ta_xxxx"
export TOMBA_SECRET_KEY="ts_xxxx"
```

L'SDK non legge le variabili d'ambiente. Passa i valori a `Tomba::Finder->new($key, $secret)`, e il client li invia come header `X-Tomba-Key` e `X-Tomba-Secret`. Il costruttore termina con un errore se uno dei due valori è più corto di 39 caratteri. La scadenza e la rotazione delle chiavi sono trattate in [Autenticazione](/authentication).

## Prima richiesta

Trova l'indirizzo email di una persona in un'azienda:

```perl
use strict;
use warnings;

use Tomba::Finder;

my $tomba = Tomba::Finder->new($ENV{TOMBA_API_KEY}, $ENV{TOMBA_SECRET_KEY});

my $result = $tomba->EmailFinder('stripe.com', 'Jane', 'Doe');
die "$result->{data}{errors}{message}\n" if $result->{data}{errors};
print $result->{data}{data}{email} // '', "\n";
```

Ogni metodo restituisce un riferimento a un hash con due chiavi: `data`, il corpo JSON decodificato, e `rate_limit`. L'API racchiude il payload in un proprio oggetto `data` ([Formato della risposta](/introduction#response-format)), quindi l'indirizzo si trova in `$result->{data}{data}{email}`.

## Errori

I metodi non terminano con un errore per gli errori dell'API: restituiscono il corpo dell'errore decodificato in `data`, quindi controlla `$result->{data}{errors}` dopo ogni chiamata:

```perl
use strict;
use warnings;

use Tomba::Finder;

my $tomba = Tomba::Finder->new($ENV{TOMBA_API_KEY}, $ENV{TOMBA_SECRET_KEY});

my $result = $tomba->EmailFinder('stripe.com', 'Jane', 'Doe');
if (my $error = $result->{data}{errors}) {
    print "$error->{code} $error->{type}: $error->{message}\n";
}
else {
    print $result->{data}{data}{email} // '', "\n";
}
```

`errors.code` è lo stato HTTP. Ogni `errors.type` è descritto in [Errori](/error-handling#error-types). I metodi `GET` terminano con un errore quando il corpo di una risposta non è JSON, ad esempio una pagina di errore Gateway Timeout.

## Limiti di frequenza e nuovi tentativi

L'SDK non riprova le richieste. `$result->{rate_limit}` contiene gli [header dei limiti di frequenza](/rate-limits#rate-limit-headers) presenti nella risposta, indicizzati per nome dell'header: `x-second-rate-limit`, `x-minute-rate-limit`, `x-daily-rate-limit`, `x-minute-request-left`, `x-daily-request-left`, `x-minute-reset-seconds`, `x-daily-reset-seconds`, `retry-after`, `ratelimit-policy` e `ratelimit`.

Con un `429`, `$result->{rate_limit}{'retry-after'}` contiene l'attesa in secondi. Riprova come descritto in [Gestisci le risposte 429](/rate-limits#handle-429-responses).

Le richieste vanno in timeout dopo 120 secondi; il timeout non è configurabile.

## Riferimento dei metodi

Chiama ogni metodo sull'oggetto `Tomba::Finder`. Ogni metodo è disponibile anche nel proprio modulo, ad esempio `Tomba::Domain->new($key, $secret)->DomainSearch(...)`. `$opts` è un riferimento a un hash facoltativo.

| Metodo                                                                                | Endpoint                                                                        |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `Account()`                                                                           | [`GET /me`](/api/account#get-account)                                           |
| `Usage()`                                                                             | [`GET /usage`](/api/account#retrieve-api-usage)                                 |
| `Logs($params)`                                                                       | [`GET /logs`](/api/account#retrieve-api-logs)                                   |
| `DomainSearch($domain, $opts)`, con `enrich_mobile` e `webhook_url` in `$opts`     | [`GET /domain-search`](/api/finder#domain-search)                               |
| `EmailFinder($domain, $first_name, $last_name, $opts)`, con `webhook_url` in `$opts` | [`GET /email-finder`](/api/finder#email-finder)                                 |
| `AuthorFinder($url, $opts)`                                                           | [`GET /author-finder`](/api/finder#author-finder)                               |
| `LinkedinFinder($url, $opts)`                                                         | [`GET /linkedin`](/api/finder#linkedin-finder)                                  |
| `Enrichment($email, $opts)`                                                           | [`GET /enrich`](/api/finder#email-enrichment)                                   |
| `EmailFormat($domain)`                                                                | [`GET /email-format`](/api/finder#email-format)                                 |
| `GetLocation($domain)`                                                                | [`GET /location`](/api/finder#location)                                         |
| `Count($domain)`                                                                      | [`GET /email-count`](/api/finder#email-count)                                   |
| `EmailVerifier($email, $opts)`                                                        | [`GET /email-verifier`](/api/verifier#email-verifier)                           |
| `EmailSources($email)`                                                                | [`GET /email-sources`](/api/email#email-sources)                                |
| `PersonFind($email)`                                                                  | [`GET /people/find`](/api/enrichment#person-api)                                |
| `CompanyFind($domain)`                                                                | [`GET /companies/find`](/api/enrichment#company-api)                            |
| `CombinedFind($email)`                                                                | [`GET /combined/find`](/api/enrichment#combined-api)                            |
| `PhoneFinder($params)`                                                                | [`GET /phone-finder`](/api/phone#phone-finder)                                  |
| `PhoneValidator($phone, $country_code)`                                               | [`GET /phone-validator`](/api/phone#phone-validator)                            |
| `Status($domain)`                                                                     | [`GET /domain-status`](/api/domain#domain-status)                               |
| `Autocomplete($search)`                                                               | [`GET /domain-suggestions`](/api/domain-suggestions#get-domain-suggestions)     |
| `Similar($domain)`                                                                    | [`GET /similar`](/api/domain#similar)                                           |
| `Technology($domain)`                                                                 | [`GET /technology`](/api/domain#technology)                                     |
| `CompaniesSearch($body)`                                                              | [`POST /reveal/search`](/api/reveal#search-companies)                           |
| `ListFlags($params)`                                                                  | [`GET /flag`](/api/flag#list-my-flags)                                          |
| `CreateFlag($body)`                                                                   | [`POST /flag`](/api/flag#flag-incorrect-data)                                   |
| `ListKeys()`                                                                          | [`GET /keys`](/api/keys#retrieve-api-keys)                                      |
| `GetKey($key_id)`                                                                     | [`GET /keys/{id}`](/api/keys#retrieve-a-single-api-key)                         |
| `CreateKey()`                                                                         | [`POST /keys`](/api/keys#create-an-api-key)                                     |
| `ResetKey($key_id)`                                                                   | [`PUT /keys/{id}`](/api/keys#reset-an-api-key)                                  |
| `DeleteKey($key_id)`                                                                  | [`DELETE /keys/{id}`](/api/keys#delete-an-api-key)                              |
| `ListLeads($params)`                                                                  | [`GET /leads`](/api/leads#retrieve-leads)                                       |
| `GetLead($lead_id)`                                                                   | [`GET /leads/{id}`](/api/leads#retrieve-a-single-lead)                          |
| `CreateLead($body)`                                                                   | [`POST /leads`](/api/leads#create-a-lead)                                       |
| `UpdateLead($lead_id, $body)`                                                         | [`PUT /leads/{id}`](/api/leads#update-a-lead)                                   |
| `DeleteLead($lead_id)`                                                                | [`DELETE /leads/{id}`](/api/leads#delete-a-lead)                                |
| `ListLeadsLists()`                                                                    | [`GET /leads_lists`](/api/lead-lists#retrieve-leads-lists)                      |
| `GetLeadsList($list_id)`                                                              | [`GET /leads_lists/{id}`](/api/lead-lists#retrieve-a-single-leads-list)         |
| `CreateLeadsList($body)`                                                              | [`POST /leads_lists`](/api/lead-lists#create-leads-list)                        |
| `UpdateLeadsList($list_id, $body)`                                                    | [`PUT /leads_lists/{id}`](/api/lead-lists#update-leads-list)                    |
| `DeleteLeadsList($list_id)`                                                           | [`DELETE /leads_lists/{id}`](/api/lead-lists#delete-leads-list)                 |
| `ListAttributes()`                                                                    | [`GET /attributes`](/api/lead-attributes#retrieve-lead-attributes)              |
| `GetAttribute($attribute_id)`                                                         | [`GET /attributes/{id}`](/api/lead-attributes#retrieve-a-single-lead-attribute) |
| `CreateAttribute($body)`                                                              | [`POST /attributes`](/api/lead-attributes#create-a-lead-attribute)              |
| `UpdateAttribute($attribute_id, $body)`                                               | [`PUT /attributes/{id}`](/api/lead-attributes#update-a-lead-attribute)          |
| `DeleteAttribute($attribute_id)`                                                      | [`DELETE /attributes/{id}`](/api/lead-attributes#delete-a-lead-attribute)       |
| `ListBulks($type, $params)`                                                           | [`GET /bulk/{type}`](/api/bulks)                                                |
| `CreateBulk($type, $body)`                                                            | [`POST /bulk/{type}`](/api/bulks)                                               |
| `GetBulk($type, $id)`                                                                 | [`GET /bulk/{type}/{id}`](/api/bulks)                                           |
| `LaunchBulk($type, $id)`                                                              | [`PUT /bulk/{type}/{id}`](/api/bulks)                                           |
| `BulkProgress($type, $id)`                                                            | [`GET /bulk/{type}/{id}/progress`](/api/bulks)                                  |
| `BulkDownload($type, $id)`                                                            | [`GET /bulk/{type}/{id}/download`](/api/bulks)                                  |
| `RenameBulk($type, $id, $name)`                                                       | [`PUT /bulk/{type}/{id}/rename`](/api/bulks)                                    |
| `ArchiveBulk($type, $id)`                                                             | [`DELETE /bulk/{type}/{id}/archive`](/api/bulks)                                |
| `DeleteBulk($type, $id)`                                                              | [`DELETE /bulk/{type}/{id}/delete`](/api/bulks)                                 |

`$type` è il segmento `{type}` elencato in [Tipi di job in blocco](/bulks#bulk-types); l'ordine delle chiamate è descritto in [Ciclo di vita](/bulks#lifecycle). `CreateBulk` invia un corpo JSON, quindi non può creare job che richiedono il caricamento di un file CSV, come i job [Email Finder](/bulks#email-finder).

## Codice sorgente

[github.com/tomba-io/perl](https://github.com/tomba-io/perl) (Apache-2.0). Le note di rilascio sono in [Changes](https://github.com/tomba-io/perl/blob/master/Changes).
