iflrandevu/assets/js/http/webhooks_http_client.js

134 lines
2.9 KiB
JavaScript
Raw Normal View History

/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Webhooks HTTP client.
*
* This module implements the webhooks related HTTP requests.
*/
App.Http.Webhooks = (function () {
/**
* Save (create or update) a webhook.
*
* @param {Object} webhook
*
* @return {Object}
*/
function save(webhook) {
return webhook.id ? update(webhook) : create(webhook);
}
/**
* Create an webhook.
*
* @param {Object} webhook
*
* @return {Object}
*/
function create(webhook) {
const url = App.Utils.Url.siteUrl('webhooks/create');
const data = {
csrf_token: vars('csrf_token'),
webhook: webhook
};
return $.post(url, data);
}
/**
* Update an webhook.
*
* @param {Object} webhook
*
* @return {Object}
*/
function update(webhook) {
const url = App.Utils.Url.siteUrl('webhooks/update');
const data = {
csrf_token: vars('csrf_token'),
webhook: webhook
};
return $.post(url, data);
}
/**
* Delete an webhook.
*
* @param {Number} webhookId
*
* @return {Object}
*/
function destroy(webhookId) {
const url = App.Utils.Url.siteUrl('webhooks/destroy');
const data = {
csrf_token: vars('csrf_token'),
webhook_id: webhookId
};
return $.post(url, data);
}
/**
* Search webhooks by keyword.
*
* @param {String} keyword
* @param {Number} limit
* @param {Number} offset
* @param {String} orderBy
*
* @return {Object}
*/
function search(keyword, limit, offset, orderBy) {
const url = App.Utils.Url.siteUrl('webhooks/search');
const data = {
csrf_token: vars('csrf_token'),
keyword,
limit,
offset,
order_by: orderBy
};
return $.post(url, data);
}
/**
* Find an webhook.
*
* @param {Number} webhookId
*
* @return {Object}
*/
function find(webhookId) {
const url = App.Utils.Url.siteUrl('webhooks/find');
const data = {
csrf_token: vars('csrf_token'),
webhook_id: webhookId
};
return $.post(url, data);
}
return {
save,
create,
update,
destroy,
search,
find
};
})();