From c154280026b17e7458c248b88ebe28a78e5cb0e5 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 17 Jan 2022 19:44:21 +0100 Subject: [PATCH] Create new Google HTTP client. --- assets/js/http/google_http_client.js | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 assets/js/http/google_http_client.js diff --git a/assets/js/http/google_http_client.js b/assets/js/http/google_http_client.js new file mode 100755 index 00000000..b15ddb96 --- /dev/null +++ b/assets/js/http/google_http_client.js @@ -0,0 +1,93 @@ +/* ---------------------------------------------------------------------------- + * Easy!Appointments - Open Source Web Scheduler + * + * @package EasyAppointments + * @author A.Tselegidis + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.2.0 + * ---------------------------------------------------------------------------- */ + +/** + * Google HTTP client. + * + * This module implements the Google Calendar related HTTP requests. + */ +App.Http.Google = (function () { + /** + * Select the Google Calendar for the synchronization with a provider. + * + * @param {Number} providerId + * @param {String} googleCalendarId + * + * @return {*|jQuery.jqXHR} + */ + function selectGoogleCalendar(providerId, googleCalendarId) { + const url = App.Utils.Url.siteUrl('google/select_google_calendar'); + + const data = { + csrf_token: App.Vars.csrf_token, + provider_id: providerId, + calendar_id: googleCalendarId + }; + + return $.post(url, data); + } + + /** + * Disable the Google Calendar syncing of a provider. + * + * @param {Number} providerId + * + * @return {*|jQuery.jqXHR} + */ + function disableProviderSync(providerId) { + const url = App.Utils.Url.siteUrl('google/disable_provider_sync'); + + const data = { + csrf_token: App.Vars.csrf_token, + provider_id: providerId + }; + + return $.post(url, data); + } + + /** + * Get the available Google Calendars of the connected provider's account. + * + * @param {Number} providerId + * + * @return {*|jQuery.jqXHR} + */ + function getGoogleCalendars(providerId) { + const url = App.Utils.Url.siteUrl('google/get_google_calendars'); + + const data = { + csrf_token: App.Vars.csrf_token, + provider_id: providerId + }; + + return $.post(url, data); + } + + /** + * Trigger the sync process between Easy!Appointments and Google Calendar. + * + * @param {Number} providerId + * + * @return {*|jQuery.jqXHR} + */ + function syncWithGoogle(providerId) { + const url = App.Utils.Url.siteUrl('google/sync/' + providerId); + + return $.get(url); + } + + return { + getGoogleCalendars, + selectGoogleCalendar, + disableProviderSync, + syncWithGoogle + }; +})();