Skip to content

Commit

Permalink
Merge pull request #61 from wf-d-whitely/patch-2
Browse files Browse the repository at this point in the history
Add `deleteItems` and `publishItems` methods. Add data to the `delete` method callsites.
  • Loading branch information
John Agan authored Aug 16, 2022
2 parents 2305de2 + a9ad823 commit a866abd
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/Webflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default class Webflow {
return this.authenticatedFetch("PATCH", path, data, query);
}

delete(path, query = {}) {
return this.authenticatedFetch("DELETE", path, null, query);
delete(path, data, query = {}) {
return this.authenticatedFetch("DELETE", path, data, query);
}

// Meta
Expand Down Expand Up @@ -221,7 +221,11 @@ export default class Webflow {
return Promise.reject(buildRequiredArgError("collectionId"));
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));

return this.delete(`/collections/${collectionId}/items/${itemId}`, query);
return this.delete(
`/collections/${collectionId}/items/${itemId}`,
null,
query
);
}

patchItem({ collectionId, itemId, ...data }, query = {}) {
Expand All @@ -236,6 +240,30 @@ export default class Webflow {
);
}

deleteItems({ collectionId, itemIds, ...data }, query = {}) {
if (!collectionId)
return Promise.reject(buildRequiredArgError("collectionId"));
if (!itemIds) return Promise.reject(buildRequiredArgError("itemIds"));

return this.delete(
`/collections/${collectionId}/items`,
{ ...data, itemIds },
query
);
}

publishItems({ collectionId, itemIds, ...data }, query = {}) {
if (!collectionId)
return Promise.reject(buildRequiredArgError("collectionId"));
if (!itemIds) return Promise.reject(buildRequiredArgError("itemIds"));

return this.put(
`/collections/${collectionId}/items/publish`,
{ ...data, itemIds },
query
);
}

// Users

users({ siteId }, query = {}) {
Expand Down Expand Up @@ -275,7 +303,7 @@ export default class Webflow {
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
if (!userId) return Promise.reject(buildRequiredArgError("userId"));

return this.delete(`/sites/${siteId}/users/${userId}`, query);
return this.delete(`/sites/${siteId}/users/${userId}`, null, query);
}

// Webhooks
Expand Down Expand Up @@ -309,6 +337,6 @@ export default class Webflow {
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
if (!webhookId) return Promise.reject(buildRequiredArgError("webhookId"));

return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, query);
return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, null, query);
}
}

0 comments on commit a866abd

Please sign in to comment.