files.com
Version:
Files.com SDK for JavaScript
68 lines (49 loc) • 2.28 kB
JavaScript
/* eslint-disable no-unused-vars */
import Api from '../Api'
import * as errors from '../Errors'
import {
getType, isArray, isInt, isObject, isString,
} from '../utils'
/* eslint-enable no-unused-vars */
/**
* Class DnsRecord
*/
class DnsRecord {
attributes = {}
options = {}
constructor(attributes = {}, options = {}) {
Object.entries(attributes).forEach(([key, value]) => {
const normalizedKey = key.replace('?', '')
this.attributes[normalizedKey] = value
Object.defineProperty(this, normalizedKey, { value, writable: false })
})
this.options = { ...options }
}
isLoaded = () => !!this.attributes.id
// string # Unique label for DNS record; used by Zapier and other integrations.
getId = () => this.attributes.id
// string # DNS record domain name
getDomain = () => this.attributes.domain
// string # DNS record type
getRrtype = () => this.attributes.rrtype
// string # DNS record value
getValue = () => this.attributes.value
// Parameters:
// cursor - string - Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
static list = async (params = {}, options = {}) => {
if (params.cursor && !isString(params.cursor)) {
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params.cursor)}`)
}
if (params.per_page && !isInt(params.per_page)) {
throw new errors.InvalidParameterError(`Bad parameter: per_page must be of type Int, received ${getType(params.per_page)}`)
}
const response = await Api.sendRequest('/dns_records', 'GET', params, options)
return response?.data?.map(obj => new DnsRecord(obj, options)) || []
}
static all = (params = {}, options = {}) =>
DnsRecord.list(params, options)
}
export default DnsRecord
module.exports = DnsRecord
module.exports.default = DnsRecord