goinwx

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 8 Imported by: 88

README

INWX Go API client

Build Status PkgGoDev Go Report Card

This go library implements some parts of the official INWX XML-RPC API.

API

package main

import (
	"log"

	"github.com/nrdcg/goinwx"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	_, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	var request = &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}
Using 2FA

If it is desired to use 2FA without manual entering the TOTP every time, you must set the parameter otp-key to the secret that is shown during the setup of 2FA for you INWX account. Otherwise, you can skip totp.GenerateCode step and enter the verification code of the Google Authenticator app every time manually.

The otp-key looks something like EELTWFL55ESIHPTJAAHBCY7LXBZARUOJ.

package main

import (
	"log"
	"time"

	"github.com/nrdcg/goinwx"
	"github.com/pquerna/otp/totp"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	resp, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	if resp.TFA != "GOOGLE-AUTH" {
		log.Fatal("unsupported 2 Factor Authentication")
	}

	tan, err := totp.GenerateCode("otp-key", time.Now())
	if err != nil {
		log.Fatal(err)
	}

	err = client.Account.Unlock(tan)
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	request := &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}

Supported Features

Full API documentation can be found here.

The following parts are implemented:

  • Account
    • Login
    • Logout
    • Lock
    • Unlock (with mobile TAN)
  • Domains
    • Check
    • Register
    • Delete
    • Info
    • GetPrices
    • List
    • Whois
    • Update
  • Nameservers
    • Check
    • Create
    • Info
    • List
    • CreateRecord
    • UpdateRecord
    • DeleteRecord
    • FindRecordById
  • Contacts
    • List
    • Info
    • Create
    • Update
    • Delete

Contributions

Your contributions are very appreciated.

Documentation

Index

Constants

View Source
const (
	APIBaseURL        = "https://api.domrobot.com/xmlrpc/"
	APISandboxBaseURL = "https://api.ote.domrobot.com/xmlrpc/"
	APILanguage       = "en"
)

API information.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService added in v0.3.0

type AccountService service

AccountService API access to Account.

func (*AccountService) Lock added in v0.3.0

func (s *AccountService) Lock() error

Lock Account lock.

func (*AccountService) Login added in v0.3.0

func (s *AccountService) Login() (*LoginResponse, error)

Login Account login.

func (*AccountService) Logout added in v0.3.0

func (s *AccountService) Logout() error

Logout Account logout.

func (*AccountService) Unlock added in v0.3.0

func (s *AccountService) Unlock(tan string) error

Unlock Account unlock.

type Client

type Client struct {
	// HTTP client used to communicate with the INWX API.
	RPCClient *xmlrpc.Client

	// Services used for communicating with the API
	Account     *AccountService
	Domains     *DomainService
	Nameservers *NameserverService
	Contacts    *ContactService
	// contains filtered or unexported fields
}

Client manages communication with INWX API.

func NewClient

func NewClient(username, password string, opts *ClientOptions) *Client

NewClient returns a new INWX API client.

func (*Client) Do

func (c *Client) Do(req *Request) (map[string]interface{}, error)

Do sends an API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(serviceMethod string, args map[string]interface{}) *Request

NewRequest creates an API request.

type ClientOptions added in v0.2.1

type ClientOptions struct {
	Sandbox bool

	// Language of the return message. (en/de/es)
	Lang string

	// Base URL for API requests (only for client testing purpose).
	BaseURL *url.URL
}

ClientOptions Options of the API client.

type Contact

type Contact struct {
	RoID          int    `mapstructure:"roId"`
	ID            string `mapstructure:"id"`
	Type          string `mapstructure:"type"`
	Name          string `mapstructure:"name"`
	Org           string `mapstructure:"org"`
	Street        string `mapstructure:"street"`
	City          string `mapstructure:"city"`
	PostalCode    string `mapstructure:"pc"`
	StateProvince string `mapstructure:"sp"`
	Country       string `mapstructure:"cc"`
	Phone         string `mapstructure:"voice"`
	Fax           string `mapstructure:"fax"`
	Email         string `mapstructure:"email"`
	Remarks       string `mapstructure:"remarks"`
	Protection    string `mapstructure:"protection"`
}

Contact API model.

type ContactCreateRequest added in v0.3.2

