diff --git a/.eslintrc b/.eslintrc index b117cc01..9d6daa39 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,7 @@ { "extends": "airbnb-base", "rules": { - "no-underscore-dangle": 0 + "no-underscore-dangle": 0, + "class-methods-use-this": 0 } } diff --git a/src/ResponseWrapper.js b/src/ResponseWrapper.js index 96334502..5b77e832 100644 --- a/src/ResponseWrapper.js +++ b/src/ResponseWrapper.js @@ -9,6 +9,7 @@ export default class ResponseWrapper { collections: this.api.collections.bind(this.api, { siteId: site._id }), webhooks: this.api.webhooks.bind(this.api, { siteId: site._id }), + domains: this.api.domains.bind(this.api, { siteId: site._id }), webhook(first, ...rest) { return this.api.webhook({ ...first, siteId: site._id }, ...rest); }, @@ -18,6 +19,15 @@ export default class ResponseWrapper { removeWebhook(first, ...rest) { return this.api.removeWebhook({ ...first, siteId: site._id }, ...rest); }, + publishSite(domains) { + return this.api.publishSite({ siteId: site._id, domains }); + }, + }; + } + + domain(domain) { + return { + ...domain, }; } diff --git a/src/Webflow.js b/src/Webflow.js index 49c4b662..f223059e 100644 --- a/src/Webflow.js +++ b/src/Webflow.js @@ -128,6 +128,23 @@ export default class Webflow { return this.get(`/sites/${siteId}`, query).then(site => this.responseWrapper.site(site)); } + publishSite({ siteId, domains }) { + if (!siteId) return Promise.reject(buildRequiredArgError('siteId')); + if (!domains) return Promise.reject(buildRequiredArgError('domains')); + + return this.post(`/sites/${siteId}/publish`, { domains }); + } + + // Domains + + domains({ siteId }) { + if (!siteId) return Promise.reject(buildRequiredArgError('siteId')); + + return this.get(`/sites/${siteId}/domains`).then( + domains => domains.map(domain => this.responseWrapper.domain(domain, siteId)), + ); + } + // Collections collections({ siteId }, query = {}) { diff --git a/test.js b/test.js index 24824bc4..828f6042 100644 --- a/test.js +++ b/test.js @@ -161,6 +161,24 @@ test('Responds with a list of webhooks', (t) => { }); }); +test('Responds with a list of domains', (t) => { + const scope = nock('https://api.webflow.com') + .get('/sites/123/domains') + .reply(200, [ + { + _id: '321', + }, + ]); + + const api = new Webflow({ token: 'token' }); + + return api.domains({ siteId: '123' }).then((domains) => { + scope.done(); + t.is(domains.length, 1); + t.is(domains[0]._id, '321'); + }); +}); + test('Responds with a single webhook', (t) => { const scope = nock('https://api.webflow.com') .get('/sites/123/webhooks/321')