Google_Calendar_Helpers::list_calendars()

Method list_calendars.


Description Description

A wp_ajax callback method.


Top ↑

Return Return

(Uncanny_Automatorvoid.)


Source Source

File: src/integrations/google-calendar/helpers/google-calendar-helpers.php

	public function list_calendars() {

		if ( ! wp_verify_nonce( automator_filter_input( 'nonce', INPUT_POST ), 'uncanny_automator' ) ) {
			wp_send_json(
				array(
					'error' => 'Authentication failed. Invalid nonce.',
				)
			);
		}

		$response = get_transient( 'automator_google_calendar_calendar_list' );

		if ( false !== $response ) {
			wp_send_json( $response );
		}

		$body = array(
			'action' => 'list_calendars',
		);

		try {

			$response = $this->api_call( $body, null );

			set_transient( 'automator_google_calendar_calendar_list', $response, 5 * MINUTE_IN_SECONDS );

			wp_send_json( $response );

		} catch ( \Exception $e ) {

			$error_message = $e->getMessage();

			wp_send_json(
				array(
					'error'      => $error_message,
					'error_code' => $e->getCode(),
				)
			);

		}

	}