+/*
+ * watc_provider.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 Simón Pena <bulfaiter@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#include "watc_provider.h"
+#include "string.h"
+
+int watc_has_stingers(const char *name) {
+
+ RestProxy *proxy;
+ RestProxyCall *call;
+ const gchar *response;
+ gssize len;
+
+ /* Initialization: most probably done in the invoker */
+ g_thread_init(NULL);
+ g_type_init();
+
+ /* Provider initialization, should be refactored. Maybe it can be reused between calls */
+ proxy = rest_proxy_new(WATC_SERVICE_URL, FALSE);
+ call = rest_proxy_new_call(proxy);
+
+ /* Adding params to the call: check http://en.wikipedia.org/w/api.php
+ *
+ * There's only one variable param: the movie name
+ * */
+ rest_proxy_call_add_params(call, "action", "opensearch", "search", name,
+ NULL);
+
+ /* The actual call */
+ rest_proxy_call_run(call, NULL, NULL);
+
+ /* Retrieving the results: should be done in/should receive a callback function */
+ response = rest_proxy_call_get_payload(call);
+ len = rest_proxy_call_get_payload_length(call);
+
+ /* Process the output: must be checked whether the response has a * in the expected result
+ * or not */
+ write(1, response, len);
+ printf("\n");
+
+ /* Object disposal, should be refactored. */
+ g_object_unref(call);
+ g_object_unref(proxy);
+
+ return parse_response(response);
+}
+
+/* Ad-hoc implementation. Will give a wrong result if the query had more than one result,
+ * if the title has a * in its text, or if the conventions used in what's after the credits vary.
+ */
+int parse_response(const gchar *response) {
+
+ return (strpbrk(response, "*") != NULL);
+}