[PATCH 04/18] flickr: Add helper function to get Flickr's login link



This login link is used to authorise application to access Flickr's account.
---
 src/flickr/grl-flickr-auth.c |   44 ++++++++++++++++++++++++++++++++++++++++++
 src/flickr/grl-flickr-auth.h |   12 +++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/flickr/grl-flickr-auth.c b/src/flickr/grl-flickr-auth.c
index 5a34c60..40a3104 100644
--- a/src/flickr/grl-flickr-auth.c
+++ b/src/flickr/grl-flickr-auth.c
@@ -133,3 +133,47 @@ grl_flickr_get_frob (const gchar *api_key,
 
   return frob;
 }
+
+gchar *
+grl_flickr_get_login_link (const gchar *api_key,
+                           const gchar *secret,
+                           const gchar *frob,
+                           FlickrPerm perm)
+{
+  gchar *api_sig;
+  gchar *strperm;
+  gchar *url;
+
+  switch (perm) {
+  case FLICKR_PERM_READ:
+    strperm = "read";
+    break;
+  case FLICKR_PERM_WRITE:
+    strperm = "write";
+    break;
+  case FLICKR_PERM_DELETE:
+    strperm = "delete";
+    break;
+  default:
+    g_warning ("Unknown perm");
+    return NULL;
+  }
+
+  api_sig = get_api_sig (secret,
+                         "api_key", api_key,
+                         "frob", frob,
+                         "perms", strperm,
+                         NULL);
+  url = g_strdup_printf (FLICKR_AUTH
+                         "api_key=%s&"
+                         "perms=%s&"
+                         "frob=%s&"
+                         "api_sig=%s",
+                         api_key,
+                         strperm,
+                         frob,
+                         api_sig);
+  g_free (api_sig);
+
+  return url;
+}
diff --git a/src/flickr/grl-flickr-auth.h b/src/flickr/grl-flickr-auth.h
index 8ec238b..6c32452 100644
--- a/src/flickr/grl-flickr-auth.h
+++ b/src/flickr/grl-flickr-auth.h
@@ -27,6 +27,18 @@
 
 #include <glib.h>
 
+typedef enum {
+  FLICKR_PERM_READ,
+  FLICKR_PERM_WRITE,
+  FLICKR_PERM_DELETE
+} FlickrPerm;
+
 gchar * grl_flickr_get_frob (const gchar *api_key,
                              const gchar *secret);
+
+gchar *grl_flickr_get_login_link (const gchar *api_key,
+                                  const gchar *secret,
+                                  const gchar *frob,
+                                  FlickrPerm perm);
+
 #endif /* _GRL_FLICKR_AUTH_SOURCE_H_ */
-- 
1.7.0.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]