File: services_domains.go

package info (click to toggle)
golang-github-dnsimple-dnsimple-go 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: makefile: 3
file content (71 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package dnsimple

import (
	"context"
	"fmt"
)

func domainServicesPath(accountID string, domainIdentifier string, serviceIdentifier string) string {
	if serviceIdentifier != "" {
		return fmt.Sprintf("/%v/domains/%v/services/%v", accountID, domainIdentifier, serviceIdentifier)
	}
	return fmt.Sprintf("/%v/domains/%v/services", accountID, domainIdentifier)
}

// DomainServiceSettings represents optional settings when applying a DNSimple one-click service to a domain.
type DomainServiceSettings struct {
	Settings map[string]string `url:"settings,omitempty"`
}

// AppliedServices lists the applied one-click services for a domain.
//
// See https://developer.dnsimple.com/v2/services/domains/#applied
func (s *ServicesService) AppliedServices(ctx context.Context, accountID string, domainIdentifier string, options *ListOptions) (*ServicesResponse, error) {
	path := versioned(domainServicesPath(accountID, domainIdentifier, ""))
	servicesResponse := &ServicesResponse{}

	path, err := addURLQueryOptions(path, options)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.get(ctx, path, servicesResponse)
	if err != nil {
		return servicesResponse, err
	}

	servicesResponse.HTTPResponse = resp
	return servicesResponse, nil
}

// ApplyService applies a one-click services to a domain.
//
// See https://developer.dnsimple.com/v2/services/domains/#apply
func (s *ServicesService) ApplyService(ctx context.Context, accountID string, serviceIdentifier string, domainIdentifier string, settings DomainServiceSettings) (*ServiceResponse, error) {
	path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier))
	serviceResponse := &ServiceResponse{}

	resp, err := s.client.post(ctx, path, settings, nil)
	if err != nil {
		return nil, err
	}

	serviceResponse.HTTPResponse = resp
	return serviceResponse, nil
}

// UnapplyService unapplies a one-click services from a domain.
//
// See https://developer.dnsimple.com/v2/services/domains/#unapply
func (s *ServicesService) UnapplyService(ctx context.Context, accountID string, serviceIdentifier string, domainIdentifier string) (*ServiceResponse, error) {
	path := versioned(domainServicesPath(accountID, domainIdentifier, serviceIdentifier))
	serviceResponse := &ServiceResponse{}

	resp, err := s.client.delete(ctx, path, nil, nil)
	if err != nil {
		return nil, err
	}

	serviceResponse.HTTPResponse = resp
	return serviceResponse, nil
}