[frogr] Added fsp_session_set_license_* () functions to FspSession.
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Added fsp_session_set_license_* () functions to FspSession.
- Date: Fri, 8 Jul 2011 22:18:51 +0000 (UTC)
commit c58646e4da0b92253030947bd1f9d33902438b11
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Fri Jul 8 23:54:08 2011 +0200
Added fsp_session_set_license_* () functions to FspSession.
This allows to set the license for a given picture.
src/flicksoup/fsp-error.c | 17 ++++++++++
src/flicksoup/fsp-error.h | 5 ++-
src/flicksoup/fsp-parser.c | 30 +++++++++++++++++
src/flicksoup/fsp-parser.h | 6 +++
src/flicksoup/fsp-session.c | 73 +++++++++++++++++++++++++++++++++++++++++++
src/flicksoup/fsp-session.h | 13 ++++++++
6 files changed, 143 insertions(+), 1 deletions(-)
---
diff --git a/src/flicksoup/fsp-error.c b/src/flicksoup/fsp-error.c
index 6f7c6b1..8f75d0f 100644
--- a/src/flicksoup/fsp-error.c
+++ b/src/flicksoup/fsp-error.c
@@ -115,6 +115,19 @@ static const FspError tag_get_list_translations [N_SPECIFIC_ERRORS] = {
FSP_ERROR_UNKNOWN, /* 9 */
};
+static const FspError set_license_translations [N_SPECIFIC_ERRORS] = {
+ FSP_ERROR_UNKNOWN, /* 0 */
+ FSP_ERROR_PHOTO_NOT_FOUND, /* 1 */
+ FSP_ERROR_LICENSE_NOT_FOUND, /* 2 */
+ FSP_ERROR_UNKNOWN, /* 3 */
+ FSP_ERROR_UNKNOWN, /* 4 */
+ FSP_ERROR_UNKNOWN, /* 5 */
+ FSP_ERROR_UNKNOWN, /* 6 */
+ FSP_ERROR_UNKNOWN, /* 7 */
+ FSP_ERROR_UNKNOWN, /* 8 */
+ FSP_ERROR_UNKNOWN, /* 9 */
+};
+
static const FspError general_translations [N_GENERAL_ERRORS] = {
FSP_ERROR_UNKNOWN, /* 10 */
FSP_ERROR_UNKNOWN, /* 11 */
@@ -275,6 +288,10 @@ fsp_error_get_from_response_code (FspErrorMethod method, gint code)
retval = tag_get_list_translations[code];
break;
+ case FSP_ERROR_METHOD_SET_LICENSE:
+ retval = set_license_translations[code];
+ break;
+
default:
retval = FSP_ERROR_UNKNOWN;
}
diff --git a/src/flicksoup/fsp-error.h b/src/flicksoup/fsp-error.h
index 0b0f673..dec15f8 100644
--- a/src/flicksoup/fsp-error.h
+++ b/src/flicksoup/fsp-error.h
@@ -66,6 +66,8 @@ typedef enum {
FSP_ERROR_USER_NOT_FOUND,
+ FSP_ERROR_LICENSE_NOT_FOUND,
+
FSP_ERROR_AUTHENTICATION_FAILED,
FSP_ERROR_NOT_AUTHENTICATED,
FSP_ERROR_NOT_ENOUGH_PERMISSIONS,
@@ -91,7 +93,8 @@ typedef enum {
FSP_ERROR_METHOD_PHOTOSET_ADD_PHOTO,
FSP_ERROR_METHOD_GROUP_GET_LIST,
FSP_ERROR_METHOD_GROUP_ADD_PHOTO,
- FSP_ERROR_METHOD_TAG_GET_LIST
+ FSP_ERROR_METHOD_TAG_GET_LIST,
+ FSP_ERROR_METHOD_SET_LICENSE
} FspErrorMethod;
FspError
diff --git a/src/flicksoup/fsp-parser.c b/src/flicksoup/fsp-parser.c
index 062b610..8550ede 100644
--- a/src/flicksoup/fsp-parser.c
+++ b/src/flicksoup/fsp-parser.c
@@ -94,6 +94,9 @@ _added_to_group_parser (xmlDoc *doc,
static gpointer
_get_tags_list_parser (xmlDoc *doc,
GError **error);
+static gpointer
+_set_license_parser (xmlDoc *doc,
+ GError **error);
static FspDataPhotoInfo *
_get_photo_info_from_node (xmlNode *node);
@@ -277,6 +280,8 @@ _get_error_method_from_parser (gpointer (*body_parser)
error_method = FSP_ERROR_METHOD_GROUP_ADD_PHOTO;
else if (body_parser == _get_tags_list_parser)
error_method = FSP_ERROR_METHOD_TAG_GET_LIST;
+ else if (body_parser == _set_license_parser)
+ error_method = FSP_ERROR_METHOD_SET_LICENSE;
return error_method;
}
@@ -844,6 +849,14 @@ _get_tags_list_parser (xmlDoc *doc,
return tagsList;
}
+static gpointer
+_set_license_parser (xmlDoc *doc,
+ GError **error)
+{
+ /* Dummy parser, as there is no response for this method */
+ return NULL;
+}
+
static FspDataPhotoInfo *
_get_photo_info_from_node (xmlNode *node)
{
@@ -1313,3 +1326,20 @@ fsp_parser_get_tags_list (FspParser *self,
/* No return value for this method */
return tags_list;
}
+
+gpointer
+fsp_parser_set_license (FspParser *self,
+ const gchar *buffer,
+ gulong buf_size,
+ GError **error)
+{
+ g_return_val_if_fail (FSP_IS_PARSER (self), NULL);
+ g_return_val_if_fail (buffer != NULL, NULL);
+
+ /* Process the response */
+ _process_xml_response (self, buffer, buf_size,
+ _set_license_parser, error);
+
+ /* No return value for this method */
+ return GINT_TO_POINTER ((gint)(*error == NULL));
+}
diff --git a/src/flicksoup/fsp-parser.h b/src/flicksoup/fsp-parser.h
index 17fdf0f..ad5fe29 100644
--- a/src/flicksoup/fsp-parser.h
+++ b/src/flicksoup/fsp-parser.h
@@ -133,6 +133,12 @@ fsp_parser_get_tags_list (FspParser *self,
gulong buf_size,
GError **error);
+gpointer
+fsp_parser_set_license (FspParser *self,
+ const gchar *buffer,
+ gulong buf_size,
+ GError **error);
+
G_END_DECLS
#endif
diff --git a/src/flicksoup/fsp-session.c b/src/flicksoup/fsp-session.c
index 2d9d728..d94c0b8 100644
--- a/src/flicksoup/fsp-session.c
+++ b/src/flicksoup/fsp-session.c
@@ -261,6 +261,10 @@ _get_tags_list_soup_session_cb (SoupSession *session,
SoupMessage *msg,
gpointer data);
+static void
+_set_license_soup_session_cb (SoupSession *session,
+ SoupMessage *msg,
+ gpointer data);
/* Private API */
@@ -1248,6 +1252,19 @@ _get_tags_list_soup_session_cb (SoupSession *session,
data);
}
+static void
+_set_license_soup_session_cb (SoupSession *session,
+ SoupMessage *msg,
+ gpointer data)
+{
+ g_assert (SOUP_IS_MESSAGE (msg));
+ g_assert (data != NULL);
+
+ /* Handle message with the right parser */
+ _handle_soup_response (msg,
+ (FspParserFunc) fsp_parser_set_license,
+ data);
+}
/* Public API */
@@ -2091,3 +2108,59 @@ fsp_session_get_tags_list_finish (FspSession *self,
return (GSList*) _finish_async_request (G_OBJECT (self), res,
fsp_session_get_tags_list_async, error);
}
+
+void
+fsp_session_set_license_async (FspSession *self,
+ const gchar *photo_id,
+ FspLicense license,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer data)
+{
+ FspSessionPrivate *priv = NULL;
+ SoupSession *soup_session = NULL;
+ gchar *license_str = NULL;
+ gchar *url = NULL;
+ gchar *signed_query = NULL;
+
+ g_return_if_fail (FSP_IS_SESSION (self));
+ g_return_if_fail (photo_id != NULL);
+
+ /* Build the signed url */
+ priv = self->priv;
+ license_str = g_strdup_printf ("%d", license);
+ signed_query = _get_signed_query (priv->secret,
+ "method", "flickr.photos.licenses.setLicense",
+ "api_key", priv->api_key,
+ "auth_token", priv->token,
+ "photo_id", photo_id,
+ "license_id", license_str,
+ NULL);
+ g_free (license_str);
+ url = g_strdup_printf ("%s/?%s", FLICKR_API_BASE_URL, signed_query);
+ g_free (signed_query);
+
+ /* Perform the async request */
+ soup_session = _get_soup_session (self);
+ _perform_async_request (soup_session, url,
+ _set_license_soup_session_cb, G_OBJECT (self),
+ cancellable, callback, fsp_session_set_license_async, data);
+
+ g_free (url);
+}
+
+gboolean
+fsp_session_set_license_finish (FspSession *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ gpointer result = NULL;
+
+ g_return_val_if_fail (FSP_IS_SESSION (self), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+
+ result = _finish_async_request (G_OBJECT (self), res,
+ fsp_session_set_license_async, error);
+
+ return result ? TRUE : FALSE;
+}
diff --git a/src/flicksoup/fsp-session.h b/src/flicksoup/fsp-session.h
index 783b077..db3e319 100644
--- a/src/flicksoup/fsp-session.h
+++ b/src/flicksoup/fsp-session.h
@@ -228,6 +228,19 @@ fsp_session_get_tags_list_finish (FspSession *self,
GAsyncResult *res,
GError **error);
+void
+fsp_session_set_license_async (FspSession *self,
+ const gchar *photo_id,
+ FspLicense license,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer data);
+
+gboolean
+fsp_session_set_license_finish (FspSession *self,
+ GAsyncResult *res,
+ GError **error);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]