namecheap

package module
v0.0.0-...-6050015 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 9 Imported by: 0

README

go-namecheap

A Go library for using the Namecheap API.

Build Status: Build Status

Examples

package main
import (
  "fmt"
  namecheap "github.com/billputer/go-namecheap"
)

func main() {
  apiUser := "billwiens"
  apiToken := "xxxxxxx"
  userName := "billwiens"

  client := namecheap.NewClient(apiUser, apiToken, userName)

  // Get a list of your domains
  domains, _ := client.DomainsGetList()
  for _, domain := range domains {
    fmt.Printf("Domain: %+v\n\n", domain.Name)
  }

}

For more complete documentation, load up godoc and find the package.

Development

Pull requests welcome!

Attribution

Most concepts and code borrowed from the excellent go-dnsimple.

Documentation

Overview

Package namecheap implements a client for the Namecheap API.

In order to use this package you will need a Namecheap account and your API Token.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressGetInfoResult

type AddressGetInfoResult struct {
	ID       int    `xml:"AddressId"`
	UserName string `xml:"UserName"`
	Name     string `xml:"AddressName"`
	Default  bool   `xml:"Default_YN"`

	FirstName string `xml:"FirstName"`
	LastName  string `xml:"LastName"`

	JobTitle     string `xml:"JobTitle"`
	Organization string `xml:"Organization"`

	Address1 string `xml:"Address1"`
	Address2 string `xml:"Address2"`
	City     string `xml:"City"`

	StateProvince       string `xml:"StateProvince"`
	StateProvinceChoice string `xml:"StateProvinceChoice"`
	PostalCode          string `xml:"Zip"`
	Country             string `xml:"Country"`

	Phone    string `xml:"Phone"`
	Fax      string `xml:"Fax"`
	PhoneExt string `xml:"PhoneExt"`

	EmailAddress string `xml:"EmailAddress"`
}

type AddressGetListResult

type AddressGetListResult struct {
	ID   int    `xml:"AddressId,attr"`
	Name string `xml:"AddressName,attr"`
}

type ApiError

type ApiError struct {
	Number  int    `xml:"Number,attr"`
	Message string `xml:",innerxml"`
}

ApiError is the format of the error returned in the api responses.

func (*ApiError) Error

func (err *ApiError) Error() string

type ApiErrors

type ApiErrors []ApiError

ApiErrors holds multiple ApiError's but implements the error interface

func (ApiErrors) Error

func (errs ApiErrors) Error() string

type ApiRequest

type ApiRequest struct {
	// contains filtered or unexported fields
}

type ApiResponse

type ApiResponse struct {
	Status             string                    `xml:"Status,attr"`
	Command            string                    `xml:"RequestedCommand"`
	TLDList            []TLDListResult           `xml:"CommandResponse>Tlds>Tld"`
	AddressGetList     []AddressGetListResult    `xml:"CommandResponse>AddressGetListResult>List"`
	AddressGetInfo     *AddressGetInfoResult     `xml:"CommandResponse>GetAddressInfoResult"`
	Domains            []DomainGetListResult     `xml:"CommandResponse>DomainGetListResult>Domain"`
	DomainInfo         *DomainInfo               `xml:"CommandResponse>DomainGetInfoResult"`
	DomainDNSHosts     *DomainDNSGetHostsResult  `xml:"CommandResponse>DomainDNSGetHostsResult"`
	DomainDNSSetHosts  *DomainDNSSetHostsResult  `xml:"CommandResponse>DomainDNSSetHostsResult"`
	DomainCreate       *DomainCreateResult       `xml:"CommandResponse>DomainCreateResult"`
	DomainRenew        *DomainRenewResult        `xml:"CommandResponse>DomainRenewResult"`
	DomainsCheck       []DomainCheckResult       `xml:"CommandResponse>DomainCheckResult"`
	DomainNSInfo       *DomainNSInfoResult       `xml:"CommandResponse>DomainNSInfoResult"`
	DomainDNSSetCustom *DomainDNSSetCustomResult `xml:"CommandResponse>DomainDNSSetCustomResult"`
	DomainContacts     *DomainGetContactsResult  `xml:"CommandResponse>DomainContactsResult"`
	UsersGetPricing    []UsersGetPricingResult   `xml:"CommandResponse>UserGetPricingResult>ProductType"`
	UsersGetBalances   []UsersGetBalancesResult  `xml:"CommandResponse>UserGetBalancesResult"`
	WhoisguardList     []WhoisguardGetListResult `xml:"CommandResponse>WhoisguardGetListResult>Whoisguard"`
	WhoisguardEnable   whoisguardEnableResult    `xml:"CommandResponse>WhoisguardEnableResult"`
	WhoisguardDisable  whoisguardDisableResult   `xml:"CommandResponse>WhoisguardDisableResult"`
	WhoisguardRenew    *WhoisguardRenewResult    `xml:"CommandResponse>WhoisguardRenewResult"`
	Paging             *Paging                   `xml:"CommandResponse>Paging"`
	Errors             ApiErrors                 `xml:"Errors>Error"`
}

