Documentation
¶
Overview ¶
Package checkhim provides a Go SDK for phone number verification using the CheckHim API.
This SDK allows you to verify phone numbers by checking if they are valid and active. It provides a simple interface to interact with the CheckHim verification service.
Basic usage:
client := checkhim.New("your-api-key") result, err := client.Verify(checkhim.VerifyRequest{ Number: "+1234567890", }) if err != nil { log.Fatal(err) } fmt.Printf("Valid: %v, Carrier: %s\n", result.Valid, result.Carrier)
Index ¶
Examples ¶
Constants ¶
const ( // DefaultBaseURL is the default base URL for the CheckHim API DefaultBaseURL = "http://api.checkhim.tech" // DefaultTimeout is the default timeout for HTTP requests DefaultTimeout = 30 * time.Second // APIVersion is the current API version APIVersion = "v1" )
const ( ErrorCodeRejectedNetwork = "REJECTED_NETWORK" ErrorCodeRejectedPrefixMissing = "REJECTED_PREFIX_MISSING" ErrorCodeRejectedFormat = "REJECTED_FORMAT" ErrorCodeRejectedSubscriberAbsent = "REJECTED_SUBSCRIBER_ABSENT" ErrorCodeRejectedUnknownSubscriber = "REJECTED_UNKNOWN_SUBSCRIBER" ErrorCodeRejectedUndeliverable = "REJECTED_UNDELIVERABLE" ErrorCodeUndeliverableNotDelivered = "UNDELIVERABLE_NOT_DELIVERED" ErrorCodeTemporaryFailure = "TEMPORARY_FAILURE" )
Códigos de erro (sandbox / produção)
const (
DeliveryStatusDeliveredToHandset = "DELIVERED_TO_HANDSET"
)
Códigos de status de entrega (sucesso)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents an API error
func (*APIError) IsNetworkRelated ¶
IsNetworkRelated indica erros relacionados à rede/assinante
func (*APIError) IsNumberInvalid ¶
IsNumberInvalid indica erros de formato/prefixo/número inválido
func (*APIError) IsTemporary ¶
IsTemporary indica se o erro é temporário e pode ser re-tentado
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a CheckHim API client
func New ¶
New creates a new CheckHim client with the provided API key
Example ¶
Example tests that demonstrate usage
client := New("your-api-key") result, err := client.Verify(VerifyRequest{ Number: "+1234567890", }) if err != nil { panic(err) } println(result.Valid, result.Carrier)
func (*Client) Verify ¶
func (c *Client) Verify(req VerifyRequest) (*VerifyResponse, error)
Verify verifies a phone number using the CheckHim API
Example ¶
client := New("your-api-key") result, err := client.Verify(VerifyRequest{ Number: "+5511984339000", }) if err != nil { panic(err) } println(result.Valid, result.Carrier)
func (*Client) VerifyWithContext ¶
func (c *Client) VerifyWithContext(ctx context.Context, req VerifyRequest) (*VerifyResponse, error)
VerifyWithContext verifies a phone number with a custom context
Example ¶
client := New("your-api-key") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() result, err := client.VerifyWithContext(ctx, VerifyRequest{ Number: "+1234567890", }) if err != nil { panic(err) } println(result.Valid, result.Carrier)
type Config ¶
type Config struct { // BaseURL is the base URL for the CheckHim API (optional) BaseURL string // Timeout is the timeout for HTTP requests (optional) Timeout time.Duration // HTTPClient is a custom HTTP client (optional) HTTPClient *http.Client }
Config holds configuration options for the Client
type ErrorResponse ¶
type ErrorResponse struct { // Error is the error message Error string `json:"error"` // Code is the error code Code string `json:"code,omitempty"` // Details provides additional error details Details map[string]interface{} `json:"details,omitempty"` }
ErrorResponse represents an error response from the API
type VerifyRequest ¶
type VerifyRequest struct { // Number is the phone number to verify (required) // Should include country code (e.g., "+1234567890") Number string `json:"number"` }
VerifyRequest represents a phone number verification request
type VerifyResponse ¶
type VerifyResponse struct { // Carrier is the name of the mobile carrier Carrier string `json:"carrier"` // Valid indicates whether the phone number is valid and active Valid bool `json:"valid"` // Status (opcional) - quando disponível, ex: "DELIVERED_TO_HANDSET" Status string `json:"status,omitempty"` }
VerifyResponse represents the response from a phone number verification