// https://developer.stackpath.com/en/api/dns/#operation/CreateZoneRecord
551862
func (d *DNSProvider) createZoneRecord(zone *Zone, record Record) error {
	u := fmt.Sprintf("/zones/%s/records", zone.ID)
	req, err := d.newRequest(http.MethodPost, u, record)
	if err != nil {
		return err
	}

	return d.do(req, nil)
}
577492
func (s *ZonesService) ListRecords(accountID string, zoneName string, options *ZoneRecordListOptions) (*zoneRecordsResponse, error) {
	path := versioned(zoneRecordPath(accountID, zoneName, 0))
	recordsResponse := &zoneRecordsResponse{}

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

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

	recordsResponse.HttpResponse = resp
	return recordsResponse, nil
}
1000806
func (s *ZonesService) GetRecord(accountID string, zoneName string, recordID int64) (*zoneRecordResponse, error) {
	path := versioned(zoneRecordPath(accountID, zoneName, recordID))
	recordResponse := &zoneRecordResponse{}

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

	recordResponse.HttpResponse = resp
	return recordResponse, nil
}
458272
func getRecordsByName(client *godo.Client, zoneName, recordName string) ([]godo.DomainRecord, error) {
	records, err := getRecords(client, zoneName)
	if err != nil {
		return nil, err
	}

	// digitalocean record.Name returns record without the zone suffix
	// so normalize record by removing it
	normalizedRecordName := strings.TrimSuffix(recordName, ".")
	normalizedRecordName = strings.TrimSuffix(normalizedRecordName, "."+zoneName)

	var recordsByName []godo.DomainRecord
	for _, record := range records {
		if record.Name == normalizedRecordName {
			recordsByName = append(recordsByName, record)
		}
	}

	return recordsByName, nil
}
214035
func editRecord(c *godo.Client, zoneName string, recordID int, editRequest *godo.DomainRecordEditRequest) error {
	_, _, err := c.Domains.EditRecord(context.TODO(), zoneName, recordID, editRequest)
	if err != nil {
		return fmt.Errorf("error editing record: %v", err)
	}

	return nil
}
1048675
func NewZone(hostname string) *Zone {
	zone := &Zone{Token: "new"}
	zone.Zone.Soa = NewSoaRecord()
	zone.Zone.Name = hostname
	return zone
}
1193966
func (api *Client) CreateRecordingTranscription(id string) (string, error) {
	_, headers, err := api.makeRequest(http.MethodPost, fmt.Sprintf("%s/%s/%s", api.concatUserPath(recordingsPath), id, transcriptionsPath))
	if err != nil {
		return "", err
	}
	return getIDFromLocationHeader(headers), nil
}
384460
func (d *DNS) CreateNewRecord(name string, rtype string, rdata string, ttl int) *DNSRecordSet {
	return &DNSRecordSet{
		// Name
		Name: name,
		// Type
		Type: rtype,
		// RData
		RData: rdata,
		// TTL
		TTL: ttl,
	}
}
778461
func (api *API) DNSRecord(zoneID, recordID string) (DNSRecord, error) {
	uri := "/zones/" + zoneID + "/dns_records/" + recordID
	res, err := api.makeRequest("GET", uri, nil)
	if err != nil {
		return DNSRecord{}, errors.Wrap(err, errMakeRequestError)
	}
	var r DNSRecordResponse
	err = json.Unmarshal(res, &r)
	if err != nil {
		return DNSRecord{}, errors.Wrap(err, errUnmarshalError)
	}
	return r.Result, nil
}
677231
func (_class NetworkClass) Create(sessionID SessionRef, args NetworkRecord) (_retval NetworkRef, _err error) {
	_method := "network.create"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_argsArg, _err := convertNetworkRecordToXen(fmt.Sprintf("%s(%s)", _method, "args"), args)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _argsArg)
	if _err != nil {
		return
	}
	_retval, _err = convertNetworkRefToGo(_method + " -> ", _result.Value)
	return
}
270213
func (c *Client) CreateRecord(domainID string, cr map[string]interface{}) (string, error) {

	path := create.endpoint(domainID, "")
	buf := bytes.NewBuffer(nil)
	enc := json.NewEncoder(buf)
	if err := enc.Encode(cr); err != nil {
		return "", err
	}

	req, err := c.NewRequest("POST", path, buf, "")
	if err != nil {
		return "", fmt.Errorf("Error from NewRequest: %s", err)
	}

	resp, err := checkResp(c.HTTP.Do(req))
	if err != nil {
		return "", fmt.Errorf("Error creating record: %s", err)
	}

	record := new(Record)

	err = decodeBody(resp, &record)
	if err != nil {
		return "", fmt.Errorf("Error parsing record response: %s", err)
	}

	// The request was successful
	return record.StringRecordID(), nil
}
444168
func NewZone(name, file string) *Zone {
	z := &Zone{
		origin:         dns.Fqdn(name),
		origLen:        dns.CountLabel(dns.Fqdn(name)),
		file:           filepath.Clean(file),
		Tree:           &tree.Tree{},
		Expired:        new(bool),
		reloadShutdown: make(chan bool),
		LastReloaded:   time.Now(),
	}
	*z.Expired = false

	return z
}
387180
func (zone *Zone) Save() error {
	// This lock will restrict the concurrency of API calls
	// to 1 save request at a time. This is needed for the Soa.Serial value which
	// is required to be incremented for every subsequent update to a zone
	// so we have to save just one request at a time to ensure this is always
	// incremented properly
	zoneWriteLock.Lock()
	defer zoneWriteLock.Unlock()

	valid, f := zone.validateCnames()
	if valid == false {
		var msg string
		for _, v := range f {
			msg = msg + fmt.Sprintf("\n%s Record '%s' conflicts with CNAME", v.recordType, v.name)
		}
		return &ZoneError{
			zoneName:        zone.Zone.Name,
			apiErrorMessage: "All CNAMEs must be unique in the zone" + msg,
		}
	}

	req, err := client.NewJSONRequest(
		Config,
		"POST",
		"/config-dns/v1/zones/"+zone.Zone.Name,
		zone,
	)
	if err != nil {
		return err
	}

	res, err := client.Do(Config, req)

	// Network error
	if err != nil {
		return &ZoneError{
			zoneName:         zone.Zone.Name,
			httpErrorMessage: err.Error(),
			err:              err,
		}
	}

	// API error
	if client.IsError(res) {
		err := client.NewAPIError(res)
		return &ZoneError{zoneName: zone.Zone.Name, apiErrorMessage: err.Detail, err: err}
	}

	for {
		updatedZone, err := GetZone(zone.Zone.Name)
		if err != nil {
			return err
		}

		if updatedZone.Token != zone.Token {
			*zone = *updatedZone
			break
		}
		time.Sleep(time.Second)
	}

	return nil
}
601661
func (d *DNSProvider) getZoneRecords(name string, zone *Zone) ([]Record, error) {
	u := fmt.Sprintf("/zones/%s/records", zone.ID)
	req, err := d.newRequest(http.MethodGet, u, nil)
	if err != nil {
		return nil, err
	}

	query := req.URL.Query()
	query.Add("page_request.filter", fmt.Sprintf("name='%s' and type='TXT'", name))
	req.URL.RawQuery = query.Encode()

	var records Records
	err = d.do(req, &records)
	if err != nil {
		return nil, err
	}

	if len(records.Records) == 0 {
		return nil, fmt.Errorf("did not find record with name %s", name)
	}

	return records.Records, nil
}
883964
func (s *DNSViewSnapshot) RecordsForZone(zoneInfo DNSZoneInfo) []DNSRecord {
	var records []DNSRecord

	zone := s.zoneMap[zoneInfo.Name]
	if zone != nil {
		for k := range zone.Records {
			records = append(records, zone.Records[k])
		}
	}

	return records
}
83727
func (api *API) DNSRecords(zoneID string, rr DNSRecord) ([]DNSRecord, error) {
	// Construct a query string
	v := url.Values{}
	// Request as many records as possible per page - API max is 50
	v.Set("per_page", "50")
	if rr.Name != "" {
		v.Set("name", rr.Name)
	}
	if rr.Type != "" {
		v.Set("type", rr.Type)
	}
	if rr.Content != "" {
		v.Set("content", rr.Content)
	}

	var query string
	var records []DNSRecord
	page := 1

	// Loop over makeRequest until what we've fetched all records
	for {
		v.Set("page", strconv.Itoa(page))
		query = "?" + v.Encode()
		uri := "/zones/" + zoneID + "/dns_records" + query
		res, err := api.makeRequest("GET", uri, nil)
		if err != nil {
			return []DNSRecord{}, errors.Wrap(err, errMakeRequestError)
		}
		var r DNSListResponse
		err = json.Unmarshal(res, &r)
		if err != nil {
			return []DNSRecord{}, errors.Wrap(err, errUnmarshalError)
		}
		records = append(records, r.Result...)
		if r.ResultInfo.Page >= r.ResultInfo.TotalPages {
			break
		}
		// Loop around and fetch the next page
		page++
	}
	return records, nil
}
1143559
func CreateNewDNS(zoneName string) *DNS {
	return &DNS{
		Resource: &Resource{},
		propName: propName{Name: zoneName},
		Status: DNSStatus{
			Zone: zoneName,
		},
		Provider: DNSProvider{
			Class: "dns",
		},
		Settings: DNSSettings{
			DNS: DNSRecordSets{
				ResourceRecordSets: []DNSRecordSet{},
			},
		},
	}
}