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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
package dnsimple
import (
"context"
"fmt"
)
// TemplateRecord represents a DNS record for a template in DNSimple.
type TemplateRecord struct {
ID int64 `json:"id,omitempty"`
TemplateID int64 `json:"template_id,omitempty"`
Name string `json:"name"`
Content string `json:"content,omitempty"`
TTL int `json:"ttl,omitempty"`
Type string `json:"type,omitempty"`
Priority int `json:"priority,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
func templateRecordPath(accountID string, templateIdentifier string, templateRecordID int64) string {
if templateRecordID != 0 {
return fmt.Sprintf("%v/records/%v", templatePath(accountID, templateIdentifier), templateRecordID)
}
return templatePath(accountID, templateIdentifier) + "/records"
}
// TemplateRecordResponse represents a response from an API method that returns a TemplateRecord struct.
type TemplateRecordResponse struct {
Response
Data *TemplateRecord `json:"data"`
}
// TemplateRecordsResponse represents a response from an API method that returns a collection of TemplateRecord struct.
type TemplateRecordsResponse struct {
Response
Data []TemplateRecord `json:"data"`
}
// ListTemplateRecords list the templates for an account.
//
// See https://developer.dnsimple.com/v2/templates/records/#list
func (s *TemplatesService) ListTemplateRecords(ctx context.Context, accountID string, templateIdentifier string, options *ListOptions) (*TemplateRecordsResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, 0))
templateRecordsResponse := &TemplateRecordsResponse{}
path, err := addURLQueryOptions(path, options)
if err != nil {
return nil, err
}
resp, err := s.client.get(ctx, path, templateRecordsResponse)
if err != nil {
return templateRecordsResponse, err
}
templateRecordsResponse.HTTPResponse = resp
return templateRecordsResponse, nil
}
// CreateTemplateRecord creates a new template record.
//
// See https://developer.dnsimple.com/v2/templates/records/#create
func (s *TemplatesService) CreateTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordAttributes TemplateRecord) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, 0))
templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.post(ctx, path, templateRecordAttributes, templateRecordResponse)
if err != nil {
return nil, err
}
templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil
}
// GetTemplateRecord fetches a template record.
//
// See https://developer.dnsimple.com/v2/templates/records/#get
func (s *TemplatesService) GetTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordID int64) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID))
templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.get(ctx, path, templateRecordResponse)
if err != nil {
return nil, err
}
templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil
}
// DeleteTemplateRecord deletes a template record.
//
// See https://developer.dnsimple.com/v2/templates/records/#delete
func (s *TemplatesService) DeleteTemplateRecord(ctx context.Context, accountID string, templateIdentifier string, templateRecordID int64) (*TemplateRecordResponse, error) {
path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID))
templateRecordResponse := &TemplateRecordResponse{}
resp, err := s.client.delete(ctx, path, nil, nil)
if err != nil {
return nil, err
}
templateRecordResponse.HTTPResponse = resp
return templateRecordResponse, nil
}
|