websitecontacts

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 9 Imported by: 0

README

website-contacts-go license website-contacts-go made-with-Go website-contacts-go test

Overview

The client library for Website Contacts API in Go language.

The minimum go version is 1.17.

Installation

The library is distributed as a Go module

go get github.com/whois-api-llc/website-contacts-go

Examples

Full API documentation available here

You can find all examples in example directory.

Create a new client

To start making requests you need the API Key. You can find it on your profile page on whoisxmlapi.com. Using the API Key you can create Client.

Most users will be fine with NewBasicClient function.

client := websitecontacts.NewBasicClient(apiKey)

If you want to set custom http.Client to use proxy then you can use NewClient function.

transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

client := websitecontacts.NewClient(apiKey, simplegeoip.ClientParams{
    HTTPClient: &http.Client{
        Transport: transport,
        Timeout:   20 * time.Second,
    },
})

Make basic requests

Website Contacts API lets you get well-structured domain owner contact information, including company name and key contacts with direct-dial phone numbers, email addresses, and social media links.


// Make request to get parsed Website Contacts API response for the domain name
wContactsResp, resp, err := client.Get(ctx, "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

log.Println(wContactsResp.DomainName)
log.Println(wContactsResp.Emails)

// Make request to get raw Website Contacts API data
resp, err := client.WContactsService.GetRaw(context.Background(), "whoisxmlapi.com")
if err != nil {
    log.Fatal(err)
}

log.Println(string(resp.Body))


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgError

type ArgError struct {
	Name    string
	Message string
}

ArgError is the argument error.

func (*ArgError) Error

func (a *ArgError) Error() string

Error returns error message as a string.

type Client

type Client struct {

	// WContactsService is an interface for Website Contacts API
	WContactsService
	// contains filtered or unexported fields
}

Client is the client for Website Contacts API services.

func NewBasicClient

func NewBasicClient(apiKey string) *Client

NewBasicClient creates Client with recommended parameters.

func NewClient

func NewClient(apiKey string, params ClientParams) *Client

NewClient creates Client with specified parameters.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v io.Writer) (response *http.Response, err error)

Do sends the API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, u *url.URL, body io.Reader) (*http.Request, error)

NewRequest creates a basic API request.

type ClientParams

type ClientParams struct {
	// HTTPClient is the client used to access API endpoint
	// If it's nil then value API client uses http.DefaultClient
	HTTPClient *http.Client

	// WContactsBaseURL is the endpoint for 'Website Contacts API' service
	WContactsBaseURL *url.URL
}

ClientParams is used to create Client. None of parameters are mandatory and leaving this struct empty works just fine for most cases.

type Emails

type Emails struct {
	Email       string `json:"email"`
	Description string `json:"description"`
}

Emails is the list of email addresses with description.

type ErrorMessage

type ErrorMessage struct {
	Code    int    `json:"code"`
	Message string `json:"messages"`
}

ErrorMessage is an error message.

func (ErrorMessage) Error

func (e ErrorMessage) Error() string

Error returns error message as a string.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Message  string
}

ErrorResponse is returned when the response status code is not 2xx.

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error returns error message as a string.

type Meta

type Meta struct {
	Title       string `json:"title"`
	Description string `json:"description"`
}

Meta is the metadata defined in the title and description meta tag on the main page.

type Option

type Option func(v url.Values)

Option adds parameters to the query.

func OptionHardRefresh

func OptionHardRefresh(value int) Option

OptionHardRefresh sets the parameter for demanding the website contacts information from scratch.

func OptionOutputFormat

func OptionOutputFormat(outputFormat string) Option

OptionOutputFormat sets Response output format JSON | XML. Default: JSON.

type Phones

type Phones struct {
	PhoneNumber string `json:"phoneNumber"`
	Description string `json:"description"`
	CallHours   string `json:"callHours"`
}

Phones is the list of phone numbers with description and call hours.

type Response

type Response struct {
	*http.Response

	// Body is the byte slice representation of http.Response Body
	Body []byte
}

Response is the http.Response wrapper with Body saved as a byte slice.

type SocialLinks struct {
	Facebook  string `json:"facebook"`
	Instagram string `json:"instagram"`
	LinkedIn  string `json:"linkedIn"`
	Twitter   string `json:"twitter"`
}

SocialLinks is the Facebook/Instagram/LinkedIn/Twitter URLs found on the main website's page.

type WContactsResponse

type WContactsResponse struct {
	// DomainName is a domain name.
	DomainName string `json:"domainName"`

	// WebsiteResponded Determines if the website was active during the crawling.
	WebsiteResponded bool `json:"websiteResponded"`

	// Meta is the metadata defined in the title and description meta tag on the main page.
	Meta Meta `json:"meta"`

	// CountryCode is the Website country (ISO-3166).
	CountryCode string `json:"countryCode"`

	// CompanyNames is the list of possible company names.
	CompanyNames []string `json:"companyNames"`

	// Emails is the list of email addresses with description.
	Emails []Emails `json:"emails"`

	// Phones is the list of phone numbers with description and call hours.
	Phones []Phones `json:"phones"`

	// PostalAddresses is the list of postal addresses. Every address is presented in the format of:
	// street, city, state, zip code, country. Some positions may be missing.
	PostalAddresses []string `json:"postalAddresses"`

	// SocialLinks is the Facebook/Instagram/LinkedIn/Twitter URLs found on the main website's page.
	SocialLinks SocialLinks `json:"socialLinks"`
}

WContactsResponse is a response of Website Contacts API.

type WContactsService

type WContactsService interface {
	// Get returns parsed Website Contacts API response
	Get(ctx context.Context, domainName string, opts ...Option) (*WContactsResponse, *Response, error)

	// GetRaw returns raw Website Contacts API response as Response struct with Body saved as a byte slice
	GetRaw(ctx context.Context, domainName string, opts ...Option) (*Response, error)
}

WContactsService is an interface for Website Contacts API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL