Blame gdata/services/calendar/gdata-calendar-service.c

Packit 4b6dd7
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
Packit 4b6dd7
/*
Packit 4b6dd7
 * GData Client
Packit 4b6dd7
 * Copyright (C) Philip Withnall 2009, 2014, 2015 <philip@tecnocode.co.uk>
Packit 4b6dd7
 *
Packit 4b6dd7
 * GData Client is free software; you can redistribute it and/or
Packit 4b6dd7
 * modify it under the terms of the GNU Lesser General Public
Packit 4b6dd7
 * License as published by the Free Software Foundation; either
Packit 4b6dd7
 * version 2.1 of the License, or (at your option) any later version.
Packit 4b6dd7
 *
Packit 4b6dd7
 * GData Client is distributed in the hope that it will be useful,
Packit 4b6dd7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4b6dd7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 4b6dd7
 * Lesser General Public License for more details.
Packit 4b6dd7
 *
Packit 4b6dd7
 * You should have received a copy of the GNU Lesser General Public
Packit 4b6dd7
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
Packit 4b6dd7
 */
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * SECTION:gdata-calendar-service
Packit 4b6dd7
 * @short_description: GData Calendar service object
Packit 4b6dd7
 * @stability: Stable
Packit 4b6dd7
 * @include: gdata/services/calendar/gdata-calendar-service.h
Packit 4b6dd7
 *
Packit 4b6dd7
 * #GDataCalendarService is a subclass of #GDataService for communicating with the GData API of Google Calendar. It supports querying
Packit 4b6dd7
 * for, inserting, editing and deleting events from calendars, as well as operations on the calendars themselves.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details of Google Calendar's GData API, see the
Packit 4b6dd7
 * <ulink type="http" url="https://developers.google.com/google-apps/calendar/v3/reference/">
Packit 4b6dd7
 * online documentation</ulink>.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Each calendar accessible through the service has an access control list (ACL) which defines the level of access to the calendar to each user, and
Packit 4b6dd7
 * which users the calendar is shared with. For more information about ACLs for calendars, see the
Packit 4b6dd7
 * <ulink type="http" url="https://developers.google.com/google-apps/calendar/v3/reference/acl">online documentation on
Packit 4b6dd7
 * sharing calendars</ulink>.
Packit 4b6dd7
 *
Packit 4b6dd7
 * <example>
Packit 4b6dd7
 * 	<title>Retrieving the Access Control List for a Calendar</title>
Packit 4b6dd7
 * 	<programlisting>
Packit 4b6dd7
 *	GDataCalendarService *service;
Packit 4b6dd7
 *	GDataCalendarCalendar *calendar;
Packit 4b6dd7
 *	GDataFeed *acl_feed;
Packit 4b6dd7
 *	GDataAccessRule *rule, *new_rule;
Packit 4b6dd7
 *	GDataLink *acl_link;
Packit 4b6dd7
 *	GList *i;
Packit 4b6dd7
 *	GError *error = NULL;
Packit 4b6dd7
 *
Packit 4b6dd7
 *	/* Create a service and retrieve a calendar to work on */
Packit 4b6dd7
 *	service = create_calendar_service ();
Packit 4b6dd7
 *	calendar = get_calendar (service);
Packit 4b6dd7
 *
Packit 4b6dd7
 *	/* Query the service for the ACL for the given calendar */
Packit 4b6dd7
 *	acl_feed = gdata_access_handler_get_rules (GDATA_ACCESS_HANDLER (calendar), GDATA_SERVICE (service), NULL, NULL, NULL, &error);
Packit 4b6dd7
 *
Packit 4b6dd7
 *	if (error != NULL) {
Packit 4b6dd7
 *		g_error ("Error getting ACL feed for calendar: %s", error->message);
Packit 4b6dd7
 *		g_error_free (error);
Packit 4b6dd7
 *		g_object_unref (calendar);
Packit 4b6dd7
 *		g_object_unref (service);
Packit 4b6dd7
 *		return;
Packit 4b6dd7
 *	}
Packit 4b6dd7
 *
Packit 4b6dd7
 *	/* Iterate through the ACL */
Packit 4b6dd7
 *	for (i = gdata_feed_get_entries (acl_feed); i != NULL; i = i->next) {
Packit 4b6dd7
 *		const gchar *scope_value;
Packit 4b6dd7
 *
Packit 4b6dd7
 *		rule = GDATA_ACCESS_RULE (i->data);
Packit 4b6dd7
 *
Packit 4b6dd7
 *		/* Do something with the access rule here. As an example, we update the rule applying to test@gmail.com and delete all
Packit 4b6dd7
 *		 * the other rules. We then insert another rule for example@gmail.com below. */
Packit 4b6dd7
 *		gdata_access_rule_get_scope (rule, NULL, &scope_value);
Packit 4b6dd7
 *		if (scope_value != NULL && strcmp (scope_value, "test@gmail.com") == 0) {
Packit 4b6dd7
 *			GDataAccessRule *updated_rule;
Packit 4b6dd7
 *
Packit 4b6dd7
 *			/* Update the rule to make test@gmail.com an editor (full read/write access to the calendar, but they can't change
Packit 4b6dd7
 *			 * the ACL). */
Packit 4b6dd7
 *			gdata_access_rule_set_role (rule, GDATA_CALENDAR_ACCESS_ROLE_EDITOR);
Packit 4b6dd7
 *			updated_rule = GDATA_ACCESS_RULE (gdata_service_update_entry (GDATA_SERVICE (service), GDATA_ENTRY (rule), NULL, &error));
Packit 4b6dd7
 *
Packit 4b6dd7
 *			if (error != NULL) {
Packit 4b6dd7
 *				g_error ("Error updating access rule for %s: %s", scope_value, error->message);
Packit 4b6dd7
 *				g_error_free (error);
Packit 4b6dd7
 *				g_object_unref (acl_feed);
Packit 4b6dd7
 *				g_object_unref (calendar);
Packit 4b6dd7
 *				g_object_unref (service);
Packit 4b6dd7
 *				return;
Packit 4b6dd7
 *			}
Packit 4b6dd7
 *
Packit 4b6dd7
 *			g_object_unref (updated_rule);
Packit 4b6dd7
 *		} else {
Packit 4b6dd7
 *			/* Delete any rule which doesn't apply to test@gmail.com */
Packit 4b6dd7
 *			gdata_service_delete_entry (GDATA_SERVICE (service), GDATA_ENTRY (rule), NULL, &error);
Packit 4b6dd7
 *
Packit 4b6dd7
 *			if (error != NULL) {
Packit 4b6dd7
 *				g_error ("Error deleting access rule for %s: %s", scope_value, error->message);
Packit 4b6dd7
 *				g_error_free (error);
Packit 4b6dd7
 *				g_object_unref (acl_feed);
Packit 4b6dd7
 *				g_object_unref (calendar);
Packit 4b6dd7
 *				g_object_unref (service);
Packit 4b6dd7
 *				return;
Packit 4b6dd7
 *			}
Packit 4b6dd7
 *		}
Packit 4b6dd7
 *	}
Packit 4b6dd7
 *
Packit 4b6dd7
 *	g_object_unref (acl_feed);
Packit 4b6dd7
 *
Packit 4b6dd7
 *	/* Create and insert a new access rule for example@gmail.com which allows them to view free/busy information for events in the
Packit 4b6dd7
 *	 * calendar, but doesn't allow them to view the full event details. */
Packit 4b6dd7
 *	rule = gdata_access_rule_new (NULL);
Packit 4b6dd7
 *	gdata_access_rule_set_role (rule, GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY);
Packit 4b6dd7
 *	gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "example@gmail.com");
Packit 4b6dd7
 *
Packit 4b6dd7
 *	acl_link = gdata_entry_look_up_link (GDATA_ENTRY (calendar), GDATA_LINK_ACCESS_CONTROL_LIST);
Packit 4b6dd7
 *	new_rule = GDATA_ACCESS_RULE (gdata_service_insert_entry (GDATA_SERVICE (service), gdata_link_get_uri (acl_link), GDATA_ENTRY (rule),
Packit 4b6dd7
 *	                                                          NULL, &error));
Packit 4b6dd7
 *
Packit 4b6dd7
 *	g_object_unref (rule);
Packit 4b6dd7
 *	g_object_unref (calendar);
Packit 4b6dd7
 *	g_object_unref (service);
Packit 4b6dd7
 *
Packit 4b6dd7
 *	if (error != NULL) {
Packit 4b6dd7
 *		g_error ("Error inserting access rule: %s", error->message);
Packit 4b6dd7
 *		g_error_free (error);
Packit 4b6dd7
 *		return;
Packit 4b6dd7
 *	}
Packit 4b6dd7
 *
Packit 4b6dd7
 *	g_object_unref (acl_link);
Packit 4b6dd7
 * 	</programlisting>
Packit 4b6dd7
 * </example>
Packit 4b6dd7
 *
Packit 4b6dd7
 * Before version 0.17.2, the Calendar service could be manipulated using
Packit 4b6dd7
 * batch operations. That is no longer supported, and any batch operations
Packit 4b6dd7
 * created on the calendar will fail.
Packit 4b6dd7
 */
Packit 4b6dd7
Packit 4b6dd7
#include <config.h>
Packit 4b6dd7
#include <glib.h>
Packit 4b6dd7
#include <glib/gi18n-lib.h>
Packit 4b6dd7
#include <libsoup/soup.h>
Packit 4b6dd7
#include <string.h>
Packit 4b6dd7
Packit 4b6dd7
#include "gdata-calendar-service.h"
Packit 4b6dd7
#include "gdata-batchable.h"
Packit 4b6dd7
#include "gdata-service.h"
Packit 4b6dd7
#include "gdata-private.h"
Packit 4b6dd7
#include "gdata-query.h"
Packit 4b6dd7
#include "gdata-calendar-feed.h"
Packit 4b6dd7
Packit 4b6dd7
/* Standards reference here:
Packit 4b6dd7
 * https://developers.google.com/google-apps/calendar/v3/reference/ */
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
parse_error_response (GDataService *self,
Packit 4b6dd7
                      GDataOperationType operation_type,
Packit 4b6dd7
                      guint status,
Packit 4b6dd7
                      const gchar *reason_phrase,
Packit 4b6dd7
                      const gchar *response_body,
Packit 4b6dd7
                      gint length,
Packit 4b6dd7
                      GError **error);
Packit 4b6dd7
static GList *get_authorization_domains (void);
Packit 4b6dd7
Packit 4b6dd7
_GDATA_DEFINE_AUTHORIZATION_DOMAIN (calendar, "cl", "https://www.google.com/calendar/feeds/")
Packit 4b6dd7
G_DEFINE_TYPE_WITH_CODE (GDataCalendarService, gdata_calendar_service, GDATA_TYPE_SERVICE, G_IMPLEMENT_INTERFACE (GDATA_TYPE_BATCHABLE, NULL))
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_calendar_service_class_init (GDataCalendarServiceClass *klass)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataServiceClass *service_class = GDATA_SERVICE_CLASS (klass);
Packit 4b6dd7
	service_class->feed_type = GDATA_TYPE_CALENDAR_FEED;