type Client

type Client struct {
	ApiUser    string
	ApiToken   string
	UserName   string
	HttpClient *http.Client

	// Base URL for API requests.
	// Defaults to the public Namecheap API,
	// but can be set to a different endpoint (e.g. the sandbox).
	// BaseURL should always be specified with a trailing slash.
	BaseURL string

	*Registrant
}

Client represents a client used to make calls to the Namecheap API.

func NewClient

func NewClient(apiUser, apiToken, userName string) *Client

func (*Client) AddressGetInfo

func (client *Client) AddressGetInfo(addressID int) (*AddressGetInfoResult, error)

func (*Client) AddressGetList

func (client *Client) AddressGetList() ([]AddressGetListResult, error)

func (*Client) DomainCreate

func (client *Client) DomainCreate(domainName string, years int, options ...DomainCreateOption) (*DomainCreateResult, error)

func (*Client) DomainDNSSetCustom

func (client *Client) DomainDNSSetCustom(sld, tld, nameservers string) (*DomainDNSSetCustomResult, error)

func (*Client) DomainDNSSetHosts

func (client *Client) DomainDNSSetHosts(
	sld, tld string, hosts []DomainDNSHost,
) (*DomainDNSSetHostsResult, error)

func (*Client) DomainGetContacts

func (client *Client) DomainGetContacts(domainName string) (*DomainGetContactsResult, error)

func (*Client) DomainGetInfo

func (client *Client) DomainGetInfo(domainName string) (*DomainInfo, error)

func (*Client) DomainRenew

func (client *Client) DomainRenew(domainName string, years int) (*DomainRenewResult, error)

func (*Client) DomainsCheck

func (client *Client) DomainsCheck(domainNames ...string) ([]DomainCheckResult, error)

func (*Client) DomainsDNSGetHosts

func (client *Client) DomainsDNSGetHosts(sld, tld string) (*DomainDNSGetHostsResult, error)

func (*Client) DomainsGetList

func (client *Client) DomainsGetList(page int, pageSize int) ([]DomainGetListResult, *Paging, error)

func (*Client) DomainsTLDList

func (client *Client) DomainsTLDList() ([]TLDListResult, error)

func (*Client) NSGetInfo

func (client *Client) NSGetInfo(sld, tld, nameserver string) (*DomainNSInfoResult, error)

func (*Client) NewRegistrant

func (client *Client) NewRegistrant(
	firstName, lastName,
	addr1, addr2,
	city, state, postalCode, country,
	phone, email string,
)

NewRegistrant associates a new registrant with the

func (*Client) UsersGetBalances

func (client *Client) UsersGetBalances() ([]UsersGetBalancesResult, error)

func (*Client) UsersGetPricing

func (client *Client) UsersGetPricing(productType string) ([]UsersGetPricingResult, error)

func (*Client) WhoisguardDisable

func (client *Client) WhoisguardDisable(id int64) error

func (*Client) WhoisguardEnable

