157
157
#include "gdata-private.h"
158
158
#include "gdata-query.h"
160
static GList *get_authorization_domains (void);
162
_GDATA_DEFINE_AUTHORIZATION_DOMAIN (contacts, "cp", "https://www.google.com/m8/feeds/")
160
163
G_DEFINE_TYPE_WITH_CODE (GDataContactsService, gdata_contacts_service, GDATA_TYPE_SERVICE,
161
164
G_IMPLEMENT_INTERFACE (GDATA_TYPE_BATCHABLE, NULL))
174
177
/* Nothing to see here */
181
get_authorization_domains (void)
183
return g_list_prepend (NULL, get_contacts_authorization_domain ());
178
187
* gdata_contacts_service_new:
179
* @client_id: your application's client ID
181
* Creates a new #GDataContactsService. The @client_id must be unique for your application, and as registered with Google.
183
* Return value: a new #GDataContactsService, or %NULL
188
* @authorizer: (allow-none): a #GDataAuthorizer to authorize the service's requests, or %NULL
190
* Creates a new #GDataContactsService using the given #GDataAuthorizer. If @authorizer is %NULL, all requests are made as an unauthenticated user.
192
* Return value: a new #GDataContactsService, or %NULL; unref with g_object_unref()
187
196
GDataContactsService *
188
gdata_contacts_service_new (const gchar *client_id)
197
gdata_contacts_service_new (GDataAuthorizer *authorizer)
190
g_return_val_if_fail (client_id != NULL, NULL);
199
g_return_val_if_fail (authorizer == NULL || GDATA_IS_AUTHORIZER (authorizer), NULL);
192
201
return g_object_new (GDATA_TYPE_CONTACTS_SERVICE,
193
"client-id", client_id,
202
"authorizer", authorizer,
207
* gdata_contacts_service_get_primary_authorization_domain:
209
* The primary #GDataAuthorizationDomain for interacting with Google Contacts. This will not normally need to be used, as it's used internally
210
* by the #GDataContactsService methods. However, if using the plain #GDataService methods to implement custom queries or requests which libgdata
211
* does not support natively, then this domain may be needed to authorize the requests.
213
* The domain never changes, and is interned so that pointer comparison can be used to differentiate it from other authorization domains.
215
* Return value: (transfer none): the service's authorization domain
219
GDataAuthorizationDomain *
220
gdata_contacts_service_get_primary_authorization_domain (void)
222
return get_contacts_authorization_domain ();
198
226
* gdata_contacts_service_query_contacts:
199
227
* @self: a #GDataContactsService
200
228
* @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
201
* @cancellable: optional #GCancellable object, or %NULL
202
* @progress_callback: (scope call): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
229
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
230
* @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
203
231
* @progress_user_data: (closure): data to pass to the @progress_callback function
204
232
* @error: a #GError, or %NULL
224
252
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
226
254
/* Ensure we're authenticated first */
227
if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
255
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
256
get_contacts_authorization_domain ()) == FALSE) {
228
257
g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
229
258
_("You must be authenticated to query contacts."));
233
262
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/contacts/default/full", NULL);
234
feed = gdata_service_query (GDATA_SERVICE (self), request_uri, GDATA_QUERY (query),
263
feed = gdata_service_query (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_QUERY (query),
235
264
GDATA_TYPE_CONTACTS_CONTACT, cancellable, progress_callback, progress_user_data, error);
236
265
g_free (request_uri);
242
* gdata_contacts_service_query_contacts_async: (skip)
271
* gdata_contacts_service_query_contacts_async:
243
272
* @self: a #GDataContactsService
244
273
* @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
245
* @cancellable: optional #GCancellable object, or %NULL
246
* @progress_callback: a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
274
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
275
* @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
247
276
* @progress_user_data: (closure): data to pass to the @progress_callback function
277
* @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
278
* called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
248
279
* @callback: a #GAsyncReadyCallback to call when the query is finished
249
280
* @user_data: (closure): data to pass to the @callback function
254
285
* For more details, see gdata_contacts_service_query_contacts(), which is the synchronous version of this function,
255
286
* and gdata_service_query_async(), which is the base asynchronous query function.
260
291
gdata_contacts_service_query_contacts_async (GDataContactsService *self, GDataQuery *query, GCancellable *cancellable,
261
292
GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
293
GDestroyNotify destroy_progress_user_data,
262
294
GAsyncReadyCallback callback, gpointer user_data)
264
296
gchar *request_uri;
269
301
g_return_if_fail (callback != NULL);
271
303
/* Ensure we're authenticated first */
272
if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
273
g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data,
274
GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
275
_("You must be authenticated to query contacts."));
304
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
305
get_contacts_authorization_domain ()) == FALSE) {
306
GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, gdata_service_query_async);
307
g_simple_async_result_set_error (result, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
308
_("You must be authenticated to query contacts."));
309
g_simple_async_result_complete_in_idle (result);
310
g_object_unref (result);
279
315
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/contacts/default/full", NULL);
280
gdata_service_query_async (GDATA_SERVICE (self), request_uri, GDATA_QUERY (query),
281
GDATA_TYPE_CONTACTS_CONTACT, cancellable, progress_callback, progress_user_data, callback, user_data);
316
gdata_service_query_async (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_QUERY (query),
317
GDATA_TYPE_CONTACTS_CONTACT, cancellable, progress_callback, progress_user_data,
318
destroy_progress_user_data, callback, user_data);
282
319
g_free (request_uri);
286
323
* gdata_contacts_service_insert_contact:
287
324
* @self: a #GDataContactsService
288
325
* @contact: the #GDataContactsContact to insert
289
* @cancellable: optional #GCancellable object, or %NULL
326
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
290
327
* @error: a #GError, or %NULL
292
329
* Inserts @contact by uploading it to the online contacts service.
309
346
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
311
348
uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/contacts/default/full", NULL);
312
entry = gdata_service_insert_entry (GDATA_SERVICE (self), uri, GDATA_ENTRY (contact), cancellable, error);
349
entry = gdata_service_insert_entry (GDATA_SERVICE (self), get_contacts_authorization_domain (), uri, GDATA_ENTRY (contact), cancellable,
315
353
return GDATA_CONTACTS_CONTACT (entry);
319
357
* gdata_contacts_service_insert_contact_async:
320
358
* @self: a #GDataContactsService
321
359
* @contact: the #GDataContactsContact to insert
322
* @cancellable: optional #GCancellable object, or %NULL
360
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
323
361
* @callback: a #GAsyncReadyCallback to call when insertion is finished
324
362
* @user_data: (closure): data to pass to the @callback function
345
383
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
347
385
uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/contacts/default/full", NULL);
348
gdata_service_insert_entry_async (GDATA_SERVICE (self), uri, GDATA_ENTRY (contact), cancellable, callback, user_data);
386
gdata_service_insert_entry_async (GDATA_SERVICE (self), get_contacts_authorization_domain (), uri, GDATA_ENTRY (contact), cancellable,
387
callback, user_data);
353
392
* gdata_contacts_service_query_groups:
354
393
* @self: a #GDataContactsService
355
394
* @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
356
* @cancellable: optional #GCancellable object, or %NULL
357
* @progress_callback: (scope call): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
395
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
396
* @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
358
397
* @progress_user_data: (closure): data to pass to the @progress_callback function
359
398
* @error: a #GError, or %NULL
379
418
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
381
420
/* Ensure we're authenticated first */
382
if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
421
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
422
get_contacts_authorization_domain ()) == FALSE) {
383
423
g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
384
424
_("You must be authenticated to query contact groups."));
388
428
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/groups/default/full", NULL);
389
feed = gdata_service_query (GDATA_SERVICE (self), request_uri, GDATA_QUERY (query),
429
feed = gdata_service_query (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_QUERY (query),
390
430
GDATA_TYPE_CONTACTS_GROUP, cancellable, progress_callback, progress_user_data, error);
391
431
g_free (request_uri);
397
* gdata_contacts_service_query_groups_async: (skip)
437
* gdata_contacts_service_query_groups_async:
398
438
* @self: a #GDataContactsService
399
439
* @query: (allow-none): a #GDataQuery with the query parameters, or %NULL
400
* @cancellable: optional #GCancellable object, or %NULL
401
* @progress_callback: a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
440
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
441
* @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when an entry is loaded, or %NULL
402
442
* @progress_user_data: (closure): data to pass to the @progress_callback function
443
* @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
444
* called with @progress_user_data as a parameter and can be used to free any memory allocated for it.
403
445
* @callback: a #GAsyncReadyCallback to call when the query is finished
404
446
* @user_data: (closure): data to pass to the @callback function
409
451
* For more details, see gdata_contacts_service_query_groups(), which is the synchronous version of this function, and gdata_service_query_async(),
410
452
* which is the base asynchronous query function.
415
457
gdata_contacts_service_query_groups_async (GDataContactsService *self, GDataQuery *query, GCancellable *cancellable,
416
458
GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
459
GDestroyNotify destroy_progress_user_data,
417
460
GAsyncReadyCallback callback, gpointer user_data)
419
462
gchar *request_uri;
424
467
g_return_if_fail (callback != NULL);
426
469
/* Ensure we're authenticated first */
427
if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
428
g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data,
429
GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
430
_("You must be authenticated to query contact groups."));
470
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
471
get_contacts_authorization_domain ()) == FALSE) {
472
GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, gdata_service_query_async);
473
g_simple_async_result_set_error (result, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED, "%s",
474
_("You must be authenticated to query contact groups."));
475
g_simple_async_result_complete_in_idle (result);
476
g_object_unref (result);
434
481
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/groups/default/full", NULL);
435
gdata_service_query_async (GDATA_SERVICE (self), request_uri, GDATA_QUERY (query),
436
GDATA_TYPE_CONTACTS_GROUP, cancellable, progress_callback, progress_user_data, callback, user_data);
482
gdata_service_query_async (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_QUERY (query),
483
GDATA_TYPE_CONTACTS_GROUP, cancellable, progress_callback, progress_user_data,
484
destroy_progress_user_data, callback, user_data);
437
485
g_free (request_uri);
441
489
* gdata_contacts_service_insert_group:
442
490
* @self: a #GDataContactsService
443
491
* @group: a #GDataContactsGroup to create on the server
444
* @cancellable: optional #GCancellable object, or %NULL
492
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
445
493
* @error: a #GError, or %NULL
447
495
* Inserts a new contact group described by @group. The user must be authenticated to use this function.
470
if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
518
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
519
get_contacts_authorization_domain ()) == FALSE) {
471
520
g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
472
521
_("You must be authenticated to insert a group."));
476
525
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/groups/default/full", NULL);
477
new_group = gdata_service_insert_entry (GDATA_SERVICE (self), request_uri, GDATA_ENTRY (group), cancellable, error);
526
new_group = gdata_service_insert_entry (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_ENTRY (group),
478
528
g_free (request_uri);
480
530
return GDATA_CONTACTS_GROUP (new_group);
484
534
* gdata_contacts_service_insert_group_async:
485
535
* @self: a #GDataContactsService
486
536
* @group: the #GDataContactsGroup to insert
487
* @cancellable: optional #GCancellable object, or %NULL
537
* @cancellable: (allow-none): optional #GCancellable object, or %NULL
488
538
* @callback: a #GAsyncReadyCallback to call when insertion is finished
489
539
* @user_data: (closure): data to pass to the @callback function
510
560
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
512
562
request_uri = g_strconcat (_gdata_service_get_scheme (), "://www.google.com/m8/feeds/groups/default/full", NULL);
513
gdata_service_insert_entry_async (GDATA_SERVICE (self), request_uri, GDATA_ENTRY (group), cancellable, callback, user_data);
563
gdata_service_insert_entry_async (GDATA_SERVICE (self), get_contacts_authorization_domain (), request_uri, GDATA_ENTRY (group), cancellable,
564
callback, user_data);
514
565
g_free (request_uri);