type ContactCreateRequest struct {
	Type          string `structs:"type"`
	Name          string `structs:"name"`
	Org           string `structs:"org,omitempty"`
	Street        string `structs:"street"`
	City          string `structs:"city"`
	PostalCode    string `structs:"pc"`
	StateProvince string `structs:"sp,omitempty"`
	CountryCode   string `structs:"cc"`
	Voice         string `structs:"voice"`
	Fax           string `structs:"fax,omitempty"`
	Email         string `structs:"email"`
	Remarks       string `structs:"remarks,omitempty"`
	Protection    bool   `structs:"protection,omitempty"`
	Testing       bool   `structs:"testing,omitempty"`
}

ContactCreateRequest API model.

type ContactInfoResponse added in v0.3.2

type ContactInfoResponse struct {
	Contact Contact `mapstructure:"contact"`
}

ContactInfoResponse API model.

type ContactListResponse added in v0.3.2

type ContactListResponse struct {
	Count    int       `mapstructure:"count"`
	Contacts []Contact `mapstructure:"contact"`
}

ContactListResponse API model.

type ContactService added in v0.3.2

type ContactService service

ContactService API access to Contact.

func (*ContactService) Create added in v0.3.2

func (s *ContactService) Create(request *ContactCreateRequest) (int, error)

Create Creates a contact.

func (*ContactService) Delete added in v0.3.2

func (s *ContactService) Delete(roID int) error

Delete Deletes a contact.

func (*ContactService) Info added in v0.3.2

func (s *ContactService) Info(contactID int) (*ContactInfoResponse, error)

Info Get information about a contact.

func (*ContactService) List added in v0.3.2

func (s *ContactService) List(search string) (*ContactListResponse, error)

List Search contacts.

func (*ContactService) Update added in v0.3.2

func (s *ContactService) Update(request *ContactUpdateRequest) error

Update Updates a contact.

type ContactUpdateRequest added in v0.3.2

type ContactUpdateRequest struct {
	ID            int    `structs:"id"`
	Name          string `structs:"name,omitempty"`
	Org           string `structs:"org,omitempty"`
	Street        string `structs:"street,omitempty"`
	City          string `structs:"city,omitempty"`
	PostalCode    string `structs:"pc,omitempty"`
	StateProvince string `structs:"sp,omitempty"`
	CountryCode   string `structs:"cc,omitempty"`
	Voice         string `structs:"voice,omitempty"`
	Fax           string `structs:"fax,omitempty"`
	Email         string `structs:"email,omitempty"`
	Remarks       string `structs:"remarks,omitempty"`
	Protection    bool   `structs:"protection,omitempty"`
	Testing       bool   `structs:"testing,omitempty"`
}

ContactUpdateRequest API model.

type DomainCheckResponse

type DomainCheckResponse struct {
	Available   int     `mapstructure:"avail"`
	Status      string  `mapstructure:"status"`
	Name        string  `mapstructure:"name"`
	Domain      string  `mapstructure:"domain"`
	TLD         string  `mapstructure:"tld"`
	CheckMethod string  `mapstructure:"checkmethod"`
	Price       float32 `mapstructure:"price"`
	CheckTime   float32 `mapstructure:"checktime"`
}

DomainCheckResponse API model.

type DomainInfoResponse

type DomainInfoResponse struct {
	RoID         int                `mapstructure:"roId"`
	Domain       string             `mapstructure:"domain"`
	DomainAce    string             `mapstructure:"domainAce"`
	Period       string             `mapstructure:"period"`
	CrDate       time.Time          `mapstructure:"crDate"`
	ExDate       time.Time          `mapstructure:"exDate"`
	UpDate       time.Time          `mapstructure:"upDate"`
	ReDate       time.Time          `mapstructure:"reDate"`
	ScDate       time.Time          `mapstructure:"scDate"`
	TransferLock bool               `mapstructure:"transferLock"`
	Status       string             `mapstructure:"status"`
	AuthCode     string             `mapstructure:"authCode"`
	RenewalMode  string             `mapstructure:"renewalMode"`
	TransferMode string             `mapstructure:"transferMode"`
	Registrant   int                `mapstructure:"registrant"`
	Admin        int                `mapstructure:"admin"`
	Tech         int                `mapstructure:"tech"`
	Billing      int                `mapstructure:"billing"`
	Nameservers  []string           `mapstructure:"ns"`
	NoDelegation bool               `mapstructure:"noDelegation"`
	Contacts     map[string]Contact `mapstructure:"contact"`
}

DomainInfoResponse API model.

type DomainList

type DomainList struct {
	Count   int                  `mapstructure:"count"`
	Domains []DomainInfoResponse `mapstructure:"domain"`
}

DomainList API model.

type DomainListRequest