func (client *Client) WhoisguardEnable(id int64, email string) error

func (*Client) WhoisguardGetList

func (client *Client) WhoisguardGetList() ([]WhoisguardGetListResult, error)

func (*Client) WhoisguardRenew

func (client *Client) WhoisguardRenew(id int64, years int) (*WhoisguardRenewResult, error)

type DNSDetails

type DNSDetails struct {
	ProviderType  string   `xml:"ProviderType,attr"`
	IsUsingOurDNS bool     `xml:"IsUsingOurDNS,attr"`
	Nameservers   []string `xml:"Nameserver"`
}

type DomainCheckResult

type DomainCheckResult struct {
	Domain                   string  `xml:"Domain,attr"`
	Available                bool    `xml:"Available,attr"`
	IsPremiumName            bool    `xml:"IsPremiumName,attr"`
	PremiumRegistrationPrice float64 `xml:"PremiumRegistrationPrice,attr"`
	PremiumRenewalPrice      float64 `xml:"PremiumRenewalPrice,attr"`
	PremiumRestorePrice      float64 `xml:"PremiumRestorePrice,attr"`
	PremiumTransferPrice     float64 `xml:"PremiumTransferPrice,attr"`
	IcannFee                 float64 `xml:"IcannFee,attr"`
}

type DomainCreateOption

type DomainCreateOption struct {
	AddFreeWhoisguard      bool
	WGEnabled              bool
	Nameservers            []string
	RegistrantNexus        string
	RegistrantNexusCountry string
	RegistrantPurpose      string
	EUAgreeWhoisPolicy     string
	EUAgreeDeletePolicy    string
	EUAdrLang              string
	NUOrgNo                string
	NUvatNo                string
	CIRALegalType          string
	CIRAWhoisDisplay       string
	CIRAAgreementVersion   string
	CIRAAgreementValue     string
	CIRALanguage           string
	COUKLegalType          string
	COUKCompanyID          string
	COUKRegisteredfor      string
	MEUKLegalType          string
	MEUKCompanyID          string
	MEUKRegisteredfor      string
	ORGUKLegalType         string
	ORGUKCompanyID         string
	ORGUKRegisteredfor     string
}

type DomainCreateResult

type DomainCreateResult struct {
	Domain            string  `xml:"Domain,attr"`
	Registered        bool    `xml:"Registered,attr"`
	ChargedAmount     float64 `xml:"ChargedAmount,attr"`
	DomainID          int     `xml:"DomainID,attr"`
	OrderID           int     `xml:"OrderID,attr"`
	TransactionID     int     `xml:"TransactionID,attr"`
	WhoisguardEnable  bool    `xml:"WhoisguardEnable,attr"`
	NonRealTimeDomain bool    `xml:"NonRealTimeDomain,attr"`
}

type DomainDNSGetHostsResult

type DomainDNSGetHostsResult struct {
	Domain        string          `xml:"Domain,attr"`
	IsUsingOurDNS bool            `xml:"IsUsingOurDNS,attr"`
	Hosts         []DomainDNSHost `xml:"host"`
}

type DomainDNSHost

type DomainDNSHost struct {
	ID      int    `xml:"HostId,attr"`
	Name    string `xml:"Name,attr"`
	Type    string `xml:"Type,attr"`
	Address string `xml:"Address,attr"`
	MXPref  int    `xml:"MXPref,attr"`
	TTL     int    `xml:"TTL,attr"`
}

type DomainDNSSetCustomResult

type DomainDNSSetCustomResult struct {
	Domain string `xml:"Domain,attr"`
	Update bool   `xml:"Update,attr"`
}

type DomainDNSSetHostsResult

type DomainDNSSetHostsResult struct {
	Domain    string `xml:"Domain,attr"`
	IsSuccess bool   `xml:"IsSuccess,attr"`
}

type DomainGetContactsResult

type DomainGetContactsResult struct {
	DomainID int    `xml:"domainnameid,attr"`
	Name     string `xml:"Domain,attr"`

	Registrant
}

