[gthumb] started work on a photobucket consumer
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] started work on a photobucket consumer
- Date: Wed, 19 May 2010 18:53:22 +0000 (UTC)
commit f326f326b6d60a503fa1fcc0bcc1900aecd32c93
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Apr 21 21:24:14 2010 +0200
started work on a photobucket consumer
extensions/photobucket/dlg-export-to-photobucket.c | 11 --
extensions/photobucket/photobucket-service.c | 158 ++++++++++++++++++++
2 files changed, 158 insertions(+), 11 deletions(-)
---
diff --git a/extensions/photobucket/dlg-export-to-photobucket.c b/extensions/photobucket/dlg-export-to-photobucket.c
index 601ad00..1929c44 100644
--- a/extensions/photobucket/dlg-export-to-photobucket.c
+++ b/extensions/photobucket/dlg-export-to-photobucket.c
@@ -45,17 +45,6 @@ enum {
};
-static OAuthServer photobucket_server = {
- "PhotoBucket",
- "http://www.photobucket.com",
- "http://www.flickr.com/services/auth/",
- "http://api.flickr.com/services/rest",
- "http://api.flickr.com/services/upload/",
- "8960706ee7f4151e893b11837e9c24ce",
- "1ff8d1e45c873423"
-};
-
-
typedef struct {
GthBrowser *browser;
GthFileData *location;
diff --git a/extensions/photobucket/photobucket-service.c b/extensions/photobucket/photobucket-service.c
index 82680fe..8b5d71e 100644
--- a/extensions/photobucket/photobucket-service.c
+++ b/extensions/photobucket/photobucket-service.c
@@ -27,6 +27,164 @@
#include "photobucket-service.h"
+/* -- photobucket_consumer -- */
+
+
+static gboolean
+photobucket_utils_parse_response (SoupBuffer *body,
+ DomDocument **doc_p,
+ GError **error)
+{
+ DomDocument *doc;
+ DomElement *node;
+
+ doc = dom_document_new ();
+ if (! dom_document_load (doc, body->data, body->length, error)) {
+ g_object_unref (doc);
+ return FALSE;
+ }
+
+ for (node = DOM_ELEMENT (doc)->first_child; node; node = node->next_sibling) {
+ if (g_strcmp0 (node->tag_name, "error_response") == 0) {
+ DomElement *child;
+ int code = 0;
+ const char *message = NULL;
+
+ for (child = node->first_child; child; child = child->next_sibling) {
+ if (g_strcmp0 (child->tag_name, "error_code") == 0) {
+ code = atoi (dom_element_get_inner_text (child));
+ }
+ else if (g_strcmp0 (child->tag_name, "error_msg") == 0) {
+ message = dom_element_get_inner_text (child);
+ }
+ }
+
+ *error = g_error_new_literal (FACEBOOK_CONNECTION_ERROR,
+ code,
+ message);
+
+ g_object_unref (doc);
+ return FALSE;
+ }
+ }
+
+ *doc_p = doc;
+
+ return TRUE;
+}
+
+
+static void
+photobucket_login_request_response (OAuthConnection *self,
+ SoupMessage *msg,
+ SoupBuffer *body,
+ GSimpleAsyncResult *result)
+{
+ DomDocument *doc = NULL;
+ GError *error = NULL;
+
+ if (photobucket_utils_parse_response (body, &doc, &error)) {
+ /*OAuthAccount *account;
+ char *username;*/
+
+ /* FIXME: set the connection token and token_secret from the response */
+
+ /*account = oauth_account_new ();
+ oauth_account_set_username (account, username);
+ oauth_account_set_token (account, oauth_connection_get_token (self));
+ oauth_account_set_token_secret (account, oauth_connection_get_token_secret (self));*/
+
+ char *token;
+ char *token_secret;
+
+ token = NULL;
+ token_secret = NULL;
+
+ /* FIXME: parse the body and set the token */
+ /*oauth_connection_set_token (self, token, token_secret);*/
+
+ if ((token == NULL) || (token_secret == NULL)) {
+ error = g_error_new_literal (OAUTH_CONNECTION_ERROR, 0, _("Unknown error"));
+ g_simple_async_result_set_from_error (result, error);
+ }
+ else
+ g_simple_async_result_set_op_res_gboolean (self->priv->result, TRUE);
+
+ g_object_unref (doc);
+ }
+ else
+ g_simple_async_result_set_from_error (result, error);
+}
+
+
+static char *
+phoyobucket_get_login_link (OAuthConnection *self)
+{
+ char *token;
+ char *uri;
+
+ token = soup_uri_encode (oauth_connection_get_token (self), NULL);
+ uri = g_strconcat ("http://photobucket.com/apilogin/login?oauth_token=", token, NULL);
+
+ g_free (token);
+
+ return uri;
+}
+
+
+static void
+photobucket_get_access_token_response (OAuthConnection *self,
+ SoupMessage *msg,
+ SoupBuffer *body,
+ GSimpleAsyncResult *result)
+{
+ DomDocument *doc = NULL;
+ GError *error = NULL;
+
+ if (photobucket_utils_parse_response (body, &doc, &error)) {
+ OAuthAccount *account = NULL;
+ char *username;
+
+ /* FIXME: parse the body and set the account */
+
+ /*account = oauth_account_new ();
+ oauth_account_set_username (account, username);
+ oauth_account_set_token (account, oauth_connection_get_token (self));
+ oauth_account_set_token_secret (account, oauth_connection_get_token_secret (self));*/
+
+ /*oauth_connection_set_token (self, token, token_secret);*/
+
+ if (account == NULL) {
+ error = g_error_new_literal (OAUTH_CONNECTION_ERROR, 0, _("Unknown error"));
+ g_simple_async_result_set_from_error (result, error);
+ }
+ else
+ g_simple_async_result_set_op_res_gpointer (self->priv->result, account, g_object_unref);
+
+ g_object_unref (doc);
+ }
+ else
+ g_simple_async_result_set_from_error (result, error);
+}
+
+
+static OAuthConsumer photobucket_consumer = {
+ "PhotoBucket",
+ "http://www.photobucket.com",
+ "http",
+ "8960706ee7f4151e893b11837e9c24ce",
+ "1ff8d1e45c873423",
+ "http://api.photobucket.com/login/request",
+ photobucket_login_request_response,
+ phoyobucket_get_login_link,
+ "http://api.photobucket.com/login/access",
+ photobucket_get_access_token_response,
+};
+
+
+/* -- photobucket_service -- */
+
+
struct _PhotobucketServicePrivate
{
PhotobucketConnection *conn;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]