Packit 4b6dd7
	service_class->parse_error_response = parse_error_response;
Packit 4b6dd7
	service_class->get_authorization_domains = get_authorization_domains;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static void
Packit 4b6dd7
gdata_calendar_service_init (GDataCalendarService *self)
Packit 4b6dd7
{
Packit 4b6dd7
	/* Nothing to see here */
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/* The error format used by the Google Calendar API doesn’t seem to be
Packit 4b6dd7
 * documented anywhere, which is a little frustrating. Here’s an example of it:
Packit 4b6dd7
 *     {
Packit 4b6dd7
 *      "error": {
Packit 4b6dd7
 *       "errors": [
Packit 4b6dd7
 *        {
Packit 4b6dd7
 *         "domain": "global",
Packit 4b6dd7
 *         "reason": "parseError",
Packit 4b6dd7
 *         "message": "Parse Error",
Packit 4b6dd7
 *        }
Packit 4b6dd7
 *       ],
Packit 4b6dd7
 *       "code": 400,
Packit 4b6dd7
 *       "message": "Parse Error"
Packit 4b6dd7
 *      }
Packit 4b6dd7
 *     }
Packit 4b6dd7
 * or:
Packit 4b6dd7
 *     {
Packit 4b6dd7
 *      "error": {
Packit 4b6dd7
 *       "errors": [
Packit 4b6dd7
 *        {
Packit 4b6dd7
 *         "domain": "global",
Packit 4b6dd7
 *         "reason": "required",
Packit 4b6dd7
 *         "message": "Missing end time."
Packit 4b6dd7
 *        }
Packit 4b6dd7
 *       ],
Packit 4b6dd7
 *       "code": 400,
Packit 4b6dd7
 *       "message": "Missing end time."
Packit 4b6dd7
 *      }
Packit 4b6dd7
 *     }
Packit 4b6dd7
 */
Packit 4b6dd7
static void
Packit 4b6dd7
parse_error_response (GDataService *self,
Packit 4b6dd7
                      GDataOperationType operation_type,
Packit 4b6dd7
                      guint status,
Packit 4b6dd7
                      const gchar *reason_phrase,
Packit 4b6dd7
                      const gchar *response_body,
Packit 4b6dd7
                      gint length,
Packit 4b6dd7
                      GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	JsonParser *parser = NULL;  /* owned */
Packit 4b6dd7
	JsonReader *reader = NULL;  /* owned */
Packit 4b6dd7
	gint i;
Packit 4b6dd7
	GError *child_error = NULL;
Packit 4b6dd7
Packit 4b6dd7
	if (response_body == NULL) {
Packit 4b6dd7
		goto parent;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	if (length == -1) {
Packit 4b6dd7
		length = strlen (response_body);
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	parser = json_parser_new ();
Packit 4b6dd7
	if (!json_parser_load_from_data (parser, response_body, length,
Packit 4b6dd7
	                                 &child_error)) {
Packit 4b6dd7
		goto parent;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	reader = json_reader_new (json_parser_get_root (parser));
Packit 4b6dd7
Packit 4b6dd7
	/* Check that the outermost node is an object. */
Packit 4b6dd7
	if (!json_reader_is_object (reader)) {
Packit 4b6dd7
		goto parent;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	/* Grab the ‘error’ member, then its ‘errors’ member. */
Packit 4b6dd7
	if (!json_reader_read_member (reader, "error") ||
Packit 4b6dd7
	    !json_reader_is_object (reader) ||
Packit 4b6dd7
	    !json_reader_read_member (reader, "errors") ||
Packit 4b6dd7
	    !json_reader_is_array (reader)) {
Packit 4b6dd7
		goto parent;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	/* Parse each of the errors. Return the first one, and print out any
Packit 4b6dd7
	 * others. */
Packit 4b6dd7
	for (i = 0; i < json_reader_count_elements (reader); i++) {
Packit 4b6dd7
		const gchar *domain, *reason, *message, *extended_help;
Packit 4b6dd7
		const gchar *location_type, *location;
Packit 4b6dd7
Packit 4b6dd7
		/* Parse the error. */
Packit 4b6dd7
		if (!json_reader_read_element (reader, i) ||
Packit 4b6dd7
		    !json_reader_is_object (reader)) {
Packit 4b6dd7
			goto parent;
Packit 4b6dd7
		}
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "domain");
Packit 4b6dd7
		domain = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "reason");
Packit 4b6dd7
		reason = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "message");
Packit 4b6dd7
		message = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "extendedHelp");
Packit 4b6dd7
		extended_help = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "locationType");
Packit 4b6dd7
		location_type = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		json_reader_read_member (reader, "location");
Packit 4b6dd7
		location = json_reader_get_string_value (reader);
Packit 4b6dd7
		json_reader_end_member (reader);
Packit 4b6dd7
Packit 4b6dd7
		/* End the error element. */
Packit 4b6dd7
		json_reader_end_element (reader);
Packit 4b6dd7
Packit 4b6dd7
		/* Create an error message, but only for the first error */
Packit 4b6dd7
		if (error == NULL || *error == NULL) {
Packit 4b6dd7
			if (g_strcmp0 (domain, "usageLimits") == 0 &&
Packit 4b6dd7
			    g_strcmp0 (reason,
Packit 4b6dd7
			               "dailyLimitExceededUnreg") == 0) {
Packit 4b6dd7
				/* Daily Limit for Unauthenticated Use
Packit 4b6dd7
				 * Exceeded. */
Packit 4b6dd7
				g_set_error (error, GDATA_SERVICE_ERROR,
Packit 4b6dd7
				             GDATA_SERVICE_ERROR_API_QUOTA_EXCEEDED,
Packit 4b6dd7
				             _("You have made too many API "
Packit 4b6dd7
				               "calls recently. Please wait a "
Packit 4b6dd7
				               "few minutes and try again."));
Packit 4b6dd7
			} else if (g_strcmp0 (domain, "global") == 0 &&
Packit 4b6dd7
			           g_strcmp0 (reason, "notFound") == 0) {
Packit 4b6dd7
				/* Calendar not found. */
Packit 4b6dd7
				g_set_error (error, GDATA_SERVICE_ERROR,
Packit 4b6dd7
				             GDATA_SERVICE_ERROR_NOT_FOUND,
Packit 4b6dd7
				             /* Translators: the parameter is an
Packit 4b6dd7
				              * error message returned by the
Packit 4b6dd7
				              * server. */
Packit 4b6dd7
				             _("The requested resource was not found: %s"),
Packit 4b6dd7
				             message);
Packit 4b6dd7
			} else if ((g_strcmp0 (domain, "global") == 0 &&
Packit 4b6dd7
			            g_strcmp0 (reason, "required") == 0) ||
Packit 4b6dd7
			           (g_strcmp0 (domain, "global") == 0 &&
Packit 4b6dd7
			            g_strcmp0 (reason, "conditionNotMet") == 0)) {
Packit 4b6dd7
				/* Client-side protocol error. */
Packit 4b6dd7
				g_set_error (error, GDATA_SERVICE_ERROR,
Packit 4b6dd7
				             GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
Packit 4b6dd7
				             /* Translators: the parameter is an
Packit 4b6dd7
				              * error message returned by the
Packit 4b6dd7
				              * server. */
Packit 4b6dd7
				             _("Invalid request URI or header, "
Packit 4b6dd7
				               "or unsupported nonstandard "
Packit 4b6dd7
				               "parameter: %s"), message);
Packit 4b6dd7
			} else if (g_strcmp0 (domain, "global") == 0 &&
Packit 4b6dd7
			           (g_strcmp0 (reason, "authError") == 0 ||
Packit 4b6dd7
			            g_strcmp0 (reason, "required") == 0)) {
Packit 4b6dd7
				/* Authentication problem */
Packit 4b6dd7
				g_set_error (error, GDATA_SERVICE_ERROR,
Packit 4b6dd7
				             GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
Packit 4b6dd7
				             _("You must be authenticated to "
Packit 4b6dd7
				               "do this."));
Packit 4b6dd7
			} else if (g_strcmp0 (domain, "global") == 0 &&
Packit 4b6dd7
			           g_strcmp0 (reason, "forbidden") == 0) {
Packit 4b6dd7
				g_set_error (error, GDATA_SERVICE_ERROR,
Packit 4b6dd7
				             GDATA_SERVICE_ERROR_FORBIDDEN,
Packit 4b6dd7
				             _("Access was denied by the user "
Packit 4b6dd7
				               "or server."));
Packit 4b6dd7
			} else {
Packit 4b6dd7
				/* Unknown or validation (protocol) error. Fall
Packit 4b6dd7
				 * back to working off the HTTP status code. */
Packit 4b6dd7
				g_warning ("Unknown error code ‘%s’ in domain "
Packit 4b6dd7
				           "‘%s’ received with location type "
Packit 4b6dd7
				           "‘%s’, location ‘%s’, extended help "
Packit 4b6dd7
				           "‘%s’ and message ‘%s’.",
Packit 4b6dd7
				           reason, domain, location_type,
Packit 4b6dd7
				           location, extended_help, message);
Packit 4b6dd7
Packit 4b6dd7
				goto parent;
Packit 4b6dd7
			}
Packit 4b6dd7
		} else {
Packit 4b6dd7
			/* For all errors after the first, log the error in the
Packit 4b6dd7
			 * terminal. */
Packit 4b6dd7
			g_debug ("Error message received in response: domain "
Packit 4b6dd7
			         "‘%s’, reason ‘%s’, extended help ‘%s’, "
Packit 4b6dd7
			         "message ‘%s’, location type ‘%s’, location "
Packit 4b6dd7
			         "‘%s’.",
Packit 4b6dd7
			         domain, reason, extended_help, message,
Packit 4b6dd7
			         location_type, location);
Packit 4b6dd7
		}
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	/* End the ‘errors’ and ‘error’ members. */
Packit 4b6dd7
	json_reader_end_element (reader);
Packit 4b6dd7
	json_reader_end_element (reader);
Packit 4b6dd7
Packit 4b6dd7
	g_clear_object (&reader);
Packit 4b6dd7
	g_clear_object (&parser);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we’ve actually set an error message. */
Packit 4b6dd7
	g_assert (error == NULL || *error != NULL);
Packit 4b6dd7
Packit 4b6dd7
	return;
Packit 4b6dd7
Packit 4b6dd7
parent:
Packit 4b6dd7
	g_clear_object (&reader);
Packit 4b6dd7
	g_clear_object (&parser);
Packit 4b6dd7
Packit 4b6dd7
	/* Chain up to the parent class */
Packit 4b6dd7
	GDATA_SERVICE_CLASS (gdata_calendar_service_parent_class)->parse_error_response (self, operation_type, status, reason_phrase,
Packit 4b6dd7
	                                                                                 response_body, length, error);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static GList *
Packit 4b6dd7
get_authorization_domains (void)
Packit 4b6dd7
{
Packit 4b6dd7
	return g_list_prepend (NULL, get_calendar_authorization_domain ());
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_new:
Packit 4b6dd7
 * @authorizer: (allow-none): a #GDataAuthorizer to authorize the service's requests, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Creates a new #GDataCalendarService using the given #GDataAuthorizer. If @authorizer is %NULL, all requests are made as an unauthenticated user.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: a new #GDataCalendarService, or %NULL; unref with g_object_unref()
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.9.0
Packit 4b6dd7
 */
Packit 4b6dd7
GDataCalendarService *
Packit 4b6dd7
gdata_calendar_service_new (GDataAuthorizer *authorizer)
Packit 4b6dd7
{
Packit 4b6dd7
	g_return_val_if_fail (authorizer == NULL || GDATA_IS_AUTHORIZER (authorizer), NULL);
Packit 4b6dd7
Packit 4b6dd7
	return g_object_new (GDATA_TYPE_CALENDAR_SERVICE,
Packit 4b6dd7
	                     "authorizer", authorizer,
Packit 4b6dd7
	                     NULL);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_get_primary_authorization_domain:
Packit 4b6dd7
 *
Packit 4b6dd7
 * The primary #GDataAuthorizationDomain for interacting with Google Calendar. This will not normally need to be used, as it's used internally
Packit 4b6dd7
 * by the #GDataCalendarService methods. However, if using the plain #GDataService methods to implement custom queries or requests which libgdata
Packit 4b6dd7
 * does not support natively, then this domain may be needed to authorize the requests.
Packit 4b6dd7
 *
Packit 4b6dd7
 * The domain never changes, and is interned so that pointer comparison can be used to differentiate it from other authorization domains.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer none): the service's authorization domain
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.9.0
Packit 4b6dd7
 */
Packit 4b6dd7
GDataAuthorizationDomain *
Packit 4b6dd7
gdata_calendar_service_get_primary_authorization_domain (void)
Packit 4b6dd7
{
Packit 4b6dd7
	return get_calendar_authorization_domain ();
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_all_calendars:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @error: a #GError, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of all calendars from the authenticated account which match the given
Packit 4b6dd7
 * @query. It will return all calendars the user has read access to, including primary, secondary and imported
Packit 4b6dd7
 * calendars.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_service_query().
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer full): a #GDataFeed of query results; unref with g_object_unref()
Packit 4b6dd7
 */
Packit 4b6dd7
GDataFeed *
Packit 4b6dd7
gdata_calendar_service_query_all_calendars (GDataCalendarService *self, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                            GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataFeed *feed;
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
Packit 4b6dd7
	g_return_val_if_fail (query == NULL || GDATA_IS_QUERY (query), NULL);
Packit 4b6dd7
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
Packit 4b6dd7
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
Packit 4b6dd7
		                     _("You must be authenticated to query all calendars."));
Packit 4b6dd7
		return NULL;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.googleapis.com/calendar/v3/users/me/calendarList", NULL);
Packit 4b6dd7
	feed = gdata_service_query (GDATA_SERVICE (self), get_calendar_authorization_domain (), request_uri, query, GDATA_TYPE_CALENDAR_CALENDAR,
Packit 4b6dd7
	                            cancellable, progress_callback, progress_user_data, error);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
Packit 4b6dd7
	return feed;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_all_calendars_async:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
Packit 4b6dd7
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
Packit 4b6dd7
 * @callback: a #GAsyncReadyCallback to call when authentication is finished
Packit 4b6dd7
 * @user_data: (closure): data to pass to the @callback function
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of all calendars from the authenticated account which match the given
Packit 4b6dd7
 * @query. @self and @query are all reffed when this function is called, so can safely be unreffed after
Packit 4b6dd7
 * this function returns.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_calendar_service_query_all_calendars(), which is the synchronous version of
Packit 4b6dd7
 * this function, and gdata_service_query_async(), which is the base asynchronous query function.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.9.1
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_calendar_service_query_all_calendars_async (GDataCalendarService *self, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                                  GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
Packit 4b6dd7
                                                  GDestroyNotify destroy_progress_user_data,
Packit 4b6dd7
                                                  GAsyncReadyCallback callback, gpointer user_data)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
Packit 4b6dd7
	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
Packit 4b6dd7
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit 4b6dd7
	g_return_if_fail (callback != NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_autoptr(GTask) task = NULL;
Packit 4b6dd7
Packit 4b6dd7
		task = g_task_new (self, cancellable, callback, user_data);
Packit 4b6dd7
		g_task_set_source_tag (task, gdata_service_query_async);
Packit 4b6dd7
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
Packit 4b6dd7
		                         _("You must be authenticated to query all calendars."));
Packit 4b6dd7
Packit 4b6dd7
		return;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.googleapis.com/calendar/v3/users/me/calendarList", NULL);
Packit 4b6dd7
	gdata_service_query_async (GDATA_SERVICE (self), get_calendar_authorization_domain (), request_uri, query, GDATA_TYPE_CALENDAR_CALENDAR,
Packit 4b6dd7
	                           cancellable, progress_callback, progress_user_data, destroy_progress_user_data, callback, user_data);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_own_calendars:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @error: a #GError, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of calendars from the authenticated account which match the given
Packit 4b6dd7
 * @query, and the authenticated user owns. (i.e. They have full read/write access to the calendar, as well
Packit 4b6dd7
 * as the ability to set permissions on the calendar.)
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_service_query().
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer full): a #GDataFeed of query results; unref with g_object_unref()
Packit 4b6dd7
 */
Packit 4b6dd7
GDataFeed *
Packit 4b6dd7
gdata_calendar_service_query_own_calendars (GDataCalendarService *self, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                            GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	GDataFeed *feed;
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
Packit 4b6dd7
	g_return_val_if_fail (query == NULL || GDATA_IS_QUERY (query), NULL);
Packit 4b6dd7
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
Packit 4b6dd7
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
Packit 4b6dd7
		                     _("You must be authenticated to query your own calendars."));
Packit 4b6dd7
		return NULL;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=owner", NULL);
Packit 4b6dd7
	feed = gdata_service_query (GDATA_SERVICE (self), get_calendar_authorization_domain (), request_uri, query, GDATA_TYPE_CALENDAR_CALENDAR,
Packit 4b6dd7
	                            cancellable, progress_callback, progress_user_data, error);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
Packit 4b6dd7
	return feed;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_own_calendars_async:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
Packit 4b6dd7
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
Packit 4b6dd7
 * @callback: a #GAsyncReadyCallback to call when authentication is finished
Packit 4b6dd7
 * @user_data: (closure): data to pass to the @callback function
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of calendars from the authenticated account which match the given
Packit 4b6dd7
 * @query, and the authenticated user owns. @self and @query are all reffed when this function is called,
Packit 4b6dd7
 * so can safely be unreffed after this function returns.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_calendar_service_query_own_calendars(), which is the synchronous version of
Packit 4b6dd7
 * this function, and gdata_service_query_async(), which is the base asynchronous query function.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.9.1
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_calendar_service_query_own_calendars_async (GDataCalendarService *self, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                                  GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
Packit 4b6dd7
                                                  GDestroyNotify destroy_progress_user_data,
Packit 4b6dd7
                                                  GAsyncReadyCallback callback, gpointer user_data)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
Packit 4b6dd7
	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
Packit 4b6dd7
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit 4b6dd7
	g_return_if_fail (callback != NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_autoptr(GTask) task = NULL;
Packit 4b6dd7
Packit 4b6dd7
		task = g_task_new (self, cancellable, callback, user_data);
Packit 4b6dd7
		g_task_set_source_tag (task, gdata_service_query_async);
Packit 4b6dd7
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
Packit 4b6dd7
		                         _("You must be authenticated to query your own calendars."));
Packit 4b6dd7
Packit 4b6dd7
		return;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=owner", NULL);
Packit 4b6dd7
	gdata_service_query_async (GDATA_SERVICE (self), get_calendar_authorization_domain (), request_uri, query, GDATA_TYPE_CALENDAR_CALENDAR,
Packit 4b6dd7
	                           cancellable, progress_callback, progress_user_data, destroy_progress_user_data, callback, user_data);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
static gchar *
Packit 4b6dd7
build_events_uri (GDataCalendarCalendar *calendar)
Packit 4b6dd7
{
Packit 4b6dd7
	GString *uri;
Packit 4b6dd7
	const gchar *calendar_id;
Packit 4b6dd7
Packit 4b6dd7
	calendar_id = (calendar != NULL) ? gdata_entry_get_id (GDATA_ENTRY (calendar)) : "default";
Packit 4b6dd7
Packit 4b6dd7
	uri = g_string_new (_gdata_service_get_scheme ());
Packit 4b6dd7
	g_string_append (uri, "://www.googleapis.com/calendar/v3/calendars/");
Packit 4b6dd7
	g_string_append_uri_escaped (uri, calendar_id, NULL, FALSE);
Packit 4b6dd7
	g_string_append (uri, "/events");
Packit 4b6dd7
Packit 4b6dd7
	return g_string_free (uri, FALSE);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_events:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @calendar: a #GDataCalendarCalendar
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @error: a #GError, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of events in the given @calendar, which match @query.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_service_query().
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer full): a #GDataFeed of query results; unref with g_object_unref()
Packit 4b6dd7
 */
Packit 4b6dd7
GDataFeed *
Packit 4b6dd7
gdata_calendar_service_query_events (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                     GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
	GDataFeed *feed;
Packit 4b6dd7
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_CALENDAR (calendar), NULL);
Packit 4b6dd7
	g_return_val_if_fail (query == NULL || GDATA_IS_QUERY (query), NULL);
Packit 4b6dd7
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
Packit 4b6dd7
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
Packit 4b6dd7
		                     _("You must be authenticated to query your own calendars."));
Packit 4b6dd7
		return NULL;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	/* Execute the query. */
Packit 4b6dd7
	request_uri = build_events_uri (calendar);
Packit 4b6dd7
	feed = gdata_service_query (GDATA_SERVICE (self),
Packit 4b6dd7
	                            get_calendar_authorization_domain (),
Packit 4b6dd7
	                            request_uri, query,
Packit 4b6dd7
	                            GDATA_TYPE_CALENDAR_EVENT, cancellable,
Packit 4b6dd7
	                            progress_callback, progress_user_data,
Packit 4b6dd7
	                            error);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
Packit 4b6dd7
	return feed;
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_query_events_async:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @calendar: a #GDataCalendarCalendar
Packit 4b6dd7
 * @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
Packit 4b6dd7
 * @progress_user_data: (closure): data to pass to the @progress_callback function
Packit 4b6dd7
 * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be
Packit 4b6dd7
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
Packit 4b6dd7
 * @callback: a #GAsyncReadyCallback to call when the query is finished
Packit 4b6dd7
 * @user_data: (closure): data to pass to the @callback function
Packit 4b6dd7
 *
Packit 4b6dd7
 * Queries the service to return a list of events in the given @calendar, which match @query. @self, @calendar and @query are all reffed when this
Packit 4b6dd7
 * function is called, so can safely be unreffed after this function returns.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Get the results of the query using gdata_service_query_finish() in the @callback.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_calendar_service_query_events(), which is the synchronous version of this function, and gdata_service_query_async(),
Packit 4b6dd7
 * which is the base asynchronous query function.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.9.1
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_calendar_service_query_events_async (GDataCalendarService *self, GDataCalendarCalendar *calendar, GDataQuery *query, GCancellable *cancellable,
Packit 4b6dd7
                                           GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
Packit 4b6dd7
                                           GDestroyNotify destroy_progress_user_data,
Packit 4b6dd7
                                           GAsyncReadyCallback callback, gpointer user_data)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *request_uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_CALENDAR (calendar));
Packit 4b6dd7
	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
Packit 4b6dd7
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit 4b6dd7
	g_return_if_fail (callback != NULL);
Packit 4b6dd7
Packit 4b6dd7
	/* Ensure we're authenticated first */
Packit 4b6dd7
	if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
Packit 4b6dd7
	                                               get_calendar_authorization_domain ()) == FALSE) {
Packit 4b6dd7
		g_autoptr(GTask) task = NULL;
Packit 4b6dd7
Packit 4b6dd7
		task = g_task_new (self, cancellable, callback, user_data);
Packit 4b6dd7
		g_task_set_source_tag (task, gdata_service_query_async);
Packit 4b6dd7
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
Packit 4b6dd7
		                         _("You must be authenticated to query your own calendars."));