type DomainGetListResult

type DomainGetListResult struct {
	ID         int    `xml:"ID,attr"`
	Name       string `xml:"Name,attr"`
	User       string `xml:"User,attr"`
	Created    string `xml:"Created,attr"`
	Expires    string `xml:"Expires,attr"`
	IsExpired  bool   `xml:"IsExpired,attr"`
	IsLocked   bool   `xml:"IsLocked,attr"`
	IsPremium  bool   `xml:"IsPremium,attr"`
	IsOurDNS   bool   `xml:"IsOurDNS,attr"`
	AutoRenew  bool   `xml:"AutoRenew,attr"`
	WhoisGuard string `xml:"WhoisGuard,attr"`
}

DomainGetListResult represents the data returned by 'domains.getList'

type DomainInfo

type DomainInfo struct {
	ID         int        `xml:"ID,attr"`
	Name       string     `xml:"DomainName,attr"`
	Owner      string     `xml:"OwnerName,attr"`
	IsOwner    bool       `xml:"IsOwner,attr"`
	IsPremium  bool       `xml:"IsPremium,attr"`
	Created    string     `xml:"DomainDetails>CreatedDate"`
	Expires    string     `xml:"DomainDetails>ExpiredDate"`
	IsExpired  bool       `xml:"IsExpired,attr"`
	IsLocked   bool       `xml:"IsLocked,attr"`
	AutoRenew  bool       `xml:"AutoRenew,attr"`
	DNSDetails DNSDetails `xml:"DnsDetails"`
	Whoisguard Whoisguard `xml:"Whoisguard"`
}

DomainInfo represents the data returned by 'domains.getInfo'

type DomainNSInfoResult

type DomainNSInfoResult struct {
	Domain     string   `xml:"Domain,attr"`
	Nameserver string   `xml:"Nameserver,attr"`
	IP         string   `xml:"IP,attr"`
	Statuses   []string `xml:"NameserverStatuses>Status"`
}

type DomainRenewResult

type DomainRenewResult struct {
	DomainID      int     `xml:"DomainID,attr"`
	Name          string  `xml:"DomainName,attr"`
	Renewed       bool    `xml:"Renew,attr"`
	ChargedAmount float64 `xml:"ChargedAmount,attr"`
	OrderID       int     `xml:"OrderID,attr"`
	TransactionID int     `xml:"TransactionID,attr"`
	ExpireDate    string  `xml:"DomainDetails>ExpiredDate"`
}

type Paging

type Paging struct {
	TotalItems  int `xml:"TotalItems"`
	CurrentPage int `xml:"CurrentPage"`
	PageSize    int `xml:"PageSize"`
}

type Registrant

