Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion lib/pkgcloud/rackspace/dns/client/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,53 @@ var urlJoin = require('url-join'),
dns = pkgcloud.providers.rackspace.dns;

var _urlPrefix = 'domains',
_recordFragment = 'records';
_recordFragment = 'records',
_defaultLimitValue = 100,
_defaultOffsetValue = 0,
_limitParam = 'limit',
_offsetParam = 'offset';

module.exports = {

/**
* @name Client.getRecordsPaged
* @description getRecordsPaged retrieves your a list of records for this domain given the page parameters
* @param {Object|Number} zone the zone for the getRecords query
* @param {Object} page paging parameters for the getRecords query
* @param {Function} callback handles the callback of your api call
*/
getRecordsPaged: function (zone, page, callback) {
var self = this,
zoneId = zone instanceof dns.Zone ? zone.id : zone,
limit = page && page.limit && page.limit <= 100
? parseInt(page.limit)
: _defaultLimitValue,
offset = page && page.offset && page.offset % limit === 0
? parseInt(page.offset)
: _defaultOffsetValue,
params = '?' + [[_limitParam, limit].join('='), [_offsetParam, offset].join('=')].join('&');

var requestOptions = {
path: urlJoin(_urlPrefix, zoneId, _recordFragment, params)
};

self._request(requestOptions, function (err, body, res) {
if(err) {
return callback(err);
}

else if (!body || !body.records) {
return callback(new Error('Unexpected empty response'));
}

else{
return callback(null, body.records.map(function (record) {
return new dns.Record(self, record);
}), res, res.body.totalEntries);
}
});
},

/**
* @name Client.getRecords
* @description getRecords retrieves your list of records for this domain
Expand Down