Packit 4b6dd7
Packit 4b6dd7
		return;
Packit 4b6dd7
	}
Packit 4b6dd7
Packit 4b6dd7
	/* Execute the query. */
Packit 4b6dd7
	request_uri = build_events_uri (calendar);
Packit 4b6dd7
	gdata_service_query_async (GDATA_SERVICE (self),
Packit 4b6dd7
	                           get_calendar_authorization_domain (),
Packit 4b6dd7
	                           request_uri, query,
Packit 4b6dd7
	                           GDATA_TYPE_CALENDAR_EVENT, cancellable,
Packit 4b6dd7
	                           progress_callback, progress_user_data,
Packit 4b6dd7
	                           destroy_progress_user_data, callback,
Packit 4b6dd7
	                           user_data);
Packit 4b6dd7
	g_free (request_uri);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_insert_event:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @event: the #GDataCalendarEvent to insert
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @error: a #GError, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Inserts @event by uploading it to the online calendar service.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_service_insert_entry().
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer full): an updated #GDataCalendarEvent, or %NULL; unref with g_object_unref()
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.2.0
Packit 4b6dd7
 * Deprecated: 0.17.2: Use gdata_calendar_service_insert_calendar_event()
Packit 4b6dd7
 *   instead to be able to specify the calendar to add the event to; otherwise
