[librest/gwagner/deprecated: 7/10] lastfm: modernized
- From: Günther Wagner <gwagner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librest/gwagner/deprecated: 7/10] lastfm: modernized
- Date: Tue, 28 Dec 2021 18:40:03 +0000 (UTC)
commit 890d1450f3004ada27ae1038dd2efb009b48f171
Author: Günther Wagner <info gunibert de>
Date: Wed Dec 22 23:16:17 2021 +0100
lastfm: modernized
rest-extras/lastfm-proxy-call.c | 16 ++---
rest-extras/lastfm-proxy-call.h | 6 +-
rest-extras/lastfm-proxy-private.h | 33 ----------
rest-extras/lastfm-proxy.c | 132 +++++++++++++++++++++++--------------
rest-extras/lastfm-proxy.h | 75 ++++++---------------
5 files changed, 109 insertions(+), 153 deletions(-)
---
diff --git a/rest-extras/lastfm-proxy-call.c b/rest-extras/lastfm-proxy-call.c
index 417fa18..dd56715 100644
--- a/rest-extras/lastfm-proxy-call.c
+++ b/rest-extras/lastfm-proxy-call.c
@@ -25,7 +25,7 @@
#include <rest/rest-private.h>
#include <rest/rest-proxy-call.h>
#include "lastfm-proxy-call.h"
-#include "lastfm-proxy-private.h"
+#include "lastfm-proxy.h"
#include "rest/sha1.h"
G_DEFINE_TYPE (LastfmProxyCall, lastfm_proxy_call, REST_TYPE_PROXY_CALL)
@@ -34,23 +34,23 @@ static gboolean
_prepare (RestProxyCall *call, GError **error)
{
LastfmProxy *proxy = NULL;
- LastfmProxyPrivate *priv;
GHashTable *params;
+ const gchar *session_key;
char *s;
g_object_get (call, "proxy", &proxy, NULL);
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
rest_proxy_call_add_params (call,
"method", rest_proxy_call_get_function (call),
- "api_key", priv->api_key,
+ "api_key", lastfm_proxy_get_api_key (proxy),
NULL);
/* Reset function because Lastfm puts the function in the parameters */
rest_proxy_call_set_function (call, NULL);
- if (priv->session_key)
- rest_proxy_call_add_param (call, "sk", priv->session_key);
+ session_key = lastfm_proxy_get_session_key (proxy);
+ if (session_key)
+ rest_proxy_call_add_param (call, "sk", session_key);
params = rest_params_as_string_hash_table (rest_proxy_call_get_params (call));
s = lastfm_proxy_sign (proxy, params);
@@ -75,7 +75,3 @@ static void
lastfm_proxy_call_init (LastfmProxyCall *self)
{
}
-
-#if BUILD_TESTS
-#warning TODO lastfm signature test cases
-#endif
diff --git a/rest-extras/lastfm-proxy-call.h b/rest-extras/lastfm-proxy-call.h
index da4c7ad..20e9b8e 100644
--- a/rest-extras/lastfm-proxy-call.h
+++ b/rest-extras/lastfm-proxy-call.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _LASTFM_PROXY_CALL
-#define _LASTFM_PROXY_CALL
+#pragma once
#include <rest/rest-proxy-call.h>
@@ -44,6 +43,3 @@ struct _LastfmProxyCallClass {
};
G_END_DECLS
-
-#endif /* _LASTFM_PROXY_CALL */
-
diff --git a/rest-extras/lastfm-proxy.c b/rest-extras/lastfm-proxy.c
index b9fc713..7b0dd28 100644
--- a/rest-extras/lastfm-proxy.c
+++ b/rest-extras/lastfm-proxy.c
@@ -26,18 +26,26 @@
#include <rest/rest-proxy.h>
#include <libsoup/soup.h>
#include "lastfm-proxy.h"
-#include "lastfm-proxy-private.h"
#include "lastfm-proxy-call.h"
-G_DEFINE_TYPE (LastfmProxy, lastfm_proxy, REST_TYPE_PROXY)
+typedef struct {
+ char *api_key;
+ char *secret;
+ char *session_key;
+} LastfmProxyPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (LastfmProxy, lastfm_proxy, REST_TYPE_PROXY)
enum {
PROP_0,
PROP_API_KEY,
PROP_SECRET,
PROP_SESSION_KEY,
+ N_PROPS,
};
+static GParamSpec *properties [N_PROPS];
+
GQuark
lastfm_proxy_error_quark (void)
{
@@ -57,10 +65,13 @@ _new_call (RestProxy *proxy)
}
static void
-lastfm_proxy_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+lastfm_proxy_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -81,7 +92,8 @@ static void
lastfm_proxy_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -107,7 +119,8 @@ lastfm_proxy_set_property (GObject *object, guint property_id,
static void
lastfm_proxy_finalize (GObject *object)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
g_free (priv->api_key);
g_free (priv->secret);
@@ -116,18 +129,11 @@ lastfm_proxy_finalize (GObject *object)
G_OBJECT_CLASS (lastfm_proxy_parent_class)->finalize (object);
}
-#ifndef G_PARAM_STATIC_STRINGS
-#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
-#endif
-
static void
lastfm_proxy_class_init (LastfmProxyClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
RestProxyClass *proxy_class = REST_PROXY_CLASS (klass);
- GParamSpec *pspec;
-
- g_type_class_add_private (klass, sizeof (LastfmProxyPrivate));
object_class->get_property = lastfm_proxy_get_property;
object_class->set_property = lastfm_proxy_set_property;
@@ -135,32 +141,38 @@ lastfm_proxy_class_init (LastfmProxyClass *klass)
proxy_class->new_call = _new_call;
- pspec = g_param_spec_string ("api-key", "api-key",
- "The API key", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_API_KEY,
- pspec);
-
- pspec = g_param_spec_string ("secret", "secret",
- "The API key secret", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_SECRET,
- pspec);
-
- pspec = g_param_spec_string ("session-key", "session-key",
- "The session key", NULL,
- G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_SESSION_KEY,
- pspec);
+ properties [PROP_API_KEY] =
+ g_param_spec_string ("api-key",
+ "api-key",
+ "The API key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_SECRET] =
+ g_param_spec_string ("secret",
+ "secret",
+ "The API key secret",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_SESSION_KEY] =
+ g_param_spec_string ("session-key",
+ "session-key",
+ "The session key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
lastfm_proxy_init (LastfmProxy *self)
{
- self->priv = LASTFM_PROXY_GET_PRIVATE (self);
}
RestProxy *
@@ -196,9 +208,12 @@ lastfm_proxy_new_with_session (const char *api_key,
* freed.
*/
const char *
-lastfm_proxy_get_api_key (LastfmProxy *proxy)
+lastfm_proxy_get_api_key (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->api_key;
}
@@ -212,9 +227,12 @@ lastfm_proxy_get_api_key (LastfmProxy *proxy)
* freed.
*/
const char *
-lastfm_proxy_get_secret (LastfmProxy *proxy)
+lastfm_proxy_get_secret (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->secret;
}
@@ -228,9 +246,12 @@ lastfm_proxy_get_secret (LastfmProxy *proxy)
* by #LastfmProxy and should not be freed.
*/
const char *
-lastfm_proxy_get_session_key (LastfmProxy *proxy)
+lastfm_proxy_get_session_key (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->session_key;
}
@@ -242,12 +263,14 @@ lastfm_proxy_get_session_key (LastfmProxy *proxy)
* Set the session key.
*/
void
-lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key)
+lastfm_proxy_set_session_key (LastfmProxy *self,
+ const char *session_key)
{
LastfmProxyPrivate *priv;
- g_return_if_fail (LASTFM_IS_PROXY (proxy));
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ g_return_if_fail (LASTFM_IS_PROXY (self));
+
+ priv = lastfm_proxy_get_instance_private (self);
if (priv->session_key)
g_free (priv->session_key);
@@ -256,17 +279,18 @@ lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key)
}
char *
-lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params)
+lastfm_proxy_sign (LastfmProxy *self,
+ GHashTable *params)
{
LastfmProxyPrivate *priv;
GString *s;
GList *keys;
char *md5;
- g_return_val_if_fail (LASTFM_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
g_return_val_if_fail (params, NULL);
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ priv = lastfm_proxy_get_instance_private (self);
s = g_string_new (NULL);
@@ -295,13 +319,18 @@ lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params)
}
char *
-lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token)
+lastfm_proxy_build_login_url (LastfmProxy *self,
+ const char *token)
{
- g_return_val_if_fail (LASTFM_IS_PROXY (proxy), NULL);
+ LastfmProxyPrivate *priv;
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
g_return_val_if_fail (token, NULL);
+ priv = lastfm_proxy_get_instance_private (self);
+
return g_strdup_printf ("http://www.last.fm/api/auth/?api_key=%s&token=%s",
- proxy->priv->api_key,
+ priv->api_key,
token);
}
@@ -316,7 +345,8 @@ lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token)
* Returns: %TRUE if this response is successful, %FALSE otherwise.
*/
gboolean
-lastfm_proxy_is_successful (RestXmlNode *root, GError **error)
+lastfm_proxy_is_successful (RestXmlNode *root,
+ GError **error)
{
RestXmlNode *node;
diff --git a/rest-extras/lastfm-proxy.h b/rest-extras/lastfm-proxy.h
index 85e612a..b378882 100644
--- a/rest-extras/lastfm-proxy.h
+++ b/rest-extras/lastfm-proxy.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _LASTFM_PROXY
-#define _LASTFM_PROXY
+#pragma once
#include <rest/rest-proxy.h>
#include <rest/rest-xml-parser.h>
@@ -30,65 +29,33 @@ G_BEGIN_DECLS
#define LASTFM_TYPE_PROXY lastfm_proxy_get_type()
-#define LASTFM_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), LASTFM_TYPE_PROXY, LastfmProxy))
+G_DECLARE_DERIVABLE_TYPE (LastfmProxy, lastfm_proxy, LASTFM, PROXY, RestProxy)
-#define LASTFM_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), LASTFM_TYPE_PROXY, LastfmProxyClass))
-
-#define LASTFM_IS_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LASTFM_TYPE_PROXY))
-
-#define LASTFM_IS_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), LASTFM_TYPE_PROXY))
-
-#define LASTFM_PROXY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), LASTFM_TYPE_PROXY, LastfmProxyClass))
-
-typedef struct _LastfmProxyPrivate LastfmProxyPrivate;
-
-/**
- * LastfmProxy:
- *
- * #LastfmProxy has no publicly available members.
- */
-typedef struct {
- RestProxy parent;
- LastfmProxyPrivate *priv;
-} LastfmProxy;
-
-typedef struct {
+struct _LastfmProxyClass {
RestProxyClass parent_class;
+
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
-} LastfmProxyClass;
+};
#define LASTFM_PROXY_ERROR lastfm_proxy_error_quark()
-GType lastfm_proxy_get_type (void);
-
-RestProxy* lastfm_proxy_new (const char *api_key,
- const char *secret);
-
-RestProxy* lastfm_proxy_new_with_session (const char *api_key,
- const char *secret,
- const char *session_key);
-
-const char * lastfm_proxy_get_api_key (LastfmProxy *proxy);
-
-const char * lastfm_proxy_get_secret (LastfmProxy *proxy);
-
-const char * lastfm_proxy_get_session_key (LastfmProxy *proxy);
-
-void lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key);
-
-char * lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params);
-
-char * lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token);
-
-gboolean lastfm_proxy_is_successful (RestXmlNode *root, GError **error);
+RestProxy *lastfm_proxy_new (const char *api_key,
+ const char *secret);
+RestProxy *lastfm_proxy_new_with_session (const char *api_key,
+ const char *secret,
+ const char *session_key);
+const char *lastfm_proxy_get_api_key (LastfmProxy *proxy);
+const char *lastfm_proxy_get_secret (LastfmProxy *proxy);
+const char *lastfm_proxy_get_session_key (LastfmProxy *proxy);
+void lastfm_proxy_set_session_key (LastfmProxy *proxy,
+ const char *session_key);
+char *lastfm_proxy_sign (LastfmProxy *proxy,
+ GHashTable *params);
+char *lastfm_proxy_build_login_url (LastfmProxy *proxy,
+ const char *token);
+gboolean lastfm_proxy_is_successful (RestXmlNode *root,
+ GError **error);
G_END_DECLS
-
-#endif /* _LASTFM_PROXY */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]