Comparing version 0.3.3 to 1.0.0
@@ -7,7 +7,7 @@ var model = require("./model") | ||
AccessToken.prototype = { | ||
destroy: function(cb) { | ||
this.client.destroy({element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({element: this}); | ||
}, | ||
}; | ||
exports.AccessToken = AccessToken; | ||
exports.AccessToken = AccessToken; |
var base64 = require('base64-js'), | ||
when = require("when"), | ||
nodefn = require("when/node"), | ||
fn = require("when/function"), | ||
http = require('http'), | ||
@@ -43,10 +46,10 @@ https = require('https'); | ||
authorizeFromCredentials: function(cb) { | ||
authorizeFromCredentials: function() { | ||
var client = this; | ||
if (!(this.client_id && this.client_secret)) { | ||
return cb("Instantiate the client with a client_id and client_secret to authorize from credentials"); | ||
throw("Instantiate the client with a client_id and client_secret to authorize from credentials"); | ||
} | ||
this.request({ | ||
return this.request({ | ||
type: "post", | ||
@@ -61,17 +64,18 @@ url: "/oauth/token", | ||
body: "grant_type=client_credentials" | ||
}, function(err, data) { | ||
if (err) return cb(err); | ||
client.access_token = data.access_token; | ||
cb(null, data.access_token); | ||
}).then(function(response) { | ||
client.access_token = response.data.access_token; | ||
return response.data.access_token; | ||
}).catch(function(response) { | ||
return when.reject(response.data); | ||
}); | ||
}, | ||
authorizeFromCode: function(code, cb) { | ||
authorizeFromCode: function(code) { | ||
var client = this; | ||
if (!(this.client_id && this.client_secret && this.redirect_uri)) { | ||
return cb("Instantiate the client with a client_id, client_secret and redirect_uri to authorize from code"); | ||
throw("Instantiate the client with a client_id, client_secret and redirect_uri to authorize from code"); | ||
} | ||
this.request({ | ||
return this.request({ | ||
type: "post", | ||
@@ -90,6 +94,7 @@ url: "/oauth/token", | ||
].join("&") | ||
}, function(err, data) { | ||
if (err) return cb(err); | ||
client.access_token = data.access_token; | ||
cb(null, data.access_token); | ||
}).then(function(response) { | ||
client.access_token = response.data.access_token; | ||
return response.data.access_token; | ||
}).catch(function(response) { | ||
return when.reject(response.data); | ||
}); | ||
@@ -109,14 +114,14 @@ }, | ||
sites: function(options, cb) { this.collection({model: Client.models.Site}, options, cb); }, | ||
sites: function(options) { return this.collection({model: Client.models.Site}, options); }, | ||
site: function(id, cb) { this.element({model: Client.models.Site, id: id}, cb); }, | ||
site: function(id) { return this.element({model: Client.models.Site, id: id}); }, | ||
createSite: function(options, cb) { | ||
this.withAuthorization(cb, function() { | ||
createSite: function(options) { | ||
return this.withAuthorization().then(function(client) { | ||
if (options.dir) { | ||
Client.models.Site.createFromDir(this, options.dir, cb); | ||
return Client.models.Site.createFromDir(client, options.dir); | ||
} else if (options.zip) { | ||
Client.models.Site.createFromZip(this, options.zip, cb); | ||
return Client.models.Site.createFromZip(client, options.zip); | ||
} else { | ||
Client.models.Site.create(this, options, cb); | ||
return Client.models.Site.create(client, options); | ||
} | ||
@@ -126,51 +131,50 @@ }); | ||
forms: function(cb) { this.collection({model: Client.models.Form}, cb); }, | ||
forms: function() { return this.collection({model: Client.models.Form}); }, | ||
form: function(id, cb) { this.element({model: Client.models.Form, id: id}, cb); }, | ||
form: function(id) { return this.element({model: Client.models.Form, id: id}); }, | ||
submissions: function(options, cb) { this.collection({model: Client.models.Submission}, options, cb); }, | ||
submissions: function(options) { return this.collection({model: Client.models.Submission}, options); }, | ||
submission: function(id, cb) { this.element({model: Client.models.Submission, id: id}, cb); }, | ||
submission: function(id) { return this.element({model: Client.models.Submission, id: id}); }, | ||
users: function(options, cb) { this.collection({model: Client.models.User}, options, cb); }, | ||
users: function(options) { return this.collection({model: Client.models.User}, options); }, | ||
user: function(id, cb) { this.element({model: Client.models.User, id: id}, cb); }, | ||
user: function(id) { return this.element({model: Client.models.User, id: id}); }, | ||
createUser: function(attributes, cb) { | ||
this.create({model: Client.models.User, attributes: attributes}, cb); | ||
createUser: function(attributes) { | ||
return this.create({model: Client.models.User, attributes: attributes}); | ||
}, | ||
dnsZones: function(options, cb) { this.collection({model: Client.models.DnsZone}, options, cb); }, | ||
dnsZones: function(options) { return this.collection({model: Client.models.DnsZone}, options); }, | ||
dnsZone: function(id, cb) { this.element({model: Client.models.DnsZone, id: id}, cb); }, | ||
dnsZone: function(id) { return this.element({model: Client.models.DnsZone, id: id}); }, | ||
createDnsZone: function(attributes, cb) { | ||
this.create({model: Client.models.DnsZone, attributes: attributes}, cb); | ||
createDnsZone: function(attributes) { | ||
return this.create({model: Client.models.DnsZone, attributes: attributes}); | ||
}, | ||
accessToken: function(id, cb) { this.element({model: Client.models.AccessToken, id: id}, cb); }, | ||
accessToken: function(id) { return this.element({model: Client.models.AccessToken, id: id}); }, | ||
createAccessToken: function(attributes, cb) { | ||
this.create({model: Client.models.AccessToken, attributes: attributes}, cb); | ||
createAccessToken: function(attributes) { | ||
return this.create({model: Client.models.AccessToken, attributes: attributes}); | ||
}, | ||
createDeployKey: function(attributes, cb) { | ||
this.create({model: Client.models.DeployKey, attributes: attributes}, cb); | ||
createDeployKey: function(attributes) { | ||
return this.create({model: Client.models.DeployKey, attributes: attributes}); | ||
}, | ||
ticket: function(id, cb) { this.element({model: Client.models.Ticket, id: id}, cb); }, | ||
ticket: function(id) { return this.element({model: Client.models.Ticket, id: id}); }, | ||
createTicket: function(cb) { | ||
this.request({ | ||
createTicket: function() { | ||
return this.request({ | ||
url: Client.models.Ticket.path, | ||
type: "post", | ||
body: {client_id: this.client_id} | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
cb(null, new Client.models.Ticket(client, data)); | ||
}).then(function(response) { | ||
return new Client.models.Ticket(response.client, response.data); | ||
}); | ||
}, | ||
collection: function(options, meta, cb) { | ||
if (cb === undefined) { cb = meta; meta = {}} | ||
collection: function(options, meta) { | ||
meta = meta || {}; | ||
var params = []; | ||
@@ -182,21 +186,19 @@ for (var key in meta.params || {}) { | ||
if (meta.per_page) { params.push(["per_page", meta.per_page].join("=")) } | ||
this.withAuthorization(cb, function() { | ||
this.request({ | ||
return this.withAuthorization().then(function(client) { | ||
return client.request({ | ||
url: (options.prefix || "") + options.model.path + (params.length ? "?" + params.join("&") : "") | ||
}, function(err, collection, client, meta) { | ||
if (err) return cb(err); | ||
var result = collection.map(function(data) { return new options.model(client, data); }); | ||
result.meta = meta | ||
cb(null, result); | ||
}) | ||
}).then(function(response) { | ||
var result = response.data.map(function(data) { return new options.model(response.client, data); }); | ||
result.meta = response.meta | ||
return result; | ||
}); | ||
}); | ||
}, | ||
element: function(options, cb) { | ||
this.withAuthorization(cb, function() { | ||
this.request({ | ||
element: function(options) { | ||
return this.withAuthorization().then(function(client) { | ||
return client.request({ | ||
url: (options.prefix || "" ) + options.model.path + "/" + options.id | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
cb(null, new options.model(client, data)); | ||
}).then(function(response) { | ||
return new options.model(response.client, response.data); | ||
}); | ||
@@ -206,11 +208,10 @@ }); | ||
create: function(options, cb) { | ||
this.withAuthorization(cb, function() { | ||
this.request({ | ||
create: function(options) { | ||
return this.withAuthorization().then(function(client) { | ||
return client.request({ | ||
url: (options.prefix || "") + options.model.path, | ||
type: "post", | ||
body: options.attributes | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
cb(null, new options.model(client, data)); | ||
}).then(function(response) { | ||
return new options.model(response.client, response.data); | ||
}); | ||
@@ -220,12 +221,11 @@ }); | ||
update: function(options, cb) { | ||
this.withAuthorization(cb, function() { | ||
this.request({ | ||
update: function(options) { | ||
return this.withAuthorization().then(function(client) { | ||
return client.request({ | ||
url: (options.prefix || "") + options.element.apiPath, | ||
type: "put", | ||
body: options.attributes | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
options.model.call(options.element, client, data); | ||
cb(null, options.element); | ||
}).then(function(response) { | ||
options.model.call(options.element, response.client, response.data); | ||
return options.element; | ||
}); | ||
@@ -235,10 +235,8 @@ }); | ||
destroy: function(options, cb) { | ||
this.withAuthorization(cb, function() { | ||
this.request({ | ||
destroy: function(options) { | ||
return this.withAuthorization().then(function(client) { | ||
return client.request({ | ||
url: (options.prefix || "") + options.element.apiPath, | ||
type: "delete", | ||
ignoreResponse: true | ||
}, function(err) { | ||
return cb(err); | ||
}); | ||
@@ -248,3 +246,3 @@ }); | ||
request: function(options, cb) { | ||
request: function(options) { | ||
var client = this, | ||
@@ -278,56 +276,58 @@ http = this.http, | ||
var request = http.request(requestOptions, function(res) { | ||
var body = "", | ||
data = null; | ||
return when.promise(function(resolve, reject) { | ||
var request = http.request(requestOptions, function(res) { | ||
var body = "", | ||
data = null; | ||
res.on("data", function(chunk) { | ||
body += chunk; | ||
res.on("data", function(chunk) { | ||
body += chunk; | ||
}); | ||
res.on("end", function() { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
if (body && !options.ignoreResponse) { | ||
data = JSON.parse(body); | ||
} | ||
resolve({client: client, data: data, meta: client.metadata(res)}); | ||
} else if (res.statusCode == 401 || res.statusCode == 403) { | ||
reject({data: "Authentication failed", client: client, meta: client.metadata(res)}); | ||
} else { | ||
if ((requestOptions.method === "get" || | ||
requestOptions.method === "put" || | ||
requestOptions.method === "delete") && | ||
(retries > 0 && res.statusCode !== 422 && res.statusCode !== 404)) { | ||
options.retries = retries - 1; | ||
setTimeout(function() { client.request(options).then(resolve).catch(reject); }, 500); | ||
} else { | ||
reject({client: client, data: body, meta: client.metadata(res)}); | ||
} | ||
} | ||
}); | ||
}); | ||
res.on("end", function() { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
if (body && !options.ignoreResponse) { | ||
data = JSON.parse(body); | ||
} | ||
cb(null, data, client, client.metadata(res)); | ||
} else if (res.statusCode == 401 || res.statusCode == 403) { | ||
cb("Authentication failed", null, client, client.metadata(res)); | ||
request.setTimeout(300000, function() { | ||
request.abort(); | ||
}); | ||
request.on("error", function(err) { | ||
if ((requestOptions.method == "get" || | ||
requestOptions.method == "put" || | ||
requestOptions.method == "delete") && | ||
retries > 0) { | ||
options.retries = retries - 1; | ||
setTimeout(function() { client.request(options).then(resolve).catch(reject); }, 500); | ||
} else { | ||
if ((requestOptions.method === "get" || | ||
requestOptions.method === "put" || | ||
requestOptions.method === "delete") && | ||
(retries > 0 && res.statusCode !== 422 && res.statusCode !== 404)) { | ||
options.retries = retries - 1; | ||
setTimeout(function() { client.request(options, cb); }, 500); | ||
} else { | ||
cb(body, null, client, client.metadata(res)); | ||
} | ||
reject({client: client, data: err, meta: null}); | ||
} | ||
}); | ||
}); | ||
request.setTimeout(300000, function() { | ||
request.abort(); | ||
}); | ||
request.on("error", function(err) { | ||
if ((requestOptions.method == "get" || | ||
requestOptions.method == "put" || | ||
requestOptions.method == "delete") && | ||
retries > 0) { | ||
options.retries = retries - 1; | ||
setTimeout(function() { client.request(options, cb); }, 500); | ||
} else { | ||
cb(err, null, client); | ||
if (body) { | ||
request.write(body); | ||
} | ||
request.end(); | ||
}); | ||
if (body) { | ||
request.write(body); | ||
} | ||
request.end(); | ||
}, | ||
withAuthorization: function(cb, fn) { | ||
if (!this.isAuthorized()) return cb("Not authorized: Instantiate client with access_token"); | ||
fn.call(this); | ||
withAuthorization: function() { | ||
if (!this.isAuthorized()) return when.reject("Not authorized: Instantiate client with access_token"); | ||
return when.resolve(this); | ||
}, | ||
@@ -334,0 +334,0 @@ |
@@ -1,2 +0,4 @@ | ||
var model = require("./model"); | ||
var when = require("when"), | ||
nodefn = require("when/node"), | ||
model = require("./model"); | ||
@@ -14,42 +16,33 @@ if (typeof(require) !== 'undefined') { | ||
}, | ||
restore: function(cb) { | ||
restore: function() { | ||
var self = this; | ||
this.client.request({ | ||
return this.client.request({ | ||
url: "/sites/" + this.site_id + "/deploys/" + this.id + "/restore", | ||
type: "post" | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
Deploy.call(self, client, data); | ||
cb(null, self); | ||
}).then(function(response) { | ||
Deploy.call(self, response.client, response.data); | ||
return self; | ||
}).catch(function(response) { | ||
return when.reject(response.data); | ||
}); | ||
}, | ||
publish: function(cb) { | ||
this.restore(cb); | ||
publish: function() { | ||
return this.restore(); | ||
}, | ||
waitForReady: function(cb) { | ||
var self = this; | ||
waitForReady: function() { | ||
if (this.isReady()) { | ||
process.nextTick(function() { cb(null, self); }); | ||
return when.resolve(this); | ||
} else { | ||
setTimeout(function() { | ||
self.refresh(function(err) { | ||
if (err) return cb(err); | ||
self.waitForReady(cb); | ||
}); | ||
}, 1000); | ||
return when.resolve().delay(1000).then(this.refresh.bind(this)).then(this.waitForReady.bind(this)); | ||
} | ||
}, | ||
uploadFiles: function(files, cb) { | ||
if (this.state !== "uploading") return cb(null, this); | ||
if (files.length == 0) { return this.refresh(cb); } | ||
uploadFiles: function(files, progress) { | ||
if (this.state !== "uploading") return when.resolve(this); | ||
if (files.length == 0) { return this.refresh(); } | ||
var self = this, | ||
cbCalled = false, | ||
uploaded = []; | ||
progress && progress("start", {total: files.length}); | ||
files.forEach(function(file) { | ||
fs.readFile(file.abs, function(err, data) { | ||
if (cbCalled) return null; | ||
if (err) { cbCalled = true; return cb(err); } | ||
var self = this; | ||
var results = files.map(function(file) { | ||
return nodefn.call(fs.readFile, file.abs).then(function(data) { | ||
var filePath = file.rel.split("/").map(function(segment) { | ||
@@ -59,3 +52,3 @@ return encodeURIComponent(segment); | ||
self.client.request({ | ||
return self.client.request({ | ||
url: "/deploys/" + self.id + "/files/" + filePath, | ||
@@ -66,13 +59,13 @@ type: "put", | ||
ignoreResponse: true | ||
}, function(err) { | ||
if (cbCalled) return null; | ||
if (err) { cbCalled = true; return cb(err); } | ||
uploaded.push(file); | ||
if (uploaded.length == files.length) { | ||
self.refresh(cb); | ||
} | ||
}).then(function(response) { | ||
progress && progress("upload", {file: file, total: files.length}); | ||
return file; | ||
}).catch(function(response) { | ||
progress && progress("uploadError", {file:file, message: response.data}); | ||
return when.reject(response.data); | ||
}); | ||
}); | ||
}); | ||
return when.all(results).then(self.refresh.bind(self)); | ||
} | ||
@@ -79,0 +72,0 @@ }; |
@@ -8,7 +8,7 @@ var model = require("./model"), | ||
DnsRecord.prototype = { | ||
destroy: function(cb) { | ||
this.client.destroy({prefix: "/dns_zones/" + this.domain_id, element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({prefix: "/dns_zones/" + this.domain_id, element: this}); | ||
}, | ||
}; | ||
exports.DnsRecord = DnsRecord; | ||
exports.DnsRecord = DnsRecord; |
@@ -8,16 +8,16 @@ var model = require("./model"), | ||
DnsZone.prototype = { | ||
destroy: function(cb) { | ||
this.client.destroy({element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({element: this}); | ||
}, | ||
records: function(options, cb) { | ||
this.client.collection({prefix: this.apiPath, model: DnsRecord}, options, cb); | ||
records: function(options) { | ||
return this.client.collection({prefix: this.apiPath, model: DnsRecord}, options); | ||
}, | ||
record: function(id, cb) { | ||
this.client.element({prefix: this.apiPath, model: DnsRecord, id: id}, cb); | ||
record: function(id) { | ||
return this.client.element({prefix: this.apiPath, model: DnsRecord, id: id}); | ||
}, | ||
createRecord: function(attributes, cb) { | ||
this.client.create({prefix: this.apiPath, model: DnsRecord, attributes: attributes}, cb); | ||
} | ||
createRecord: function(attributes) { | ||
return this.client.create({prefix: this.apiPath, model: DnsRecord, attributes: attributes}); | ||
} | ||
}; | ||
exports.DnsZone = DnsZone; | ||
exports.DnsZone = DnsZone; |
@@ -8,7 +8,7 @@ var model = require("./model"), | ||
Form.prototype = { | ||
submissions: function(cb) { | ||
this.client.collection({prefix: this.apiPath, model: Submission}, cb); | ||
submissions: function() { | ||
return this.client.collection({prefix: this.apiPath, model: Submission}); | ||
} | ||
}; | ||
exports.Form = Form; | ||
exports.Form = Form; |
@@ -0,1 +1,3 @@ | ||
var when = require("when"); | ||
exports.constructor = function() { | ||
@@ -9,10 +11,11 @@ var obj = function(client, attributes) { | ||
this.apiPath = obj.path + "/" + this.id; | ||
this.refresh = function(cb) { | ||
this.refresh = function() { | ||
var self = this; | ||
this.client.request({ | ||
return client.request({ | ||
url: this.apiPath | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
obj.call(self, client, data); | ||
cb(null, self); | ||
}).then(function(response) { | ||
obj.call(self, response.client, response.data); | ||
return self; | ||
}).catch(function(response) { | ||
return when.reject(response.data); | ||
}); | ||
@@ -19,0 +22,0 @@ } |
@@ -1,2 +0,3 @@ | ||
var Client = require("./client").Client; | ||
var when = require("when"), | ||
Client = require("./client").Client; | ||
@@ -7,28 +8,22 @@ exports.createClient = function(options) { | ||
exports.deploy = function(options, cb) { | ||
exports.deploy = function(options) { | ||
if (typeof options !== "object") { | ||
return cb("deploy needs an options object"); | ||
return when.reject("deploy needs an options object"); | ||
} | ||
if (!options.access_token) { | ||
return cb("deploy needs an access_token"); | ||
return when.reject("deploy needs an access_token"); | ||
} | ||
if (!options.site_id) { | ||
return cb("deploy needs a site_id"); | ||
return when.reject("deploy needs a site_id"); | ||
} | ||
if (!(options.dir || options.zip)) { | ||
return cb("deploy needs a dir or a zip to deploy"); | ||
return when.reject("deploy needs a dir or a zip to deploy"); | ||
} | ||
this.createClient({access_token: options.access_token}).site(options.site_id, function(err, site) { | ||
if (err) { return cb(err); } | ||
site.createDeploy({dir: options.dir, zip: options.zip}, function(err, deploy) { | ||
if (err) { return cb(err); } | ||
deploy.waitForReady(function(err, deploy) { | ||
return cb(err, deploy); | ||
}); | ||
return this.createClient({access_token: options.access_token}).site(options.site_id).then(function(site) { | ||
return site.createDeploy({dir: options.dir, zip: options.zip}).then(function(deploy) { | ||
return deploy.waitForReady(); | ||
}); | ||
@@ -35,0 +30,0 @@ }); |
259
lib/site.js
@@ -1,23 +0,19 @@ | ||
var path = require("path"), | ||
model = require("./model"), | ||
Form = require("./form").Form, | ||
var path = require("path"), | ||
when = require("when"), | ||
nodefn = require("when/node"), | ||
glob = require("glob"), | ||
crypto = require("crypto"), | ||
fs = require("graceful-fs"); | ||
model = require("./model"), | ||
Form = require("./form").Form, | ||
Submission = require("./submission").Submission, | ||
File = require("./file").File, | ||
Snippet = require("./snippet").Snippet, | ||
Deploy = require("./deploy").Deploy; | ||
File = require("./file").File, | ||
Snippet = require("./snippet").Snippet, | ||
Deploy = require("./deploy").Deploy; | ||
if (typeof(require) !== 'undefined') { | ||
var glob = require("glob"), | ||
path = require("path"), | ||
crypto = require("crypto"), | ||
fs = require("graceful-fs"); | ||
} | ||
var Site = model.constructor(); | ||
Site.path = "/sites"; | ||
var globFiles = function(dir, cb) { | ||
glob("**/*", {cwd: dir}, function(err, files) { | ||
if (err) return cb(err); | ||
function globFiles(dir) { | ||
return nodefn.call(glob, "**/*", {cwd: dir}).then(function(files) { | ||
var filtered = files.filter(function(file) { | ||
@@ -27,82 +23,77 @@ return file.match(/(\/__MACOSX|\/\.)/) ? false : true; | ||
filterFiles(filtered, cb); | ||
}); | ||
return filterFiles(filtered); | ||
}) | ||
}; | ||
var filterFiles = function(filesAndDirs, cb) { | ||
var processed = [], | ||
files = [], | ||
cbCalled = false; | ||
filesAndDirs.forEach(function(fileOrDir) { | ||
fs.lstat(fileOrDir.abs, function(err, stat) { | ||
if (cbCalled) return null; | ||
if (err) { cbCalled = true; return cb(err); } | ||
if (stat.isFile()) { | ||
files.push(fileOrDir); | ||
function filterFiles(filesAndDirs) { | ||
var lstats = filesAndDirs.map(function(fileOrDir) { | ||
return nodefn.call(fs.lstat, fileOrDir.abs) | ||
}); | ||
return when.all(lstats).then(function(fileData) { | ||
var result = []; | ||
for (var i=0,len=fileData.length; i<len; i++) { | ||
var file = filesAndDirs[i], | ||
data = fileData[i]; | ||
if (data.isFile()) { | ||
result.push(file); | ||
} | ||
processed.push(fileOrDir); | ||
if (processed.length == filesAndDirs.length) { | ||
cb(null, files); | ||
} | ||
}); | ||
} | ||
return result; | ||
}); | ||
}; | ||
var calculateShas = function(files, cb) { | ||
var shas = {}, | ||
cbCalled = false, | ||
processed = []; | ||
files.forEach(function(file) { | ||
fs.readFile(file.abs, function(err, data) { | ||
if (cbCalled) return null; | ||
if (err) { cbCalled = true; return cb(err); } | ||
function calculateShas(files) { | ||
var shas = files.map(function(file) { | ||
return nodefn.call(fs.readFile, file.abs).then(function(data) { | ||
var shasum = crypto.createHash('sha1'); | ||
shasum.update(data); | ||
shas[file.rel] = shasum.digest('hex'); | ||
processed.push(file); | ||
if (processed.length == files.length) { | ||
cb(null, shas); | ||
} | ||
file.sha = shasum.digest('hex'); | ||
return true; | ||
}); | ||
}); | ||
return when.all(shas).then(function() { | ||
var result = {}; | ||
files.forEach(function(file) { | ||
result[file.rel] = file.sha; | ||
}); | ||
return {files: files, shas: result}; | ||
}); | ||
}; | ||
var deployFromDir = function(site, dir, draft, cb) { | ||
function deployFromDir(site, dir, draft, progress) { | ||
var fullDir = path.resolve(dir); | ||
fs.stat(fullDir, function(err, stat) { | ||
if (err || stat.isFile()) return cb("No such dir " + dir + " (" + fullDir + ")"); | ||
return nodefn.call(fs.stat, fullDir).then(function(stat) { | ||
if (stat.isFile()) { | ||
throw("No such dir " + dir + " (" + fullDir + ")"); | ||
} | ||
globFiles(fullDir, function(err, files) { | ||
calculateShas(files, function(err, filesWithShas) { | ||
site.client.request({ | ||
url: site.apiPath + "/deploys", | ||
type: "post", | ||
body: JSON.stringify({ | ||
files: filesWithShas, | ||
draft: draft | ||
}) | ||
}, function(err, data) { | ||
if (err) return cb(err); | ||
var deploy = new Deploy(site.client, data); | ||
var shas = {}; | ||
data.required.forEach(function(sha) { shas[sha] = true; }); | ||
var filtered = files.filter(function(file) { return shas[filesWithShas[file.rel]]; }); | ||
deploy.uploadFiles(filtered, function(err, deploy) { | ||
cb(err, deploy); | ||
}); | ||
}); | ||
return globFiles(fullDir).then(calculateShas).then(function(filesWithShas) { | ||
return site.client.request({ | ||
url: site.apiPath + "/deploys", | ||
type: "post", | ||
body: JSON.stringify({ | ||
files: filesWithShas.shas, | ||
draft: draft | ||
}) | ||
}).then(function(response) { | ||
var deploy = new Deploy(site.client, response.data); | ||
var shas = {}; | ||
response.data.required.forEach(function(sha) { shas[sha] = true; }); | ||
var filtered = filesWithShas.files.filter(function(file) { return shas[file.sha]; }); | ||
return deploy.uploadFiles(filtered,progress); | ||
}); | ||
}); | ||
}).catch(function(err) { | ||
return when.reject(err); | ||
}); | ||
}; | ||
var deployFromZip = function(site, zip, draft, cb) { | ||
function deployFromZip(site, zip, draft) { | ||
var fullPath = zip.match(/^\//) ? zip : process.cwd() + "/" + zip; | ||
fs.readFile(fullPath, function(err, zipData) { | ||
if (err) return cb(err); | ||
return nodefn.call(fs.readFile, fullPath).then(function(zipData) { | ||
var path = site.apiPath + "/deploys"; | ||
@@ -112,3 +103,3 @@ | ||
site.client.request({ | ||
return site.client.request({ | ||
url: path, | ||
@@ -118,6 +109,4 @@ type: "post", | ||
contentType: "application/zip" | ||
}, function(err, data) { | ||
if (err) return cb(err); | ||
return cb(null, new Deploy(site.client, data)); | ||
}).then(function(response) { | ||
return new Deploy(site.client, response.data); | ||
}); | ||
@@ -145,22 +134,22 @@ }); | ||
Site.createFromDir = function(client, dir, cb) { | ||
Site.create(client, {}, function(err, site) { | ||
site.createDeploy({dir: dir}, function(err, deploy) { | ||
Site.createFromDir = function(client, dir, progress) { | ||
return Site.create(client, {}).then(function(site) { | ||
return site.createDeploy({dir: dir, progress: progress}).then(function(deploy) { | ||
site.deploy_id = deploy.id; | ||
cb(null, site); | ||
}) | ||
return site; | ||
}); | ||
}); | ||
}; | ||
Site.createFromZip = function(client, zip, cb) { | ||
Site.create(client, {}, function(err, site) { | ||
site.createDeploy({zip: zip}, function(err, deploy) { | ||
Site.createFromZip = function(client, zip) { | ||
return Site.create(client, {}).then(function(site) { | ||
return site.createDeploy({zip: zip}).then(function(deploy) { | ||
site.deploy_id = deploy.id; | ||
cb(null, site); | ||
}) | ||
return site; | ||
}); | ||
}); | ||
}; | ||
Site.create = function(client, attributes, cb) { | ||
client.create({model: Site, attributes: attributesForUpdate(attributes)}, cb); | ||
Site.create = function(client, attributes) { | ||
return client.create({model: Site, attributes: attributesForUpdate(attributes)}); | ||
}; | ||
@@ -172,14 +161,13 @@ | ||
}, | ||
refresh: function(cb) { | ||
refresh: function() { | ||
var self = this; | ||
this.client.request({ | ||
return this.client.request({ | ||
url: "/sites/" + this.id | ||
}, function(err, data, client) { | ||
if (err) return cb(err); | ||
Site.call(self, client, data); | ||
cb(null, self); | ||
}).then(function(response) { | ||
Site.call(self, response.client, response.data); | ||
return self; | ||
}); | ||
}, | ||
update: function(attributes, cb) { | ||
update: function(attributes) { | ||
attributes = attributes || {}; | ||
@@ -190,78 +178,71 @@ | ||
if (attributes.dir) { | ||
createFromDir(this.client, attributes.dir, this.id, cb); | ||
return createFromDir(this.client, attributes.dir, this.id); | ||
} else if (attributes.zip) { | ||
createFromZip(this.client, attributes.zip, this.id, cb); | ||
return createFromZip(this.client, attributes.zip, this.id); | ||
} else { | ||
this.client.update({model: Site, element: this, attributes: attributesForUpdate(attributes)}, cb); | ||
return this.client.update({model: Site, element: this, attributes: attributesForUpdate(attributes)}); | ||
} | ||
}, | ||
destroy: function(cb) { | ||
this.client.destroy({element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({element: this}); | ||
}, | ||
createDeploy: function(attributes, cb) { | ||
createDeploy: function(attributes) { | ||
if (attributes.dir) { | ||
deployFromDir(this, attributes.dir, attributes.draft || false, cb); | ||
return deployFromDir(this, attributes.dir, attributes.draft || false, attributes.progress); | ||
} else if (attributes.zip) { | ||
deployFromZip(this, attributes.zip, attributes.draft || false, cb); | ||
return deployFromZip(this, attributes.zip, attributes.draft || false); | ||
} else { | ||
cb("You must specify a 'dir' or a 'zip' to deploy"); | ||
return when.reject("You must specify a 'dir' or a 'zip' to deploy"); | ||
} | ||
}, | ||
createDraftDeploy: function(attributes, cb) { | ||
createDraftDeploy: function(attributes) { | ||
attributes.draft = true; | ||
this.createDeploy(attributes, cb); | ||
return this.createDeploy(attributes); | ||
}, | ||
waitForReady: function(cb) { | ||
var self = this; | ||
waitForReady: function() { | ||
if (this.isReady()) { | ||
process.nextTick(function() { cb(null, self); }); | ||
} else { | ||
setTimeout(function() { | ||
self.refresh(function(err) { | ||
if (err) return cb(err); | ||
self.waitForReady(cb); | ||
}); | ||
}, 1000); | ||
return when.resolve(this); | ||
} | ||
return when.resolve().delay(1000).then(this.refresh.bind(this)).then(this.waitForReady.bind(this)); | ||
}, | ||
forms: function(options, cb) { | ||
this.client.collection({prefix: this.apiPath, model: Form}, options, cb); | ||
forms: function(options) { | ||
return this.client.collection({prefix: this.apiPath, model: Form}, options); | ||
}, | ||
submissions: function(options, cb) { | ||
this.client.collection({prefix: this.apiPath, model: Submission}, options, cb); | ||
submissions: function(options) { | ||
return this.client.collection({prefix: this.apiPath, model: Submission}, options); | ||
}, | ||
files: function(cb) { | ||
this.client.collection({prefix: this.apiPath, model: File}, cb); | ||
files: function() { | ||
return this.client.collection({prefix: this.apiPath, model: File}); | ||
}, | ||
file: function(path, cb) { | ||
this.client.element({prefix: this.apiPath, model: File, id: path}, cb); | ||
file: function(path) { | ||
return this.client.element({prefix: this.apiPath, model: File, id: path}); | ||
}, | ||
snippets: function(cb) { | ||
this.client.collection({prefix: this.apiPath, model: Snippet}, cb); | ||
snippets: function() { | ||
return this.client.collection({prefix: this.apiPath, model: Snippet}); | ||
}, | ||
snippet: function(id, cb) { | ||
this.client.element({prefix: this.apiPath, model: Snippet, id: id}, cb); | ||
snippet: function(id) { | ||
return this.client.element({prefix: this.apiPath, model: Snippet, id: id}); | ||
}, | ||
createSnippet: function(attributes, cb) { | ||
this.client.create({prefix: this.apiPath, model: Snippet, attributes: attributes}, cb); | ||
createSnippet: function(attributes) { | ||
return this.client.create({prefix: this.apiPath, model: Snippet, attributes: attributes}); | ||
}, | ||
deploys: function(options, cb) { | ||
this.client.collection({prefix: this.apiPath, model: Deploy}, options, cb); | ||
deploys: function(options) { | ||
return this.client.collection({prefix: this.apiPath, model: Deploy}, options); | ||
}, | ||
deploy: function(id, cb) { | ||
this.client.element({prefix: this.apiPath, model: Deploy, id: id}, cb); | ||
deploy: function(id) { | ||
return this.client.element({prefix: this.apiPath, model: Deploy, id: id}); | ||
} | ||
@@ -268,0 +249,0 @@ }; |
@@ -7,10 +7,10 @@ var model = require("./model"); | ||
Snippet.prototype = { | ||
update: function(attributes, cb) { | ||
this.client.update({prefix: "/sites/" + this.site_id, model: Snippet, element: this, attributes: attributes}, cb); | ||
update: function(attributes) { | ||
return this.client.update({prefix: "/sites/" + this.site_id, model: Snippet, element: this, attributes: attributes}); | ||
}, | ||
destroy: function(cb) { | ||
this.client.destroy({prefix: "/sites/" + this.site_id, model: Snippet, element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({prefix: "/sites/" + this.site_id, model: Snippet, element: this}); | ||
} | ||
} | ||
exports.Snippet = Snippet; | ||
exports.Snippet = Snippet; |
@@ -7,10 +7,10 @@ var model = require("./model"); | ||
Ticket.prototype = { | ||
exchange: function(cb) { | ||
this.client.request({ | ||
exchange: function() { | ||
var client = this.client; | ||
return client.request({ | ||
url: this.apiPath + "/exchange", | ||
type: "post" | ||
}, function(err, data, client) { | ||
if (err) { return cb(err) } | ||
client.access_token = data.access_token | ||
cb(null, data); | ||
}).then(function(response) { | ||
client.access_token = response.data.access_token; | ||
return response.data; | ||
}); | ||
@@ -17,0 +17,0 @@ } |
@@ -8,13 +8,13 @@ var model = require("./model"), | ||
User.prototype = { | ||
update: function(attributes, cb) { | ||
this.client.update({element: this, model: User, attributes: attributes}, cb); | ||
update: function(attributes) { | ||
return this.client.update({element: this, model: User, attributes: attributes}); | ||
}, | ||
destroy: function(cb) { | ||
this.client.destroy({element: this}, cb); | ||
destroy: function() { | ||
return this.client.destroy({element: this}); | ||
}, | ||
sites: function(options, cb) { | ||
this.client.collection({prefix: this.apiPath, model: Site}, options, cb); | ||
sites: function(options) { | ||
return this.client.collection({prefix: this.apiPath, model: Site}, options); | ||
} | ||
}; | ||
exports.User = User; | ||
exports.User = User; |
@@ -5,3 +5,3 @@ { | ||
"description": "Netlify API client", | ||
"version": "0.3.3", | ||
"version": "1.0.0", | ||
"bugs": { | ||
@@ -19,3 +19,4 @@ "url": "https://github.com/netlify/netlify-js/issues" | ||
"glob": ">=3.2.6", | ||
"graceful-fs": "^3.0.4" | ||
"graceful-fs": "^3.0.4", | ||
"when": "^3.7.5" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
194
README.md
@@ -42,4 +42,3 @@ Netlify Node Client | ||
client.authorizeFromCredentials(function(err, access_token) { | ||
if (err) return console.log(err); | ||
client.authorizeFromCredentials().then(function(access_token) { | ||
// Client is now ready to do requests | ||
@@ -64,4 +63,3 @@ // You can store the access_token to avoid authorizing in the future | ||
client.authorizeFromCode(params.code, function(err, access_token) { | ||
if (err) return console.log(err); | ||
client.authorizeFromCode(params.code).then(function(access_token) { | ||
// Client is now ready to do requests | ||
@@ -80,4 +78,3 @@ // You can store the access_token to avoid authorizing in the future | ||
netlify.deploy({access_token: "some-token", site_id: "some-site", dir: "/path/to/site"}, function(err, deploy) { | ||
if (err) { return console.log(err); } | ||
netlify.deploy({access_token: "some-token", site_id: "some-site", dir: "/path/to/site"}).then(function(deploy) { | ||
console.log("New deploy is live"); | ||
@@ -93,3 +90,3 @@ }); | ||
```js | ||
client.sites(function(err, sites) { | ||
client.sites().then(function(sites) { | ||
// do work | ||
@@ -102,3 +99,3 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
client.site(id).then(function(site) { | ||
// do work | ||
@@ -111,5 +108,10 @@ }) | ||
```js | ||
client.createSite({name: "my-unique-site-name", domain: "example.com", password: "secret"}, function(err, site) { | ||
client.createSite({ | ||
name: "my-unique-site-name", | ||
domain: "example.com", | ||
password: "secret" | ||
}).then(function(site) { | ||
console.log(site); | ||
}) | ||
``` | ||
@@ -119,5 +121,5 @@ To deploy a site from a dir and wait for the processing of the site to finish: | ||
```js | ||
client.createSite({}, function(err, site) { | ||
site.createDeploy({dir: "/tmp/my-site"}, function(err, deploy) { | ||
deploy.waitForReady(function(deploy) { | ||
client.createSite({}).then(function(site) { | ||
site.createDeploy({dir: "/tmp/my-site"}).then(function(deploy) { | ||
deploy.waitForReady().then(function() { | ||
console.log("Deploy is done: ", deploy); | ||
@@ -132,12 +134,9 @@ }); | ||
```ruby | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error finding site %o", err); | ||
site.createDeploy({zip: "/tmp/my-site.zip"}, function(err, deploy) { | ||
if (err) return console.log("Error updating site %o", err); | ||
deploy.waitForReady(function(err, deploy) { | ||
if (err) return console.log("Error updating site %o", err); | ||
client.site(id).then(function(site) { | ||
site.createDeploy({zip: "/tmp/my-site.zip"}).then(function(deploy) { | ||
deploy.waitForReady().then(function() { | ||
console.log("Site redeployed"); | ||
}); | ||
}); | ||
}) | ||
}); | ||
``` | ||
@@ -148,4 +147,3 @@ | ||
```js | ||
site.update({name: "my-site", customDomain: "www.example.com", notificationEmail: "me@example.com", password: "secret"}, function(err, site) { | ||
if (err) return console.log("Error updating site %o", err); | ||
site.update({name: "my-site", customDomain: "www.example.com", notificationEmail: "me@example.com", password: "secret"}).then(function(site) { | ||
console.log("Updated site"); | ||
@@ -158,4 +156,3 @@ }); | ||
```js | ||
site.destroy(function(err) { | ||
if (err) return console.log("Error deleting site"); | ||
site.destroy().then(function() { | ||
console.log("Site deleted"); | ||
@@ -171,3 +168,3 @@ }); | ||
```js | ||
client.sites(function(err, sites) { | ||
client.sites().then(function(sites) { | ||
// Pagination has first, next, prev and last | ||
@@ -180,2 +177,10 @@ console.log(sites.meta.pagination); | ||
You can use `page` and `per_page` as options to any of the paginatied collection methods: | ||
```js | ||
client.sites({page: 2, per_page: 10}).then(function(sites) { | ||
console.log("Page 2: ", sites); | ||
}); | ||
``` | ||
Forms | ||
@@ -187,3 +192,3 @@ ===== | ||
```js | ||
client.forms(function(err, forms) { | ||
client.forms().then(function(forms) { | ||
// do work | ||
@@ -196,5 +201,4 @@ }) | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.forms(function(err, forms) { | ||
client.site(id).then(function(site) { | ||
site.forms().then(function(forms) { | ||
// do work | ||
@@ -208,4 +212,3 @@ }); | ||
```js | ||
client.form(id, function(err, form) { | ||
if (err) return console.log("Error getting form %o", err); | ||
client.form(id).then(function(form) { | ||
// do work | ||
@@ -218,4 +221,3 @@ }); | ||
```js | ||
client.submissions(function(err, submissions) { | ||
if (err) return console.log("Error getting submissions %o", err); | ||
client.submissions().then(function(submissions) { | ||
// do work | ||
@@ -228,8 +230,6 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.submissions(function(err, submissions) { | ||
if (err) return console.log("Error getting submissions %o", err); | ||
client.site(id).then(function(site) { | ||
site.submissions().then(function(submissions) { | ||
// do work | ||
}) | ||
}); | ||
}); | ||
@@ -241,6 +241,4 @@ ``` | ||
```js | ||
client.form(id, function(err, form) { | ||
if (err) return console.log("Error getting form %o", err); | ||
form.submissions(function(err, submissions) { | ||
if (err) return console.log("Error getting submissions %o", err); | ||
client.form(id).then(function(form) { | ||
form.submissions().then(function(submissions) { | ||
// do work | ||
@@ -254,4 +252,3 @@ }); | ||
```js | ||
client.submission(id, function(err, submission) { | ||
if (err) return console.log("Error getting submission %o", err); | ||
client.submission(id).then(function(submission) { | ||
// do work | ||
@@ -267,6 +264,4 @@ }) | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.files(function(err, files) { | ||
if (err) return console.log("Error getting files %o", err); | ||
client.site(id).then(function(site) { | ||
site.files().then(function(files) { | ||
// do work | ||
@@ -280,16 +275,5 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.file(path, function(err, file) { | ||
if (err) return console.log("Error getting file %o", err); | ||
file.readFile(function(err, data) { | ||
if (err) return console.log("Error reading file %o", err); | ||
console.log("Got data %o", data); | ||
}); | ||
file.writeFile("Hello, World!", function(err, file) { | ||
if (err) return console.log("Error writing to file %o", err); | ||
console.log("Wrote to file - site will now be processing"); | ||
}); | ||
client.site(id).then(function(site) { | ||
site.file(path).then(function(file) { | ||
// do work | ||
}); | ||
@@ -305,3 +289,3 @@ }); | ||
```js | ||
site.deploys(function(err, deploys) { | ||
site.deploys().then(function(deploys) { | ||
// do work | ||
@@ -314,3 +298,3 @@ }); | ||
```js | ||
site.deploy(id, function(err, deploy) { | ||
site.deploy(id).then(function(deploy) { | ||
// do work | ||
@@ -323,3 +307,3 @@ }); | ||
```js | ||
site.createDeploy({dir: "/path/to/folder"}, function(err, deploy) { | ||
site.createDeploy({dir: "/path/to/folder"}).then(function(deploy) { | ||
console.log(deploy) | ||
@@ -332,3 +316,3 @@ }) | ||
```js | ||
site.createDeploy({dir: "/path/to/folder", draft: true}, function(err, deploy) { | ||
site.createDeploy({dir: "/path/to/folder", draft: true}).then(function(deploy) { | ||
console.log(deploy); | ||
@@ -341,5 +325,4 @@ }) | ||
```js | ||
site.deploy(id, function(err, deploy) { | ||
if (err) return console.log(err); | ||
deploy.publish(function(err, deploy) { | ||
site.deploy(id).then(function(deploy) { | ||
deploy.publish().then(function(deploy) { | ||
// restored | ||
@@ -357,6 +340,4 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.snippets(function(err, snippets) { | ||
if (err) return console.log("Error getting snippets %o", err); | ||
client.site(id).then(function(site) { | ||
site.snippets().then(function(snippets) { | ||
// do work | ||
@@ -370,6 +351,4 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
site.snippet(snippetId, function(err, snippet) { | ||
if (err) return console.log("Error getting snippet %o", err); | ||
client.site(id).then(function(site) { | ||
site.snippet(snippetId).then(function(snippet) { | ||
// do work | ||
@@ -385,4 +364,3 @@ }); | ||
```js | ||
client.site(id, function(err, site) { | ||
if (err) return console.log("Error getting site %o", err); | ||
client.site(id).then(function(site) { | ||
site.createSnippet({ | ||
@@ -394,4 +372,3 @@ general: "<script>alert('Hello')</script>", | ||
title: "Alerts" | ||
}, function(err, snippet) { | ||
if (err) return console.log("Error creating snippet %o", err); | ||
}).then(function(snippet) { | ||
console.log(snippet); | ||
@@ -411,4 +388,3 @@ }); | ||
title: "Alerts" | ||
}, function(err, snippet) { | ||
if (err) return console.log("Error creating snippet %o", err); | ||
}).then(function(snippet) { | ||
console.log(snippet); | ||
@@ -421,4 +397,3 @@ }); | ||
```js | ||
snippet.destroy(function(err) { | ||
if (err) return console.log("Error deleting snippet"); | ||
snippet.destroy().then(function() { | ||
console.log("Snippet deleted"); | ||
@@ -436,3 +411,3 @@ }); | ||
```js | ||
client.users(function(err, users) { | ||
client.users().then(function(users) { | ||
// do work | ||
@@ -445,3 +420,3 @@ }); | ||
```js | ||
client.user(id, function(err, user) { | ||
client.user(id).then(function(user) { | ||
// do work | ||
@@ -454,4 +429,3 @@ }); | ||
```js | ||
client.createUser({email: "user@example.com", uid: "12345"}, function(err, user) { | ||
if (err) return console("Error creating user"); | ||
client.createUser({email: "user@example.com", uid: "12345"}).then(function(user) { | ||
console.log(user); | ||
@@ -464,6 +438,4 @@ }); | ||
```js | ||
client.user(id, function(err, user) { | ||
if (err) return console.log("Error getting user"); | ||
user.update({email: "user@example.com", uid: "12345"}, function(err, user) { | ||
if (err) return console("Error updating user"); | ||
client.user(id).then(function(user) { | ||
user.update({email: "user@example.com", uid: "12345"}).then(function(user) { | ||
console.log(user); | ||
@@ -477,6 +449,5 @@ }); | ||
```js | ||
client.user(id, function(err, user) { | ||
if (err) return console.log("Error getting user"); | ||
user.destroy(function(err) { | ||
if (err) return console("Error deleting"); | ||
client.user(id).then(function(user) { | ||
user.destroy().then(function() { | ||
console.log("User deleted"); | ||
}); | ||
@@ -489,6 +460,4 @@ }); | ||
```js | ||
client.user(id, function(err, user) { | ||
if (err) return console.log("Error getting user"); | ||
user.sites(function(err, sites) { | ||
if (err) return console("Error getting sites"); | ||
client.user(id).then(function(user) { | ||
user.sites().then(function(sites) { | ||
console.log(sites); | ||
@@ -507,3 +476,3 @@ }); | ||
```js | ||
client.dnsZones(function(err, zones) { | ||
client.dnsZones().then(function(zones) { | ||
console.log(zones); | ||
@@ -516,3 +485,3 @@ }); | ||
```js | ||
client.dnsZone(id, function(err, zone) { | ||
client.dnsZone(id).then(function(zone) { | ||
console.log(zone); | ||
@@ -525,3 +494,3 @@ }); | ||
```js | ||
client.createDnsZone({name: "example.com"}, function(err, zone) { | ||
client.createDnsZone({name: "example.com"}).then(function(zone) { | ||
console.log(zone); | ||
@@ -534,5 +503,4 @@ }); | ||
```js | ||
client.dnsZone(id, function(err, zone) { | ||
if (err) return console.log(err); | ||
zone.destroy(function(err) { | ||
client.dnsZone(id).then(function(zone) { | ||
zone.destroy().then(function() { | ||
// Deleted | ||
@@ -546,3 +514,3 @@ }); | ||
```js | ||
zone.records(function(err, records) { | ||
zone.records().then(function(records) { | ||
console.log(records); | ||
@@ -555,3 +523,3 @@ }); | ||
```js | ||
zone.record(id, function(err, record) { | ||
zone.record(id).then(function(record) { | ||
console.log(record); | ||
@@ -569,3 +537,3 @@ }); | ||
ttl: 3600 | ||
}, function(err, record) { | ||
}).then(function(record) { | ||
console.log(record); | ||
@@ -578,3 +546,3 @@ }); | ||
```js | ||
record.destroy(function(err) { | ||
record.destroy().then(function() { | ||
// deleted | ||
@@ -592,3 +560,3 @@ }); | ||
```js | ||
client.createAccessToken({user: {email: "test@example.com", uid: "1234"}}, function(err, accessToken) { | ||
client.createAccessToken({user: {email: "test@example.com", uid: "1234"}}).then(function(accessToken) { | ||
// accessToken.access_token | ||
@@ -603,4 +571,4 @@ }); | ||
```js | ||
client.accessToken("token-string", function(err, accessToken) { | ||
accessToken.destroy(function(err) { | ||
client.accessToken("token-string").then(function(accessToken) { | ||
accessToken.destroy().then(function() { | ||
console.log("Access token revoked"); | ||
@@ -607,0 +575,0 @@ }); |
@@ -94,3 +94,3 @@ if (typeof(require) !== 'undefined') { | ||
apiCall: function() { | ||
client.authorizeFromCredentials(function(err, token) { | ||
client.authorizeFromCredentials().then(function(token) { | ||
access_token = token; | ||
@@ -137,3 +137,3 @@ }); | ||
apiCall: function() { | ||
client.authorizeFromCode("my-code", function(err, token) { | ||
client.authorizeFromCode("my-code").then(function(token) { | ||
access_token = token; | ||
@@ -163,3 +163,3 @@ }); | ||
}, | ||
apiCall: function() { client.sites(function(err, data) { sites = data; }); }, | ||
apiCall: function() { client.sites().then(function(data) { sites = data; }); }, | ||
waitsFor: function() { return sites.length; }, | ||
@@ -188,3 +188,3 @@ expectations: function() { | ||
}, | ||
apiCall: function() { client.sites({page: 2, per_page: 4}, function(err, data) { sites = data; }); }, | ||
apiCall: function() { client.sites({page: 2, per_page: 4}).then(function(data) { sites = data; }); }, | ||
waitsFor: function() { return sites.length; }, | ||
@@ -212,3 +212,3 @@ expectations: function() { | ||
}, | ||
apiCall: function() { client.site("123", function(err, data) { site = data; }); }, | ||
apiCall: function() { client.site("123").then(function(data) { site = data; }); }, | ||
waitsFor: function() { return site; }, | ||
@@ -234,3 +234,3 @@ expectations: function() { | ||
}, | ||
apiCall: function() { site.refresh(function(err, site) { }); }, | ||
apiCall: function() { site.refresh(); }, | ||
waitsFor: function() { return site.isReady(); }, | ||
@@ -256,3 +256,3 @@ expectations: function() { | ||
}, | ||
apiCall: function() { site.update({name: "changed"}, function(err, s) { | ||
apiCall: function() { site.update({name: "changed"}).then(function(s) { | ||
site = s; | ||
@@ -281,4 +281,3 @@ })}, | ||
}, | ||
apiCall: function() { site.destroy(function(err, s) { | ||
if (err) return; | ||
apiCall: function() { site.destroy().then(function() { | ||
done = true; | ||
@@ -305,3 +304,3 @@ })}, | ||
}, | ||
apiCall: function() { client.forms(function(err, result) { forms = result; }); }, | ||
apiCall: function() { client.forms().then(function(result) { forms = result; }); }, | ||
waitsFor: function() { return forms; }, | ||
@@ -327,3 +326,3 @@ expectations: function() { | ||
}, | ||
apiCall: function() { site.forms(function(err, result) { forms = result; })}, | ||
apiCall: function() { site.forms().then(function(result) { forms = result; })}, | ||
waitsFor: function() { return forms; }, | ||
@@ -349,3 +348,3 @@ expectations: function() { | ||
apiCall: function() { | ||
client.createUser({email: "user@example.com"}, function(err, u) { | ||
client.createUser({email: "user@example.com"}).then(function(u) { | ||
user = u; | ||
@@ -375,3 +374,3 @@ }); | ||
apiCall: function() { | ||
user.update({email: "user@example.com"}, function(err, u) { | ||
user.update({email: "user@example.com"}).then(function(u) { | ||
done = true; | ||
@@ -401,3 +400,3 @@ }); | ||
apiCall: function() { | ||
user.destroy(function(err) { | ||
user.destroy().then(function() { | ||
done = true; | ||
@@ -430,3 +429,3 @@ }); | ||
title: "Alert" | ||
}, function(err, s) { | ||
}).then(function(s) { | ||
snippet = s; | ||
@@ -458,3 +457,3 @@ }); | ||
title: "hello" | ||
}, function(err, s) { | ||
}).then(function(s) { | ||
done = true; | ||
@@ -484,3 +483,3 @@ }); | ||
apiCall: function() { | ||
snippet.destroy(function(err, s) { | ||
snippet.destroy().then(function(s) { | ||
done = true; | ||
@@ -510,3 +509,3 @@ }); | ||
apiCall: function() { | ||
deploy.restore(function(err, s) { | ||
deploy.restore().then(function(s) { | ||
done = true; | ||
@@ -554,3 +553,3 @@ }); | ||
status: 201, | ||
response: {id: 234, state: "processing", required: [index_sha]} | ||
response: {id: 234, state: "uploading", required: [index_sha]} | ||
}, | ||
@@ -575,3 +574,3 @@ { | ||
], | ||
apiCall: function() { client.createSite({dir: "spec/files/site-dir"}, function(err, s) { | ||
apiCall: function() { client.createSite({dir: "spec/files/site-dir"}).then(function(s) { | ||
site = s; | ||
@@ -609,3 +608,3 @@ })}, | ||
}], | ||
apiCall: function() { client.createSite({zip: "spec/files/site-dir.zip"}, function(err, s) { | ||
apiCall: function() { client.createSite({zip: "spec/files/site-dir.zip"}).then(function(s) { | ||
site = s; | ||
@@ -612,0 +611,0 @@ })}, |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
770732
4
4950
530
+ Addedwhen@^3.7.5
+ Addedwhen@3.7.8(transitive)