type DomainListRequest struct {
	Domain       string `structs:"domain,omitempty"`
	RoID         int    `structs:"roId,omitempty"`
	Status       int    `structs:"status,omitempty"`
	Registrant   int    `structs:"registrant,omitempty"`
	Admin        int    `structs:"admin,omitempty"`
	Tech         int    `structs:"tech,omitempty"`
	Billing      int    `structs:"billing,omitempty"`
	RenewalMode  int    `structs:"renewalMode,omitempty"`
	TransferLock int    `structs:"transferLock,omitempty"`
	NoDelegation int    `structs:"noDelegation,omitempty"`
	Tag          int    `structs:"tag,omitempty"`
	Order        int    `structs:"order,omitempty"`
	Page         int    `structs:"page,omitempty"`
	PageLimit    int    `structs:"pagelimit,omitempty"`
}

DomainListRequest API model.

type DomainPriceResponse added in v0.3.2

type DomainPriceResponse struct {
	Tld                 string  `mapstructure:"tld"`
	Currency            string  `mapstructure:"currency"`
	CreatePrice         float32 `mapstructure:"createPrice"`
	MonthlyCreatePrice  float32 `mapstructure:"monthlyCreatePrice"`
	TransferPrice       float32 `mapstructure:"transferPrice"`
	RenewalPrice        float32 `mapstructure:"renewalPrice"`
	MonthlyRenewalPrice float32 `mapstructure:"monthlyRenewalPrice"`
	UpdatePrice         float32 `mapstructure:"updatePrice"`
	TradePrice          float32 `mapstructure:"tradePrice"`
	TrusteePrice        float32 `mapstructure:"trusteePrice"`
	MonthlyTrusteePrice float32 `mapstructure:"monthlyTrusteePrice"`
	CreatePeriod        int     `mapstructure:"createPeriod"`
	TransferPeriod      int     `mapstructure:"transferPeriod"`
	RenewalPeriod       int     `mapstructure:"renewalPeriod"`
	TradePeriod         int     `mapstructure:"tradePeriod"`
}

DomainPriceResponse API model.

type DomainRegisterRequest

type DomainRegisterRequest struct {
	Domain        string   `structs:"domain"`
	Period        string   `structs:"period,omitempty"`
	Registrant    int      `structs:"registrant"`
	Admin         int      `structs:"admin"`
	Tech          int      `structs:"tech"`
	Billing       int      `structs:"billing"`
	Nameservers   []string `structs:"ns,omitempty"`
	TransferLock  string   `structs:"transferLock,omitempty"`
	RenewalMode   string   `structs:"renewalMode,omitempty"`
	WhoisProvider string   `structs:"whoisProvider,omitempty"`
	WhoisURL      string   `structs:"whoisUrl,omitempty"`
	ScDate        string   `structs:"scDate,omitempty"`
	ExtDate       string   `structs:"extDate,omitempty"`
	Asynchron     string   `structs:"asynchron,omitempty"`
	Voucher       string   `structs:"voucher,omitempty"`
	Testing       string   `structs:"testing,omitempty"`
}

DomainRegisterRequest API model.

type DomainRegisterResponse

type DomainRegisterResponse struct {
	RoID     int     `mapstructure:"roId"`
	Price    float32 `mapstructure:"price"`
	Currency string  `mapstructure:"currency"`
}

DomainRegisterResponse API model.

type DomainService

type DomainService service

DomainService API access to Domain.

func (*DomainService) Check

func (s *DomainService) Check(domains []string) ([]DomainCheckResponse, error)

Check checks domains.

func (*DomainService) Delete

func (s *DomainService) Delete(domain string, scheduledDate time.Time) error

Delete deletes a domain.

func (*DomainService) GetPrices added in v0.3.2

func (s *DomainService) GetPrices(tlds []string) ([]DomainPriceResponse, error)

GetPrices gets TLDS prices.

func (*DomainService) Info

func (s *DomainService) Info(domain string, roID int) (*DomainInfoResponse, error)

Info gets information about a domain.

func (*DomainService) List

func (s *DomainService) List(request *DomainListRequest) (*DomainList, error)

List lists domains.

func (*DomainService) Register

Register registers a domain.

func (*DomainService) Update added in v0.8.0

func (s *DomainService) Update(request *DomainUpdateRequest) (float32, error)

Update updates domain information.

func (*DomainService) Whois

func (s *DomainService) Whois(domain string) (string, error)

Whois information about a domains.

type DomainUpdateRequest added in v0.8.0