Packit 4b6dd7
 *   the default calendar will be used.
Packit 4b6dd7
 */
Packit 4b6dd7
GDataCalendarEvent *
Packit 4b6dd7
gdata_calendar_service_insert_event (GDataCalendarService *self, GDataCalendarEvent *event, GCancellable *cancellable, GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *uri;
Packit 4b6dd7
	GDataEntry *entry;
Packit 4b6dd7
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_EVENT (event), NULL);
Packit 4b6dd7
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
Packit 4b6dd7
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit 4b6dd7
Packit 4b6dd7
	uri = build_events_uri (NULL);
Packit 4b6dd7
	entry = gdata_service_insert_entry (GDATA_SERVICE (self), get_calendar_authorization_domain (), uri, GDATA_ENTRY (event), cancellable, error);
Packit 4b6dd7
	g_free (uri);
Packit 4b6dd7
Packit 4b6dd7
	return GDATA_CALENDAR_EVENT (entry);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_insert_calendar_event:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @calendar: the #GDataCalendarCalendar to insert the event into
Packit 4b6dd7
 * @event: the #GDataCalendarEvent to insert
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @error: a #GError, or %NULL
Packit 4b6dd7
 *
Packit 4b6dd7
 * Inserts @event by uploading it to the online calendar service, adding it to
