summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/rest/rest-sections.txt1
-rw-r--r--rest-extras/flickr-proxy-call.c53
-rw-r--r--rest-extras/flickr-proxy.c18
-rw-r--r--rest-extras/flickr-proxy.h2
4 files changed, 67 insertions, 7 deletions
diff --git a/docs/reference/rest/rest-sections.txt b/docs/reference/rest/rest-sections.txt
index 96ddf9c..52f9f61 100644
--- a/docs/reference/rest/rest-sections.txt
+++ b/docs/reference/rest/rest-sections.txt
@@ -241,6 +241,7 @@ flickr_proxy_set_token
flickr_proxy_sign
flickr_proxy_build_login_url
flickr_proxy_is_successful
+flickr_proxy_new_upload
<SUBSECTION Standard>
FlickrProxyClass
FLICKR_PROXY
diff --git a/rest-extras/flickr-proxy-call.c b/rest-extras/flickr-proxy-call.c
index d923536..ad8b74e 100644
--- a/rest-extras/flickr-proxy-call.c
+++ b/rest-extras/flickr-proxy-call.c
@@ -4,7 +4,7 @@
*
* Authors: Rob Bradford <rob@linux.intel.com>
* Ross Burton <ross@linux.intel.com>
- *
+ *
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
@@ -30,6 +30,33 @@
G_DEFINE_TYPE (FlickrProxyCall, flickr_proxy_call, REST_TYPE_PROXY_CALL)
+#define GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), FLICKR_TYPE_PROXY_CALL, FlickrProxyCallPrivate))
+
+typedef struct {
+ gboolean upload;
+} FlickrProxyCallPrivate;
+
+enum {
+ PROP_0,
+ PROP_UPLOAD
+};
+
+static void
+flickr_proxy_call_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_UPLOAD:
+ GET_PRIVATE (object)->upload = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
static gboolean
_prepare (RestProxyCall *call, GError **error)
{
@@ -43,13 +70,16 @@ _prepare (RestProxyCall *call, GError **error)
priv = FLICKR_PROXY_GET_PRIVATE (proxy);
call_priv = call->priv;
- /* First reset the URL because Flickr puts the function in the parameters */
- call_priv->url = g_strdup ("http://api.flickr.com/services/rest/");
+ /* We need to reset the URL because Flickr puts the function in the parameters */
+
+ if (GET_PRIVATE (call)->upload) {
+ call_priv->url = g_strdup ("http://api.flickr.com/services/upload/");
+ } else {
+ call_priv->url = g_strdup ("http://api.flickr.com/services/rest/");
+ rest_proxy_call_add_param (call, "method", call_priv->function);
+ }
- rest_proxy_call_add_params (call,
- "method", call_priv->function,
- "api_key", priv->api_key,
- NULL);
+ rest_proxy_call_add_param (call, "api_key", priv->api_key);
if (priv->token)
rest_proxy_call_add_param (call, "auth_token", priv->token);
@@ -71,8 +101,17 @@ static void
flickr_proxy_call_class_init (FlickrProxyCallClass *klass)
{
RestProxyCallClass *call_class = REST_PROXY_CALL_CLASS (klass);
+ GObjectClass *obj_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
+
+ g_type_class_add_private (klass, sizeof (FlickrProxyCallPrivate));
call_class->prepare = _prepare;
+ obj_class->set_property = flickr_proxy_call_set_property;
+
+ pspec = g_param_spec_boolean ("upload", "upload", NULL,
+ FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (obj_class, PROP_UPLOAD, pspec);
}
static void
diff --git a/rest-extras/flickr-proxy.c b/rest-extras/flickr-proxy.c
index 9900242..f0adc4a 100644
--- a/rest-extras/flickr-proxy.c
+++ b/rest-extras/flickr-proxy.c
@@ -368,6 +368,24 @@ flickr_proxy_is_successful (RestXmlNode *root, GError **error)
return TRUE;
}
+/**
+ * flickr_proxy_new_upload:
+ * @proxy: a valid #FlickrProxy
+ *
+ * Create a new #RestProxyCall that can be used for uploading.
+ *
+ * See http://www.flickr.com/services/api/upload.api.html for details on
+ * uploading to Flickr.
+ */
+RestProxyCall *
+flickr_proxy_new_upload (FlickrProxy *proxy)
+{
+ return g_object_new (FLICKR_TYPE_PROXY_CALL,
+ "proxy", proxy,
+ "upload", TRUE,
+ NULL);
+}
+
#if BUILD_TESTS
void
test_flickr_error (void)
diff --git a/rest-extras/flickr-proxy.h b/rest-extras/flickr-proxy.h
index 550b864..249c02d 100644
--- a/rest-extras/flickr-proxy.h
+++ b/rest-extras/flickr-proxy.h
@@ -91,6 +91,8 @@ char * flickr_proxy_build_login_url (FlickrProxy *proxy,
gboolean flickr_proxy_is_successful (RestXmlNode *root, GError **error);
+RestProxyCall * flickr_proxy_new_upload (FlickrProxy *proxy);
+
G_END_DECLS
#endif /* _FLICKR_PROXY */