/*jshint -W069 */
/**
*
* @class domains
* @param {(string|object)} [domainOrOptions] - The project domain or options object. If object, see the object's optional properties.
* @param {string} [domainOrOptions.domain] - The project domain
* @param {object} [domainOrOptions.token] - auth token - object with value property and optional headerOrQueryName and isQuery properties
*/
var domains = (function() {
'use strict';
var request = require('request');
var Q = require('q');
function domains(options) {
var domain = (typeof options === 'object') ? options.domain : options;
this.domain = domain ? domain : 'https://api.godaddy.com';
if (this.domain.length === 0) {
throw new Error('Domain parameter must be specified as a string.');
}
this.token = (typeof options === 'object') ? (options.token ? options.token : {}) : {};
}
/**
* Set Token
* @method
* @name domains#setToken
* @param {string} value - token's value
* @param {string} headerOrQueryName - the header or query name to send the token at
* @param {boolean} isQuery - true if send the token as query param, otherwise, send as header param
*
*/
domains.prototype.setToken = function(value, headerOrQueryName, isQuery) {
this.token.value = value;
this.token.headerOrQueryName = headerOrQueryName;
this.token.isQuery = isQuery;
};
/**
* Update details for the specified Domain
* @method
* @name domains#update
* @param {string} domain - Domain whose details are to be updated
* @param {string} xShopperId - Shopper for whom Domain is to be updated. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {DomainUpdate} body - Changes to apply to existing Domain
*
*/
domains.prototype.update = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PATCH',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Cancel a purchased domain
* @method
* @name domains#cancel
* @param {string} domain - Domain to cancel
*
*/
domains.prototype.cancel = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'DELETE',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve details for the specified Domain
* @method
* @name domains#get
* @param {string} xShopperId - Shopper ID expected to own the specified domain
* @param {string} domain - Domain name whose details are to be retrieved
*
*/
domains.prototype.get = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Determine whether or not the specified domain is available for purchase
* @method
* @name domains#available
* @param {string} domain - Domain name whose availability is to be checked
* @param {string} checkType - Optimize for time ('FAST') or accuracy ('FULL')
* @param {boolean} forTransfer - Whether or not to include domains available for transfer. If set to True, checkType is ignored
*
*/
domains.prototype.available = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/available';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['domain'] !== undefined) {
queryParameters['domain'] = parameters['domain'];
}
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required query parameter: domain'));
return deferred.promise;
}
if (parameters['checkType'] !== undefined) {
queryParameters['checkType'] = parameters['checkType'];
}
if (parameters['forTransfer'] !== undefined) {
queryParameters['forTransfer'] = parameters['forTransfer'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Determine whether or not the specified domains are available for purchase
* @method
* @name domains#availableBulk
* @param {array} domains - Domain names for which to check availability
* @param {string} checkType - Optimize for time ('FAST') or accuracy ('FULL')
*
*/
domains.prototype.availableBulk = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/available';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['domains'] !== undefined) {
body = parameters['domains'];
}
if (parameters['domains'] === undefined) {
deferred.reject(new Error('Missing required body parameter: domains'));
return deferred.promise;
}
if (parameters['checkType'] !== undefined) {
queryParameters['checkType'] = parameters['checkType'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve a list of Domains for the specified Shopper
* @method
* @name domains#list
* @param {string} xShopperId - Shopper ID whose domains are to be retrieved
* @param {array} statuses - Only include results with `status` value in the specified set
* @param {array} statusGroups - Only include results with `status` value in any of the specified groups
* @param {integer} limit - Maximum number of domains to return
* @param {string} marker - Marker Domain to use as the offset in results
* @param {array} includes - Optional details to be included in the response
* @param {string} modifiedDate - Only include results that have been modified since the specified date
*
*/
domains.prototype.list = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters['statuses'] !== undefined) {
queryParameters['statuses'] = parameters['statuses'];
}
if (parameters['statusGroups'] !== undefined) {
queryParameters['statusGroups'] = parameters['statusGroups'];
}
if (parameters['limit'] !== undefined) {
queryParameters['limit'] = parameters['limit'];
}
if (parameters['marker'] !== undefined) {
queryParameters['marker'] = parameters['marker'];
}
if (parameters['includes'] !== undefined) {
queryParameters['includes'] = parameters['includes'];
}
if (parameters['modifiedDate'] !== undefined) {
queryParameters['modifiedDate'] = parameters['modifiedDate'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Submit a privacy cancellation request for the given domain
* @method
* @name domains#cancelPrivacy
* @param {string} xShopperId - Shopper ID of the owner of the domain
* @param {string} domain - Domain whose privacy is to be cancelled
*
*/
domains.prototype.cancelPrivacy = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/privacy';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'DELETE',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Re-send Contact E-mail Verification for specified Domain
* @method
* @name domains#verifyEmail
* @param {string} xShopperId - Shopper for whom domain contact e-mail should be verified. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose Contact E-mail should be verified.
*
*/
domains.prototype.verifyEmail = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/verifyRegistrantEmail';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieves a list of TLDs supported and enabled for sale
* @method
* @name domains#tlds
*
*/
domains.prototype.tlds = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/tlds';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Purchase and register the specified Domain
* @method
* @name domains#purchase
* @param {string} xShopperId - The Shopper for whom the domain should be purchased
* @param {DomainPurchase} body - An instance document expected to match the JSON schema returned by `./schema/{tld}`
*
*/
domains.prototype.purchase = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/purchase';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Renew the specified Domain
* @method
* @name domains#renew
* @param {string} xShopperId - Shopper for whom Domain is to be renewed. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain to renew
* @param {DomainRenew} body - Options for renewing existing Domain
*
*/
domains.prototype.renew = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/renew';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve the schema to be submitted when registering a Domain for the specified TLD
* @method
* @name domains#schema
* @param {string} tld - The Top-Level Domain whose schema should be retrieved
*
*/
domains.prototype.schema = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/purchase/schema/{tld}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
path = path.replace('{tld}', parameters['tld']);
if (parameters['tld'] === undefined) {
deferred.reject(new Error('Missing required path parameter: tld'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Validate the request body using the Domain Purchase Schema for the specified TLD
* @method
* @name domains#validate
* @param {DomainPurchase} body - An instance document expected to match the JSON schema returned by `./schema/{tld}`
*
*/
domains.prototype.validate = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/purchase/validate';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Purchase and start or restart transfer process
* @method
* @name domains#transferIn
* @param {string} xShopperId - The Shopper to whom the domain should be transfered
* @param {string} domain - Domain to transfer in
* @param {DomainTransferIn} body - Details for domain transfer purchase
*
*/
domains.prototype.transferIn = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/transfer';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Purchase privacy for a specified domain
* @method
* @name domains#purchasePrivacy
* @param {string} xShopperId - Shopper ID of the owner of the domain
* @param {string} domain - Domain for which to purchase privacy
* @param {PrivacyPurchase} body - Options for purchasing privacy
*
*/
domains.prototype.purchasePrivacy = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/privacy/purchase';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Create an Identity Document from uploaded image
* @method
* @name domains#createIdentityDocument
* @param {string} xShopperId - Shopper ID of the owner of the identity document. This is only required if you are a Reseller managing,identity documents for your customers. Use this header to pass in their subaccount ID
* @param {IdentityDocumentCreate} identityDocument - Identity document data
*
*/
domains.prototype.createIdentityDocument = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/identityDocuments';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters['identityDocument'] !== undefined) {
body = parameters['identityDocument'];
}
if (parameters['identityDocument'] === undefined) {
deferred.reject(new Error('Missing required body parameter: identityDocument'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Get a collection of identity documents the current shopper owns
* @method
* @name domains#listIdentityDocuments
* @param {string} xShopperId - Shopper ID of the owner of the identity document. This is only required if you are a Reseller managing,identity documents for your customers. Use this header to pass in their subaccount ID
*
*/
domains.prototype.listIdentityDocuments = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/identityDocuments';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Initiate verifications for the specified Domains
* @method
* @name domains#createVerification
* @param {string} xShopperId - Shopper ID of the owner of the identity document. This is only required if you are a Reseller managing,identity documents for your customers. Use this header to pass in their subaccount ID
* @param {string} identityDocumentId - Unique id of an identity document
* @param {array} tlds - An array of TLDs for which the verification was started. Alternately you can specify the whole domain from which the TLD will be extracted
*
*/
domains.prototype.createVerification = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/identityDocuments/{identityDocumentId}/verifications';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{identityDocumentId}', parameters['identityDocumentId']);
if (parameters['identityDocumentId'] === undefined) {
deferred.reject(new Error('Missing required path parameter: identityDocumentId'));
return deferred.promise;
}
if (parameters['tlds'] !== undefined) {
queryParameters['tlds'] = parameters['tlds'];
}
if (parameters['tlds'] === undefined) {
deferred.reject(new Error('Missing required query parameter: tlds'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve a list of Verifications for the specified Identity Document
* @method
* @name domains#getIdentityDocumentVerification
* @param {string} xShopperId - Shopper ID of the owner of the identity document. This is only required if you are a Reseller managing,identity documents for your customers. Use this header to pass in their subaccount ID
* @param {string} identityDocumentId - Unique identifier of the current identity document
* @param {array} tlds - An array of TLDs for which to retrieve identity document verification jobs. Alternately you can specify the whole domain from which the TLD will be extracted
*
*/
domains.prototype.getIdentityDocumentVerification = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/identityDocuments/{identityDocumentId}/verifications';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{identityDocumentId}', parameters['identityDocumentId']);
if (parameters['identityDocumentId'] === undefined) {
deferred.reject(new Error('Missing required path parameter: identityDocumentId'));
return deferred.promise;
}
if (parameters['tlds'] !== undefined) {
queryParameters['tlds'] = parameters['tlds'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Update domain
* @method
* @name domains#updateContacts
* @param {string} xShopperId - Shopper for whom domain contacts are to be updated. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose Contacts are to be updated.
* @param {DomainContacts} contacts - Changes to apply to existing Contacts
*
*/
domains.prototype.updateContacts = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/contacts';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['contacts'] !== undefined) {
body = parameters['contacts'];
}
if (parameters['contacts'] === undefined) {
deferred.reject(new Error('Missing required body parameter: contacts'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PATCH',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve the legal agreement(s) required to purchase the specified TLD and add-ons
* @method
* @name domains#getAgreement
* @param {string} xMarketId - Unique identifier of the Market used to retrieve/translate Legal Agreements
* @param {array} tlds - list of TLDs whose legal agreements are to be retrieved
* @param {boolean} privacy - Whether or not privacy has been requested
* @param {boolean} forTransfer - Whether or not domain tranfer has been requested
*
*/
domains.prototype.getAgreement = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/agreements';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xMarketId'] !== undefined) {
headers['X-Market-Id'] = parameters['xMarketId'];
}
if (parameters['tlds'] !== undefined) {
queryParameters['tlds'] = parameters['tlds'];
}
if (parameters['tlds'] === undefined) {
deferred.reject(new Error('Missing required query parameter: tlds'));
return deferred.promise;
}
if (parameters['privacy'] !== undefined) {
queryParameters['privacy'] = parameters['privacy'];
}
if (parameters['privacy'] === undefined) {
deferred.reject(new Error('Missing required query parameter: privacy'));
return deferred.promise;
}
if (parameters['forTransfer'] !== undefined) {
queryParameters['forTransfer'] = parameters['forTransfer'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Validate the request body using the Domain Contact Validation Schema for specified domains.
* @method
* @name domains#ContactsValidate
* @param {integer} xPrivateLabelId - PrivateLabelId to operate as, if different from JWT
* @param {string} marketId - MarketId in which the request is being made, and for which responses should be localized
* @param {DomainsContactsBulk} body - An instance document expected for domains contacts validation
*
*/
domains.prototype.ContactsValidate = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/contacts/validate';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xPrivateLabelId'] !== undefined) {
headers['X-Private-Label-Id'] = parameters['xPrivateLabelId'];
}
if (parameters['marketId'] !== undefined) {
queryParameters['marketId'] = parameters['marketId'];
}
if (parameters['body'] !== undefined) {
body = parameters['body'];
}
if (parameters['body'] === undefined) {
deferred.reject(new Error('Missing required body parameter: body'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'POST',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Retrieve DNS Records for the specified Domain, optionally with the specified Type and/or Name
* @method
* @name domains#recordGet
* @param {string} xShopperId - Shopper ID which owns the domain. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose DNS Records are to be retrieved
* @param {string} type - DNS Record Type for which DNS Records are to be retrieved
* @param {string} name - DNS Record Name for which DNS Records are to be retrieved
* @param {integer} offset - Number of results to skip for pagination
* @param {integer} limit - Maximum number of items to return
*
*/
domains.prototype.recordGet = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/records/{type?}/{name?}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
path = path.replace('{type}', parameters['type']);
path = path.replace('{name}', parameters['name']);
if (parameters['offset'] !== undefined) {
queryParameters['offset'] = parameters['offset'];
}
if (parameters['limit'] !== undefined) {
queryParameters['limit'] = parameters['limit'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Replace all DNS Records for the specified Domain
* @method
* @name domains#recordReplace
* @param {string} xShopperId - Shopper ID which owns the domain. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose DNS Records are to be replaced
* @param {array} records - DNS Records to replace whatever currently exists
*
*/
domains.prototype.recordReplace = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/records';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['records'] !== undefined) {
body = parameters['records'];
}
if (parameters['records'] === undefined) {
deferred.reject(new Error('Missing required body parameter: records'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PUT',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Add the specified DNS Records to the specified Domain
* @method
* @name domains#recordAdd
* @param {string} xShopperId - Shopper ID which owns the domain. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose DNS Records are to be augmented
* @param {array} records - DNS Records to add to whatever currently exists
*
*/
domains.prototype.recordAdd = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/records';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
if (parameters['records'] !== undefined) {
body = parameters['records'];
}
if (parameters['records'] === undefined) {
deferred.reject(new Error('Missing required body parameter: records'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PATCH',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Replace all DNS Records for the specified Domain with the specified Type
* @method
* @name domains#recordReplaceType
* @param {string} xShopperId - Shopper ID which owns the domain. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose DNS Records are to be replaced
* @param {string} type - DNS Record Type for which DNS Records are to be replaced
* @param {array} records - DNS Records to replace whatever currently exists
*
*/
domains.prototype.recordReplaceType = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/records/{type}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
path = path.replace('{type}', parameters['type']);
if (parameters['type'] === undefined) {
deferred.reject(new Error('Missing required path parameter: type'));
return deferred.promise;
}
if (parameters['records'] !== undefined) {
body = parameters['records'];
}
if (parameters['records'] === undefined) {
deferred.reject(new Error('Missing required body parameter: records'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PUT',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Replace all DNS Records for the specified Domain with the specified Type and Name
* @method
* @name domains#recordReplaceTypeName
* @param {string} xShopperId - Shopper ID which owns the domain. NOTE: This is only required if you are a Reseller managing a domain purchased outside the scope of your reseller account. For instance, if you're a Reseller, but purchased a Domain via http://www.godaddy.com
* @param {string} domain - Domain whose DNS Records are to be replaced
* @param {string} type - DNS Record Type for which DNS Records are to be replaced
* @param {string} name - DNS Record Name for which DNS Records are to be replaced
* @param {array} records - DNS Records to replace whatever currently exists
*
*/
domains.prototype.recordReplaceTypeName = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/{domain}/records/{type}/{name}';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
path = path.replace('{domain}', parameters['domain']);
if (parameters['domain'] === undefined) {
deferred.reject(new Error('Missing required path parameter: domain'));
return deferred.promise;
}
path = path.replace('{type}', parameters['type']);
if (parameters['type'] === undefined) {
deferred.reject(new Error('Missing required path parameter: type'));
return deferred.promise;
}
path = path.replace('{name}', parameters['name']);
if (parameters['name'] === undefined) {
deferred.reject(new Error('Missing required path parameter: name'));
return deferred.promise;
}
if (parameters['records'] !== undefined) {
body = parameters['records'];
}
if (parameters['records'] === undefined) {
deferred.reject(new Error('Missing required body parameter: records'));
return deferred.promise;
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'PUT',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
/**
* Suggest alternate Domain names based on a seed Domain, a set of keywords, or the shopper's purchase history
* @method
* @name domains#suggest
* @param {string} xShopperId - Shopper ID for which the suggestions are being generated
* @param {string} query - Domain name or set of keywords for which alternative domain names will be suggested
* @param {string} country - Two-letter ISO country code to be used as a hint for target region<br/><br/>
NOTE: These are sample values, there are many
<a href="http://www.iso.org/iso/country_codes.htm">more</a>
* @param {string} city - Name of city to be used as a hint for target region
* @param {array} sources - Sources to be queried<br/><br/><ul>
<li><strong>CC_TLD</strong> - Varies the TLD using Country Codes</li>
<li><strong>EXTENSION</strong> - Varies the TLD</li>
<li><strong>KEYWORD_SPIN</strong> - Identifies keywords and then rotates each one</li>
<li><strong>PREMIUM</strong> - Includes variations with premium prices</li></ul>
* @param {array} tlds - Top-level domains to be included in suggestions<br/><br/>
NOTE: These are sample values, there are many
<a href="http://www.godaddy.com/tlds/gtld.aspx#domain_search_form">more</a>
* @param {integer} lengthMax - Maximum length of second-level domain
* @param {integer} lengthMin - Minimum length of second-level domain
* @param {integer} limit - Maximum number of suggestions to return
* @param {integer} waitMs - Maximum amount of time, in milliseconds, to wait for responses
If elapses, return the results compiled up to that point
*
*/
domains.prototype.suggest = function(parameters) {
if (parameters === undefined) {
parameters = {};
}
var deferred = Q.defer();
var domain = this.domain;
var path = '/v1/domains/suggest';
var body;
var queryParameters = {};
var headers = {};
var form = {};
if (this.token.isQuery) {
queryParameters[this.token.headerOrQueryName] = this.token.value;
} else if (this.token.headerOrQueryName) {
headers[this.token.headerOrQueryName] = this.token.value;
} else {
headers['Authorization'] = 'Bearer ' + this.token.value;
}
if (parameters['xShopperId'] !== undefined) {
headers['X-Shopper-Id'] = parameters['xShopperId'];
}
if (parameters['query'] !== undefined) {
queryParameters['query'] = parameters['query'];
}
if (parameters['country'] !== undefined) {
queryParameters['country'] = parameters['country'];
}
if (parameters['city'] !== undefined) {
queryParameters['city'] = parameters['city'];
}
if (parameters['sources'] !== undefined) {
queryParameters['sources'] = parameters['sources'];
}
if (parameters['tlds'] !== undefined) {
queryParameters['tlds'] = parameters['tlds'];
}
Object.keys(parameters).forEach(function(parameterName) {
if (new RegExp('^[1-9][0-9]*$').test(parameterName)) {
queryParameters[parameterName] = parameters[parameterName];
}
});
Object.keys(parameters).forEach(function(parameterName) {
if (new RegExp('^[1-9][0-9]*$').test(parameterName)) {
queryParameters[parameterName] = parameters[parameterName];
}
});
Object.keys(parameters).forEach(function(parameterName) {
if (new RegExp('^[1-9][0-9]*$').test(parameterName)) {
queryParameters[parameterName] = parameters[parameterName];
}
});
if (parameters['waitMs'] !== undefined) {
queryParameters['waitMs'] = parameters['waitMs'];
}
if (parameters.$queryParameters) {
Object.keys(parameters.$queryParameters)
.forEach(function(parameterName) {
var parameter = parameters.$queryParameters[parameterName];
queryParameters[parameterName] = parameter;
});
}
var req = {
method: 'GET',
uri: domain + path,
qs: queryParameters,
headers: headers,
body: body
};
if (Object.keys(form).length > 0) {
req.form = form;
}
if (typeof(body) === 'object' && !(body instanceof Buffer)) {
req.json = true;
}
request(req, function(error, response, body) {
if (error) {
deferred.reject(error);
} else {
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) {
try {
body = JSON.parse(body);
} catch (e) {
}
}
if (response.statusCode === 204) {
deferred.resolve({
response: response
});
} else if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({
response: response,
body: body
});
} else {
deferred.reject({
response: response,
body: body
});
}
}
});
return deferred.promise;
};
return domains;
})();
exports.domains = domains;