Skip to content

Commit 68a89bb

Browse files
authored
Merge pull request #6 from webflow/site-publish
Implements site publishing
2 parents 250e1cd + 218dd1f commit 68a89bb

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "airbnb-base",
33
"rules": {
4-
"no-underscore-dangle": 0
4+
"no-underscore-dangle": 0,
5+
"class-methods-use-this": 0
56
}
67
}

src/ResponseWrapper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class ResponseWrapper {
99

1010
collections: this.api.collections.bind(this.api, { siteId: site._id }),
1111
webhooks: this.api.webhooks.bind(this.api, { siteId: site._id }),
12+
domains: this.api.domains.bind(this.api, { siteId: site._id }),
1213
webhook(first, ...rest) {
1314
return this.api.webhook({ ...first, siteId: site._id }, ...rest);
1415
},
@@ -18,6 +19,15 @@ export default class ResponseWrapper {
1819
removeWebhook(first, ...rest) {
1920
return this.api.removeWebhook({ ...first, siteId: site._id }, ...rest);
2021
},
22+
publishSite(domains) {
23+
return this.api.publishSite({ siteId: site._id, domains });
24+
},
25+
};
26+
}
27+
28+
domain(domain) {
29+
return {
30+
...domain,
2131
};
2232
}
2333

src/Webflow.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ export default class Webflow {
128128
return this.get(`/sites/${siteId}`, query).then(site => this.responseWrapper.site(site));
129129
}
130130

131+
publishSite({ siteId, domains }) {
132+
if (!siteId) return Promise.reject(buildRequiredArgError('siteId'));
133+
if (!domains) return Promise.reject(buildRequiredArgError('domains'));
134+
135+
return this.post(`/sites/${siteId}/publish`, { domains });
136+
}
137+
138+
// Domains
139+
140+
domains({ siteId }) {
141+
if (!siteId) return Promise.reject(buildRequiredArgError('siteId'));
142+
143+
return this.get(`/sites/${siteId}/domains`).then(
144+
domains => domains.map(domain => this.responseWrapper.domain(domain, siteId)),
145+
);
146+
}
147+
131148
// Collections
132149

133150
collections({ siteId }, query = {}) {

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ test('Responds with a list of webhooks', (t) => {
161161
});
162162
});
163163

164+
test('Responds with a list of domains', (t) => {
165+
const scope = nock('https://api.webflow.com')
166+
.get('/sites/123/domains')
167+
.reply(200, [
168+
{
169+
_id: '321',
170+
},
171+
]);
172+
173+
const api = new Webflow({ token: 'token' });
174+
175+
return api.domains({ siteId: '123' }).then((domains) => {
176+
scope.done();
177+
t.is(domains.length, 1);
178+
t.is(domains[0]._id, '321');
179+
});
180+
});
181+
164182
test('Responds with a single webhook', (t) => {
165183
const scope = nock('https://api.webflow.com')
166184
.get('/sites/123/webhooks/321')

0 commit comments

Comments
 (0)