# SDK de Perl

`Tomba::Finder` es el cliente oficial de Perl para la [API de Tomba](/introduction), publicado en CPAN en la distribución `Tomba-Finder`. Un único objeto `Tomba::Finder` expone todos los métodos, y cada método envía una solicitud.

## Requisitos

- Perl 5.26.1 o posterior, tal como se declara en `Makefile.PL`.
- `LWP::UserAgent`, `JSON` y `URI`, instalados como dependencias. Las solicitudes HTTPS también necesitan `LWP::Protocol::https`.

## Instalación

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

## Autenticación

Crea una clave API y copia tu secreto en la página [API keys](https://app.tomba.io/api), y luego exporta ambos:

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

El SDK no lee variables de entorno. Pasa los valores a `Tomba::Finder->new($key, $secret)`, y el cliente los envía como los encabezados `X-Tomba-Key` y `X-Tomba-Secret`. El constructor lanza una excepción si alguno de los valores tiene menos de 39 caracteres. La caducidad y la rotación de las claves se explican en [Autenticación](/authentication).

## Primera solicitud

Busca la dirección de email de una persona en una empresa:

```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";
```

Todos los métodos devuelven una referencia a un hash con dos claves: `data`, el cuerpo JSON decodificado, y `rate_limit`. La API envuelve su payload en su propio objeto `data` ([Formato de respuesta](/introduction#response-format)), así que la dirección está en `$result->{data}{data}{email}`.

## Errores

Los métodos no lanzan excepciones ante errores de la API. Devuelven el cuerpo del error decodificado en `data`, así que comprueba `$result->{data}{errors}` después de cada llamada:

```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` es el estado HTTP. Cada `errors.type` se describe en [Errores](/error-handling#error-types). Los métodos `GET` lanzan una excepción cuando el cuerpo de una respuesta no es JSON, por ejemplo una página de tiempo de espera agotado de la pasarela.

## Límites de solicitudes y reintentos

El SDK no reintenta. `$result->{rate_limit}` contiene los [encabezados de límites de solicitudes](/rate-limits#rate-limit-headers) de la respuesta que estén presentes, con el nombre del encabezado como clave: `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` y `ratelimit`.

En un `429`, `$result->{rate_limit}{'retry-after'}` contiene la espera en segundos. Reintenta como se describe en [Gestionar respuestas 429](/rate-limits#handle-429-responses).

Las solicitudes agotan el tiempo de espera a los 120 segundos; el tiempo de espera no se puede configurar.

## Referencia de métodos

Llama a todos los métodos en el objeto `Tomba::Finder`. Cada método también está disponible en su propio módulo, por ejemplo `Tomba::Domain->new($key, $secret)->DomainSearch(...)`. `$opts` es una referencia a un hash opcional.

| Método                                                                                | 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` y `webhook_url` en `$opts`     | [`GET /domain-search`](/api/finder#domain-search)                               |
| `EmailFinder($domain, $first_name, $last_name, $opts)`, con `webhook_url` en `$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` es el segmento `{type}` que se enumera en [Tipos de trabajos masivos](/bulks#bulk-types); el orden de las llamadas se describe en [Ciclo de vida](/bulks#lifecycle). `CreateBulk` envía un cuerpo JSON, así que no puede crear trabajos que requieren subir un CSV, como los trabajos de [Email Finder](/bulks#email-finder).

## Código fuente

[github.com/tomba-io/perl](https://github.com/tomba-io/perl) (Apache-2.0). Las notas de la versión están en [Changes](https://github.com/tomba-io/perl/blob/master/Changes).
