4 * This file is part of maevies
5 * Copyright (C) 2009 Simón Pena <spenap@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 #include "tmdb_movie.h"
21 void query_tmdb(const gchar *name);
23 static void parse_child_element(gpointer key, gpointer element, gpointer data);
25 RestXmlNode *get_xml(RestProxyCall *call);
27 TMDBMovie *tmdb_get_info(const gchar *name) {
29 TMDBMovie *movie = g_new0(TMDBMovie, 1);
32 movie->released = g_date_new_dmy(1, G_DATE_FEBRUARY, 2009);
39 void query_tmdb(const gchar *name) {
44 const gchar *response;
48 /* Provider initialization, should be refactored. Maybe it can be reused between calls */
49 proxy = rest_proxy_new(TMDB_SERVICE_URL, FALSE);
50 call = rest_proxy_new_call(proxy);
52 /* Generate the function string */
53 tmdb_function = g_strdup_printf("%s/%s/%s/%s/%s", TMDB_SEARCH_METHOD,
54 TMDB_LANGUAGE, TMDB_FORMAT, TMDB_API_KEY, name);
56 rest_proxy_call_set_function(call, tmdb_function);
59 rest_proxy_call_run(call, NULL, NULL);
63 /* Object disposal, should be refactored. */
65 g_object_unref(proxy);
68 RestXmlNode *get_xml(RestProxyCall *call) {
69 RestXmlParser *parser;
73 parser = rest_xml_parser_new();
75 root = rest_xml_parser_parse_from_data(parser, rest_proxy_call_get_payload(
76 call), rest_proxy_call_get_payload_length(call));
78 g_hash_table_foreach(root->children, (GHFunc) parse_child_element, NULL);
80 g_object_unref(parser);
85 static void parse_child_element(gpointer key, gpointer element, gpointer data) {
87 RestXmlNode *node = (RestXmlNode*) element;
90 if (g_hash_table_size(node->children) == 0) {
91 g_print("%s", node->content);
94 g_hash_table_foreach(node->children, (GHFunc) parse_child_element, NULL);