Packit 4b6dd7
 * the specified @calendar.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_service_insert_entry().
Packit 4b6dd7
 *
Packit 4b6dd7
 * Return value: (transfer full): an updated #GDataCalendarEvent, or %NULL;
Packit 4b6dd7
 * unref with g_object_unref()
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.17.2
Packit 4b6dd7
 */
Packit 4b6dd7
GDataCalendarEvent *
Packit 4b6dd7
gdata_calendar_service_insert_calendar_event (GDataCalendarService *self,
Packit 4b6dd7
                                              GDataCalendarCalendar *calendar,
Packit 4b6dd7
                                              GDataCalendarEvent *event,
Packit 4b6dd7
                                              GCancellable *cancellable,
Packit 4b6dd7
                                              GError **error)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *uri;
Packit 4b6dd7
	GDataEntry *entry;
Packit 4b6dd7
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_SERVICE (self), NULL);
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_CALENDAR (calendar), NULL);
Packit 4b6dd7
	g_return_val_if_fail (GDATA_IS_CALENDAR_EVENT (event), NULL);
Packit 4b6dd7
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
Packit 4b6dd7
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit 4b6dd7
Packit 4b6dd7
	uri = build_events_uri (calendar);
Packit 4b6dd7
	entry = gdata_service_insert_entry (GDATA_SERVICE (self),
Packit 4b6dd7
	                                    get_calendar_authorization_domain (),
Packit 4b6dd7
	                                    uri, GDATA_ENTRY (event),
Packit 4b6dd7
	                                    cancellable, error);
