| 1 |
/* |
| 2 |
* librest - RESTful web services access |
| 3 |
* Copyright (c) 2010 Intel Corporation. |
| 4 |
* |
| 5 |
* Authors: Rob Bradford <[email protected]> |
| 6 |
* Ross Burton <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or modify it |
| 9 |
* under the terms and conditions of the GNU Lesser General Public License, |
| 10 |
* version 2.1, as published by the Free Software Foundation. |
| 11 |
* |
| 12 |
* This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 13 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 14 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 15 |
* more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public License |
| 18 |
* along with this program; if not, write to the Free Software Foundation, |
| 19 |
* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <string.h> |
| 24 |
#include <libsoup/soup.h> |
| 25 |
#include <rest/rest-private.h> |
| 26 |
#include <rest/rest-proxy-call.h> |
| 27 |
#include "lastfm-proxy-call.h" |
| 28 |
#include "lastfm-proxy.h" |
| 29 |
#include "rest/sha1.h" |
| 30 |
|
| 31 |
G_DEFINE_TYPE (LastfmProxyCall, lastfm_proxy_call, REST_TYPE_PROXY_CALL) |
| 32 |
|
| 33 |
static gboolean |
| 34 |
_prepare (RestProxyCall *call, GError **error) |
| 35 |
{ |
| 36 |
LastfmProxy *proxy = NULL; |
| 37 |
GHashTable *params; |
| 38 |
const gchar *session_key; |
| 39 |
char *s; |
| 40 |
|
| 41 |
g_object_get (call, "proxy", &proxy, NULL); |
| 42 |
|
| 43 |
rest_proxy_call_add_params (call, |
| 44 |
"method", rest_proxy_call_get_function (call), |
| 45 |
"api_key", lastfm_proxy_get_api_key (proxy), |
| 46 |
NULL); |
| 47 |
|
| 48 |
/* Reset function because Lastfm puts the function in the parameters */ |
| 49 |
rest_proxy_call_set_function (call, NULL); |
| 50 |
|
| 51 |
session_key = lastfm_proxy_get_session_key (proxy); |
| 52 |
if (session_key) |
| 53 |
rest_proxy_call_add_param (call, "sk", session_key); |
| 54 |
|
| 55 |
params = rest_params_as_string_hash_table (rest_proxy_call_get_params (call)); |
| 56 |
s = lastfm_proxy_sign (proxy, params); |
| 57 |
g_hash_table_unref (params); |
| 58 |
rest_proxy_call_add_param (call, "api_sig", s); |
| 59 |
g_free (s); |
| 60 |
|
| 61 |
g_object_unref (proxy); |
| 62 |
|
| 63 |
return TRUE; |
| 64 |
} |
| 65 |
|
| 66 |
static void |
| 67 |
lastfm_proxy_call_class_init (LastfmProxyCallClass *klass) |
| 68 |
{ |
| 69 |
RestProxyCallClass *call_class = REST_PROXY_CALL_CLASS (klass); |
| 70 |
|
| 71 |
call_class->prepare = _prepare; |
| 72 |
} |
| 73 |
|
| 74 |
static void |
| 75 |
lastfm_proxy_call_init (LastfmProxyCall *self) |
| 76 |
{ |
| 77 |
} |