type Registrant struct {
	RegistrantFirstName string `xml:"Registrant>FirstName"`
	RegistrantLastName  string `xml:"Registrant>LastName"`

	RegistrantAddress1 string `xml:"Registrant>Address1"`
	RegistrantAddress2 string `xml:"Registrant>Address2"`
	RegistrantCity     string `xml:"Registrant>City"`

	RegistrantStateProvince string `xml:"Registrant>StateProvince"`
	RegistrantPostalCode    string `xml:"Registrant>PostalCode"`
	RegistrantCountry       string `xml:"Registrant>Country"`

	RegistrantPhone        string `xml:"Registrant>Phone"`
	RegistrantEmailAddress string `xml:"Registrant>EmailAddress"`

	TechFirstName string `xml:"Tech>FirstName"`
	TechLastName  string `xml:"Tech>LastName"`

	TechAddress1 string `xml:"Tech>Address1"`
	TechAddress2 string `xml:"Tech>Address2"`
	TechCity     string `xml:"Tech>City"`

	TechStateProvince string `xml:"Tech>StateProvince"`
	TechPostalCode    string `xml:"Tech>PostalCode"`
	TechCountry       string `xml:"Tech>Country"`

	TechPhone        string `xml:"Tech>Phone"`
	TechEmailAddress string `xml:"Tech>EmailAddress"`

	AdminFirstName string `xml:"Admin>FirstName"`
	AdminLastName  string `xml:"Admin>LastName"`

	AdminAddress1 string `xml:"Admin>Address1"`
	AdminAddress2 string `xml:"Admin>Address2"`
	AdminCity     string `xml:"Admin>City"`

	AdminStateProvince string `xml:"Admin>StateProvince"`
	AdminPostalCode    string `xml:"Admin>PostalCode"`
	AdminCountry       string `xml:"Admin>Country"`

	AdminPhone        string `xml:"Admin>Phone"`
	AdminEmailAddress string `xml:"Admin>EmailAddress"`

	AuxBillingFirstName string `xml:"AuxBilling>FirstName"`
	AuxBillingLastName  string `xml:"AuxBilling>LastName"`

	AuxBillingAddress1 string `xml:"AuxBilling>Address1"`
	AuxBillingAddress2 string `xml:"AuxBilling>Address2"`
	AuxBillingCity     string `xml:"AuxBilling>City"`

	AuxBillingStateProvince string `xml:"AuxBilling>StateProvince"`
	AuxBillingPostalCode    string `xml:"AuxBilling>PostalCode"`
	AuxBillingCountry       string `xml:"AuxBilling>Country"`

	AuxBillingPhone        string `xml:"AuxBilling>Phone"`
	AuxBillingEmailAddress string `xml:"AuxBilling>EmailAddress"`
}

Registrant is a struct that contains all the data necesary to register a domain. That is to say, every field in this struct is REQUIRED by the namecheap api to crate a new domain. In order for `addValues` method to work, all fields must remain strings.

type TLDListResult

type TLDListResult struct {
	Name string `xml:"Name,attr"`
}

type UsersGetBalancesResult

type UsersGetBalancesResult struct {
	Currency                  string  `xml:"Currency,attr"`
	AvailableBalance          float64 `xml:"AvailableBalance,attr"`
	AccountBalance            float64 `xml:"AccountBalance,attr"`
	EarnedAmount              float64 `xml:"EarnedAmount,attr"`
	WithdrawableAmount        float64 `xml:"WithdrawableAmount,attr"`
	FundsRequiredForAutoRenew float64 `xml:"FundsRequiredForAutoRenew,attr"`
}

type UsersGetPricingResult

type UsersGetPricingResult struct {
	ProductType     string `xml:"Name,attr"`
	ProductCategory []struct {
		Name    string `xml:"Name,attr"`
		Product []struct {
			Name  string `xml:"Name,attr"`
			Price []struct {
				Duration     int     `xml:"Duration,attr"`
				DurationType string  `xml:"DurationType,attr"`
				Price        float64 `xml:"Price,attr"`
				RegularPrice float64 `xml:"RegularPrice,attr"`
				YourPrice    float64 `xml:"YourPrice,attr"`
				CouponPrice  float64 `xml:"CouponPrice,attr"`
				Currency     string  `xml:"Currency,attr"`
			} `xml:"Price"`
		} `xml:"Product"`
	} `xml:"ProductCategory"`
}

type Whoisguard

type Whoisguard struct {
	Enabled     string `xml:"Enabled,attr"`
	ID          int64  `xml:"ID"`
	ExpiredDate string `xml:"ExpiredDate"`
}

type WhoisguardGetListResult

type WhoisguardGetListResult struct {
	ID         int64  `xml:"ID,attr"`
	DomainName string `xml:"DomainName,attr"`
	Created    string `xml:"Created,attr"`
	Expires    string `xml:"Expires,attr"`
	Status     string `xml:"Status,attr"`
}

type WhoisguardRenewResult

type WhoisguardRenewResult struct {
	WhoisguardID  int64   `xml:"WhoisguardId,attr"`
	Renewed       bool    `xml:"Renew,attr"`
	ChargedAmount float64 `xml:"ChargedAmount,attr"`
	OrderID       int     `xml:"OrderId,attr"`
	TransactionID int     `xml:"TransactionId,attr"`
}

Jump to

Keyboard shortcuts

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