Packit 4b6dd7
	g_free (uri);
Packit 4b6dd7
Packit 4b6dd7
	return GDATA_CALENDAR_EVENT (entry);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_insert_event_async:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @event: the #GDataCalendarEvent to insert
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @callback: a #GAsyncReadyCallback to call when insertion is finished
Packit 4b6dd7
 * @user_data: (closure): data to pass to the @callback function
Packit 4b6dd7
 *
Packit 4b6dd7
 * Inserts @event by uploading it to the online calendar service. @self and @event are both reffed when this function is called, so can safely be
Packit 4b6dd7
 * unreffed after this function returns.
Packit 4b6dd7
 *
Packit 4b6dd7
 * @callback should call gdata_service_insert_entry_finish() to obtain a #GDataCalendarEvent representing the inserted event and to check for possible
Packit 4b6dd7
 * errors.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_calendar_service_insert_event(), which is the synchronous version of this function, and
Packit 4b6dd7
 * gdata_service_insert_entry_async(), which is the base asynchronous insertion function.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.8.0
Packit 4b6dd7
 * Deprecated: 0.17.2: Use
Packit 4b6dd7
 *   gdata_calendar_service_insert_calendar_event_async() instead to be able to
Packit 4b6dd7
 *   specify the calendar to add the event to; otherwise the default calendar