type DomainUpdateRequest struct {
	Domain       string   `structs:"domain"`
	Nameservers  []string `structs:"ns,omitempty"`
	TransferLock int      `structs:"transferLock,omitempty"`
	RenewalMode  string   `structs:"renewalMode,omitempty"`
	TransferMode string   `structs:"transferMode,omitempty"`
}

DomainUpdateRequest API model.

type DomainUpdateResponse added in v0.8.0

type DomainUpdateResponse struct {
	Price float32 `mapstructure:"price"`
}

DomainUpdateResponse API model.

type ErrorResponse

type ErrorResponse struct {
	Code       int    `xmlrpc:"code"`
	Message    string `xmlrpc:"msg"`
	ReasonCode string `xmlrpc:"reasonCode"`
	Reason     string `xmlrpc:"reason"`
}

An ErrorResponse reports the error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type LoginResponse added in v0.7.0

type LoginResponse struct {
	CustomerID int64  `mapstructure:"customerId"`
	AccountID  int64  `mapstructure:"accountId"`
	TFA        string `mapstructure:"tfa"`
	BuildDate  string `mapstructure:"builddate"`
	Version    string `mapstructure:"version"`
}

LoginResponse API model.

type NameserverCheckResponse

type NameserverCheckResponse struct {
	Details []string `mapstructure:"details"`
	Status  string   `mapstructure:"status"`
}

NameserverCheckResponse API model.

type NameserverCreateRequest added in v0.3.2

type NameserverCreateRequest struct {
	Domain                 string   `structs:"domain"`
	Type                   string   `structs:"type"`
	Nameservers            []string `structs:"ns,omitempty"`
	MasterIP               string   `structs:"masterIp,omitempty"`
	Web                    string   `structs:"web,omitempty"`
	Mail                   string   `structs:"mail,omitempty"`
	SoaEmail               string   `structs:"soaEmail,omitempty"`
	URLRedirectType        string   `structs:"urlRedirectType,omitempty"`
	URLRedirectTitle       string   `structs:"urlRedirectTitle,omitempty"`
	URLRedirectDescription string   `structs:"urlRedirectDescription,omitempty"`
	URLRedirectFavIcon     string   `structs:"urlRedirectFavIcon,omitempty"`
	URLRedirectKeywords    string   `structs:"urlRedirectKeywords,omitempty"`
	Testing                bool     `structs:"testing,omitempty"`
}

NameserverCreateRequest API model.

type NameserverDomain added in v0.2.0

type NameserverDomain struct {
	RoID     int    `mapstructure:"roId"`
	Domain   string `mapstructure:"domain"`
	Type     string `mapstructure:"type"`
	MasterIP string `mapstructure:"masterIp"`
	Mail     string `mapstructure:"mail"`
	Web      string `mapstructure:"web"`
	URL      string `mapstructure:"url"`
	Ipv4     string `mapstructure:"ipv4"`
	Ipv6     string `mapstructure:"ipv6"`
}

NameserverDomain API model.

type NameserverInfoRequest added in v0.4.0

type NameserverInfoRequest struct {
	Domain   string `structs:"domain,omitempty"`
	RoID     int    `structs:"roId,omitempty"`
	RecordID int    `structs:"recordId,omitempty"`
	Type     string `structs:"type,omitempty"`
	Name     string `structs:"name,omitempty"`
	Content  string `structs:"content,omitempty"`
	TTL      int    `structs:"ttl,omitempty"`
	Priority int    `structs:"prio,omitempty"`
}

NameserverInfoRequest API model.

type NameserverInfoResponse added in v0.9.0

type NameserverInfoResponse struct {
	RoID          int                `mapstructure:"roId"`
	Domain        string             `mapstructure:"domain"`
	Type          string             `mapstructure:"type"`
	MasterIP      string             `mapstructure:"masterIp"`
	LastZoneCheck time.Time          `mapstructure:"lastZoneCheck"`
	SlaveDNS      []SlaveInfo        `mapstructure:"slaveDns"`
	SOASerial     string             `mapstructure:"SOAserial"`
	Count         int                `mapstructure:"count"`
	Records       []NameserverRecord `mapstructure:"record"`
}

NameserverInfoResponse API model.

type NameserverListRequest added in v0.9.0

type NameserverListRequest struct {
	Domain    string `structs:"domain,omitempty"`
	Wide      int    `structs:"wide,omitempty"`
	Page      int    `structs:"page,omitempty"`
	PageLimit int    `structs:"pagelimit,omitempty"`
}

NameserverListRequest API model.

type NameserverListResponse added in v0.9.0

