2022-06-19 20:05:45 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* 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) {
|
2023-10-26 06:41:25 +03:00
|
|
|
return webhook.id ? update(webhook) : store(webhook);
|
2022-06-19 20:05:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an webhook.
|
|
|
|
*
|
|
|
|
* @param {Object} webhook
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
2023-10-26 06:41:25 +03:00
|
|
|
function store(webhook) {
|
|
|
|
const url = App.Utils.Url.siteUrl('webhooks/store');
|
2022-06-19 20:05:45 +03:00
|
|
|
|
|
|
|
const data = {
|
|
|
|
csrf_token: vars('csrf_token'),
|
2023-12-22 13:35:41 +03:00
|
|
|
webhook: webhook,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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'),
|
2023-12-22 13:35:41 +03:00
|
|
|
webhook: webhook,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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'),
|
2023-12-22 13:35:41 +03:00
|
|
|
webhook_id: webhookId,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search webhooks by keyword.
|
|
|
|
*
|
|
|
|
* @param {String} keyword
|
2022-06-21 13:02:10 +03:00
|
|
|
* @param {Number} [limit]
|
|
|
|
* @param {Number} [offset]
|
|
|
|
* @param {String} [orderBy]
|
2022-06-19 20:05:45 +03:00
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
2023-12-22 13:35:41 +03:00
|
|
|
function search(keyword, limit = null, offset = null, orderBy = null) {
|
2022-06-19 20:05:45 +03:00
|
|
|
const url = App.Utils.Url.siteUrl('webhooks/search');
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
csrf_token: vars('csrf_token'),
|
|
|
|
keyword,
|
|
|
|
limit,
|
|
|
|
offset,
|
2024-10-28 18:44:34 +03:00
|
|
|
order_by: orderBy || undefined,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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'),
|
2023-12-22 13:35:41 +03:00
|
|
|
webhook_id: webhookId,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
save,
|
2023-10-26 06:41:25 +03:00
|
|
|
store,
|
2022-06-19 20:05:45 +03:00
|
|
|
update,
|
|
|
|
destroy,
|
|
|
|
search,
|
2023-12-22 13:35:41 +03:00
|
|
|
find,
|
2022-06-19 20:05:45 +03:00
|
|
|
};
|
|
|
|
})();
|