namecheap

package module
v0.0.0-...-994a912 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 9 Imported by: 60

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 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"`
	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"`
	DomainSetContacts  *DomainSetContactsResult  `xml:"CommandResponse>DomainSetContactResult"`
	SslActivate        *SslActivateResult        `xml:"CommandResponse>SSLActivateResult"`
	SslCreate          *SslCreateResult          `xml:"CommandResponse>SSLCreateResult"`
	SslCertificates    []SslGetListResult        `xml:"CommandResponse>SSLListResult>SSL"`
	UsersGetPricing    []UsersGetPricingResult   `xml:"CommandResponse>UserGetPricingResult>ProductType"`
	WhoisguardList     []WhoisguardGetListResult `xml:"CommandResponse>WhoisguardGetListResult>Whoisguard"`
	WhoisguardEnable   whoisguardEnableResult    `xml:"CommandResponse>WhoisguardEnableResult"`
	WhoisguardDisable  whoisguardDisableResult   `xml:"CommandResponse>WhoisguardDisableResult"`
	WhoisguardRenew    *WhoisguardRenewResult    `xml:"CommandResponse>WhoisguardRenewResult"`
	Errors             ApiErrors                 `xml:"Errors>Error"`
}

type Client

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

	// 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) 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) DomainGetInfo

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

func (*Client) DomainRenew

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

func (*Client) DomainSetContacts

func (client *Client) DomainSetContacts(domainName string) (*DomainSetContactsResult, 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() ([]DomainGetListResult, 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) SslActivate

func (client *Client) SslActivate(params SslActivateParams) (*SslActivateResult, error)

SslActivate activates a purchased and non-activated SSL certificate

func (*Client) SslCreate

func (client *Client) SslCreate(productType string, years int) (*SslCreateResult, error)

SslCreate creates a new SSL certificate by purchasing it using the account funds

func (*Client) SslGetList

func (client *Client) SslGetList() ([]SslGetListResult, error)

SslGetList gets a list of SSL certificates for a particular user

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
}

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

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

type Registrant

type Registrant struct {
	RegistrantFirstName, RegistrantLastName,
	RegistrantAddress1, RegistrantAddress2, RegistrantCity,
	RegistrantStateProvince, RegistrantPostalCode, RegistrantCountry,
	RegistrantPhone, RegistrantEmailAddress, RegistrantOrganizationName,

	TechFirstName, TechLastName,
	TechAddress1, TechAddress2,
	TechCity, TechStateProvince, TechPostalCode, TechCountry,
	TechPhone, TechEmailAddress, TechOrganizationName,

	AdminFirstName, AdminLastName,
	AdminAddress1, AdminAddress2,
	AdminCity, AdminStateProvince, AdminPostalCode, AdminCountry,
	AdminPhone, AdminEmailAddress, AdminOrganizationName,

	AuxBillingFirstName, AuxBillingLastName,
	AuxBillingAddress1, AuxBillingAddress2,
	AuxBillingCity, AuxBillingStateProvince, AuxBillingPostalCode, AuxBillingCountry,
	AuxBillingPhone, AuxBillingEmailAddress, AuxBillingOrganizationName string
}

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 SSLCertificate

type SSLCertificate struct {
	CertificateID int    `xml:"CertificateID,attr"`
	SSLType       string `xml:"SSLType,attr"`
	Created       string `xml:"Created,attr"`
	Years         int    `xml:"Years,attr"`
	Status        string `xml:"Status,attr"`
}

type SslActivateParams

type SslActivateParams struct {
	CertificateId      int
	Csr                string
	AdminEmailAddress  string
	WebServerType      string
	ApproverEmail      string
	IsHTTPDCValidation bool
	IsDNSDCValidation  bool
}

type SslActivateResult

type SslActivateResult struct {
	ID               int             `xml:"ID,attr"`
	IsSuccess        bool            `xml:"IsSuccess,attr"`
	HttpDCValidation SslDcValidation `xml:"HttpDCValidation"`
	DNSDCValidation  SslDcValidation `xml:"DNSDCValidation"`
}

type SslCreateResult

type SslCreateResult struct {
	IsSuccess      bool             `xml:"IsSuccess,attr"`
	OrderId        int              `xml:"OrderId,attr"`
	TransactionId  int              `xml:"TransactionId,attr"`
	ChargedAmount  float64          `xml:"ChargedAmount,attr"`
	SSLCertificate []SSLCertificate `xml:"SSLCertificate"`
}

type SslDcValidation

type SslDcValidation struct {
	ValueAvailable bool   `xml:"ValueAvailable,attr"`
	Dns            SslDns `xml:"DNS"`
}

type SslDns

type SslDns struct {
	Domain      string `xml:"domain,attr"`
	FileName    string `xml:"FileName,omitempty"`
	FileContent string `xml:"FileContent,omitempty"`
	HostName    string `xml:"HostName,omitempty"`
	Target      string `xml:"Target,omitempty"`
}

type SslGetListResult

type SslGetListResult struct {
	CertificateID        int    `xml:"CertificateID,attr"`
	HostName             string `xml:"HostName,attr"`
	SSLType              string `xml:"SSLType,attr"`
	PurchaseDate         string `xml:"PurchaseDate,attr"`
	ExpireDate           string `xml:"ExpireDate,attr"`
	ActivationExpireDate string `xml:"ActivationExpireDate,attr"`
	IsExpired            bool   `xml:"IsExpiredYN,attr"`
	Status               string `xml:"Status,attr"`
}

SslGetListResult represents the data returned by 'domains.getList'

type TLDListResult

type TLDListResult struct {
	Name string `xml:"Name,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 {
	RawEnabled  string `xml:"Enabled,attr"`
	Enabled     bool   `xml:"-"`
	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