Packit 4b6dd7
 *   will be used.
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_calendar_service_insert_event_async (GDataCalendarService *self, GDataCalendarEvent *event, GCancellable *cancellable,
Packit 4b6dd7
                                           GAsyncReadyCallback callback, gpointer user_data)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_EVENT (event));
Packit 4b6dd7
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit 4b6dd7
Packit 4b6dd7
	uri = build_events_uri (NULL);
Packit 4b6dd7
	gdata_service_insert_entry_async (GDATA_SERVICE (self), get_calendar_authorization_domain (), uri, GDATA_ENTRY (event), cancellable,
Packit 4b6dd7
	                                  callback, user_data);
Packit 4b6dd7
	g_free (uri);
Packit 4b6dd7
}
Packit 4b6dd7
Packit 4b6dd7
/**
Packit 4b6dd7
 * gdata_calendar_service_insert_calendar_event_async:
Packit 4b6dd7
 * @self: a #GDataCalendarService
Packit 4b6dd7
 * @calendar: the #GDataCalendarCalendar to insert the event into
Packit 4b6dd7
 * @event: the #GDataCalendarEvent to insert
Packit 4b6dd7
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
Packit 4b6dd7
 * @callback: a #GAsyncReadyCallback to call when insertion is finished
Packit 4b6dd7
 * @user_data: (closure): data to pass to the @callback function
Packit 4b6dd7
 *
Packit 4b6dd7
 * Inserts @event by uploading it to the online calendar service, adding it to
Packit 4b6dd7
 * the specified @calendar. @self and @event are both reffed when this function
Packit 4b6dd7
 * is called, so can safely be unreffed after this function returns.
Packit 4b6dd7
 *
Packit 4b6dd7
 * @callback should call gdata_service_insert_entry_finish() to obtain a
Packit 4b6dd7
 * #GDataCalendarEvent representing the inserted event and to check for possible
Packit 4b6dd7
 * errors.
Packit 4b6dd7
 *
Packit 4b6dd7
 * For more details, see gdata_calendar_service_insert_event(), which is the
Packit 4b6dd7
 * synchronous version of this function, and gdata_service_insert_entry_async(),
Packit 4b6dd7
 * which is the base asynchronous insertion function.
Packit 4b6dd7
 *
Packit 4b6dd7
 * Since: 0.17.2
Packit 4b6dd7
 */
Packit 4b6dd7
void
Packit 4b6dd7
gdata_calendar_service_insert_calendar_event_async (GDataCalendarService *self,
Packit 4b6dd7
                                                    GDataCalendarCalendar *calendar,
Packit 4b6dd7
                                                    GDataCalendarEvent *event,
Packit 4b6dd7
                                                    GCancellable *cancellable,
Packit 4b6dd7
                                                    GAsyncReadyCallback callback,
Packit 4b6dd7
                                                    gpointer user_data)
Packit 4b6dd7
{
Packit 4b6dd7
	gchar *uri;
Packit 4b6dd7
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_SERVICE (self));
Packit 4b6dd7
	g_return_if_fail (GDATA_IS_CALENDAR_EVENT (event));
Packit 4b6dd7
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
Packit 4b6dd7
Packit 4b6dd7
	uri = build_events_uri (calendar);
Packit 4b6dd7
	gdata_service_insert_entry_async (GDATA_SERVICE (self),
Packit 4b6dd7
	                                  get_calendar_authorization_domain (),
Packit 4b6dd7
	                                  uri, GDATA_ENTRY (event), cancellable,
Packit 4b6dd7
	                                  callback, user_data);
Packit 4b6dd7
	g_free (uri);
Packit 4b6dd7
}