Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "airbnb-base",
"rules": {
"no-underscore-dangle": 0
"no-underscore-dangle": 0,
"class-methods-use-this": 0
}
}
10 changes: 10 additions & 0 deletions src/ResponseWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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,
};
}

Expand Down
17 changes: 17 additions & 0 deletions src/Webflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down