SDK C#
Il pacchetto NuGet Tomba è il client .NET ufficiale per l'API Tomba. Ogni area dell'API è una classe di servizio, e ogni metodo invia una richiesta e restituisce l'HttpResponseMessage grezzo.
Requisiti
- .NET 10. La versione 1.0.1 del pacchetto ha come target solo
net10.0. Newtonsoft.Json, installato come dipendenza.
Installa
Code
Le classi si trovano nel namespace Tomba.
Autenticati
Crea una chiave API e copia il tuo secret nella pagina API keys, poi esportali entrambi:
Code
L'SDK non legge le variabili d'ambiente. Passa i valori a SetKey() e SetSecret(), e il client li invia come header X-Tomba-Key e X-Tomba-Secret. Chiama ogni setter una sola volta per client: una seconda chiamata lancia ArgumentException. La scadenza e la rotazione delle chiavi sono trattate in Autenticazione.
Prima richiesta
Verifica un indirizzo email.
Code
L'esempio è un programma dotnet new console con istruzioni di primo livello. I metodi restituiscono l'HttpResponseMessage senza analizzarlo, quindi leggi e analizza tu il corpo JSON. L'API racchiude il payload in un oggetto data (Formato della risposta); lo stato della verifica è in data.email.status.
Errori
L'SDK lancia TombaException quando l'API risponde con uno stato 400 o superiore e quando la richiesta non riesce. Per gli errori dell'API, l'eccezione è incapsulata: la TombaException esterna ha come Message l'errors.message dell'API, e la sua InnerException è una TombaException il cui Code è lo stato HTTP e la cui Response è il corpo grezzo della risposta.
Code
inner è null quando la richiesta non è riuscita prima che arrivasse una risposta. La Response grezza è il corpo JSON dell'errore; ogni errors.type che contiene è descritto in Errori.
Limiti di frequenza e nuovi tentativi
L'SDK non riprova le richieste. Client.ParseRateLimit(response) legge gli header dei limiti di frequenza di una risposta riuscita in un RateLimit con le proprietà int? SecondRateLimit, MinuteRateLimit, DailyRateLimit, MinuteRequestLeft, DailyRequestLeft, MinuteResetSeconds, DailyResetSeconds e RetryAfter, e le proprietà string RateLimitPolicy e RateLimitValue.
Un 429 lancia TombaException senza gli header della risposta. Attendi prima di riprovare, come descritto in Gestisci le risposte 429.
Le richieste vanno in timeout dopo 120 secondi.
Riferimento dei metodi
Crea ogni servizio con il client, ad esempio new Verifier(client). Ogni metodo restituisce Task<HttpResponseMessage>.
| Metodo | Endpoint |
|---|---|
Account.GetAccount() | GET /me |
Usage.GetUsage() | GET /usage |
Logs.GetLogs(int? page = null, int? limit = null) | GET /logs |
Format.EmailFormatAsync(string domain) | GET /email-format |
Count.EmailCount(string domain) | GET /email-count |
Verifier.EmailVerifier(string email, string webhookUrl = null) | GET /email-verifier |
Sources.EmailSources(string email) | GET /email-sources |
Phone.FinderAsync(Dictionary<string, object> parameters, string webhookUrl = null) | GET /phone-finder |
Phone.ValidatorAsync(string phone, string countryCode = null) | GET /phone-validator |
Status.DomainStatus(string domain) | GET /domain-status |
Status.AutoComplete(string query) | GET /domain-suggestions |
Keys.GetKeys() | GET /keys |
Keys.GetKey(string id) | GET /keys/{id} |
Keys.CreateKey() | POST /keys |
Keys.ResetKey(string id) | PUT /keys/{id} |
Keys.DeleteKey(string id) | DELETE /keys/{id} |
Leads.ListLeadsAsync(int? page = 1, int? limit = 10, string domain = null) | GET /leads |
Leads.GetLeadAsync(string id) | GET /leads/{id} |
Leads.CreateLeadAsync(Dictionary<string, object> data) | POST /leads |
Leads.UpdateLeadAsync(string id, Dictionary<string, object> data) | PUT /leads/{id} |
Leads.DeleteLeadAsync(string id) | DELETE /leads/{id} |
LeadsLists.GetLists() | GET /leads_lists |
LeadsLists.DeleteListId(string id) | DELETE /leads_lists/{id} |
Bulk.ListAsync(string type, Dictionary<string, object> parameters = null) | GET /bulk/{type} |
Bulk.CreateAsync(string type, Dictionary<string, object> data) | POST /bulk/{type} |
Bulk.GetAsync(string type, string id) | GET /bulk/{type}/{id} |
Bulk.ProgressAsync(string type, string id) | GET /bulk/{type}/{id}/progress |
Bulk.DownloadAsync(string type, string id) | GET /bulk/{type}/{id}/download |
Bulk.RenameAsync(string type, string id, string name) | PUT /bulk/{type}/{id}/rename |
type è il segmento {type} elencato in Tipi di job in blocco. CreateAsync invia un corpo JSON, quindi non può creare job che richiedono il caricamento di un file CSV, come i job Email Finder.
Codice sorgente
github.com/tomba-io/csharp (Apache-2.0). Le note di rilascio sono in CHANGELOG.md.