Coder Social home page Coder Social logo

transip's Introduction

SOAP V5 API Documentation (deprecated)

If you currently use the SOAP API, you may still access the documentation by clicking on LINK. It is strongly advised to switch to the new REST API because the SOAP API will be discontinued in the coming future.

LINK: https://api.transip.nl/docs/transip.nl/package-Transip.html

TransIP API

Small library in Golang that implements:

  • DomainService/getDomainNames
  • DomainService/getInfo
  • DomainService/batchGetInfo
  • DomainService/setDnsEntries
  • DomainService/batchCheckAvailability
  • DomainService/checkAvailability

If you need other methods on the TransIP API be free to fork my code and I'll merge it with love. :)

Why use this library instead of writing own:

  • 'Correctly' implementing __nonce because there's no uniqid in Golang;
  • Correctly implementing signature, RSA Private key signing of cookie signature (unittests included);
  • Tokenized XML-parser to keep data structures free of clutter (stripping SOAP envelopes);

Example code

Get info for a domain

package main

import (
	"github.com/mpdroog/transip"
	"fmt"
)

func printDomainInfo(username, privKeyPath string) error {
	creds := transip.Client{
		Login:     username,
		ReadWrite: false,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
			privKeyPath, err)
	}
    	
	domainService := transip.DomainService{creds}
	domain, err := domainService.Domain("example.com")
	if err != nil {
		return err
	}
	fmt.Printf("\t%+v\n\n", domain)
	return nil
}

Get a list of domain names and return all of their details

package main

import (
	"github.com/mpdroog/transip"
	"fmt"
)

func printDomainNames(username, privKeyPath string) error {
	creds := transip.Client{
		Login:     username,
		ReadWrite: false,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
			privKeyPath, err)
	}
    	
	domainService := transip.DomainService{creds}
	domainNames, err := domainService.DomainNames()
	if err != nil {
		return err
	}
	domains, err := domainService.Domains(domainNames)
	if err != nil {
		return err
	}
	fmt.Printf("Managed domains:\n")
	for _, domain := range domains {
		fmt.Printf("โ˜… %s\n", domain.Name)
		fmt.Printf("\t%+v\n\n", domain)
	}

	return nil
}

Overwrite a domain's DNS entries

package main

import (
	"github.com/mpdroog/transip"
	"fmt"
)

func overWriteDnsEntries(username, privKeyPath, domain string) error {
	creds := transip.Client{
		Login:     username,
		ReadWrite: true,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
	    		privKeyPath, err)
	}

	// 360 = 6min (TTL in seconds)
	recordSet := []transip.DomainDNSentry{
		{Name: "@", Expire: 360, Type: "A", Content: "127.0.0.1"},
	}

	domainService := transip.DomainService{creds}
	err := domainService.SetDNSEntries(domain, recordSet)
	return err
}

Check availability of a domain

package main

import (
	"github.com/mpdroog/transip"
	"fmt"
)

func checkAvailability(username, privKeyPath, domain string) (string, error) {
	creds := transip.Client{
        Login:     username,
        ReadWrite: false,
    }
    if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
        return "", fmt.Errorf("could not load private key from path %s: %s",
            privKeyPath, err)
    }

    domainService := transip.DomainService{creds}
	res, err := domainService.CheckAvailability(domain)
	if err != nil {
		return "", err
	}

    return res, nil
}

Check availability of a batch of domains

package main

import (
	"github.com/mpdroog/transip"
	"fmt"
)

func checkAvailability(username, privKeyPath string, domains []string) ([]transip.DomainCheckResult, error) {
	creds := transip.Client{
        Login:     username,
        ReadWrite: false,
    }
    if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
        return nil, fmt.Errorf("could not load private key from path %s: %s",
            privKeyPath, err)
    }

    domainService := transip.DomainService{creds}
	res, err := domainService.BatchCheckAvailability(domains)
	if err != nil {
		return nil, err
	}

    return res, nil
}

transip's People

Contributors

dpavlotzky avatar freeaqingme avatar mpdroog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.