type NameserverListResponse struct {
	Count   int                `mapstructure:"count"`
	Domains []NameserverDomain `mapstructure:"domains"`
}

NameserverListResponse API model.

type NameserverRecord

type NameserverRecord struct {
	ID                     int    `mapstructure:"id"`
	Name                   string `mapstructure:"name"`
	Type                   string `mapstructure:"type"`
	Content                string `mapstructure:"content"`
	TTL                    int    `mapstructure:"TTL"`
	Priority               int    `mapstructure:"prio"`
	URLAppend              bool   `mapstructure:"urlAppend,omitempty"`
	URLRedirectType        string `mapstructure:"urlRedirectType"`
	URLRedirectTitle       string `mapstructure:"urlRedirectTitle"`
	URLRedirectDescription string `mapstructure:"urlRedirectDescription"`
	URLRedirectKeywords    string `mapstructure:"urlRedirectKeywords"`
	URLRedirectFavIcon     string `mapstructure:"urlRedirectFavIcon"`
}

NameserverRecord API model.

type NameserverRecordRequest

type NameserverRecordRequest struct {
	RoID                   int    `structs:"roId,omitempty"`
	Domain                 string `structs:"domain,omitempty"`
	Type                   string `structs:"type"`
	Content                string `structs:"content"`
	Name                   string `structs:"name,omitempty"`
	TTL                    int    `structs:"ttl,omitempty"`
	Priority               int    `structs:"prio,omitempty"`
	URLAppend              bool   `structs:"urlAppend,omitempty"`
	URLRedirectType        string `structs:"urlRedirectType,omitempty"`
	URLRedirectTitle       string `structs:"urlRedirectTitle,omitempty"`
	URLRedirectDescription string `structs:"urlRedirectDescription,omitempty"`
	URLRedirectFavIcon     string `structs:"urlRedirectFavIcon,omitempty"`
	URLRedirectKeywords    string `structs:"urlRedirectKeywords,omitempty"`
}

NameserverRecordRequest API model.

type NameserverService

type NameserverService service

NameserverService API access to Nameservers.

func (*NameserverService) Check

func (s *NameserverService) Check(domain string, nameservers []string) (*NameserverCheckResponse, error)

Check checks a domain on nameservers.

func (*NameserverService) Create added in v0.3.2

func (s *NameserverService) Create(request *NameserverCreateRequest) (int, error)

Create creates a nameserver.

func (*NameserverService) CreateRecord

func (s *NameserverService) CreateRecord(request *NameserverRecordRequest) (int, error)

CreateRecord creates a DNS record.

func (*NameserverService) DeleteRecord

func (s *NameserverService) DeleteRecord(recID int) error

DeleteRecord deletes a DNS record.

func (*NameserverService) FindRecordByID added in v0.6.0

func (s *NameserverService) FindRecordByID(recID int) (*NameserverRecord, *NameserverDomain, error)

FindRecordByID search a DNS record by ID.

func (*NameserverService) Info

Info gets information.

func (*NameserverService) List added in v0.2.0

List lists nameservers for a domain. Deprecated: use ListWithParams instead.

func (*NameserverService) ListWithParams added in v0.9.0

func (s *NameserverService) ListWithParams(request *NameserverListRequest) (*NameserverListResponse, error)

ListWithParams lists nameservers for a domain.

func (*NameserverService) UpdateRecord

func (s *NameserverService) UpdateRecord(recID int, request *NameserverRecordRequest) error

UpdateRecord updates a DNS record.

type NamserverInfoResponse

type NamserverInfoResponse = NameserverInfoResponse

NamserverInfoResponse API model. Deprecated: Use NameserverInfoResponse instead.

type NamserverListResponse added in v0.2.0

type NamserverListResponse = NameserverListResponse

NamserverListResponse API model. Deprecated: Use NameserverListResponse instead.

type Request

type Request struct {
	ServiceMethod string
	Args          map[string]interface{}
}

Request The representation of an API request.

type Response

type Response struct {
	Code         int                    `xmlrpc:"code"`
	Message      string                 `xmlrpc:"msg"`
	ReasonCode   string                 `xmlrpc:"reasonCode"`
	Reason       string                 `xmlrpc:"reason"`
	ResponseData map[string]interface{} `xmlrpc:"resData"`
}

Response is a INWX API response. This wraps the standard http.Response returned from INWX.

type SlaveInfo added in v0.6.0

type SlaveInfo struct {
	Name string `mapstructure:"name"`
	IP   string `mapstructure:"ip"`
}

SlaveInfo API model.

Jump to

Keyboard shortcuts

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