[discident-glib] tests: Add support for looking up EANs



commit 50a957eb86e14c86fd4fdf9a8564fe77eacb0854
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Oct 8 21:04:03 2012 +0200

    tests: Add support for looking up EANs

 discident-glib/test-diglib.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/discident-glib/test-diglib.c b/discident-glib/test-diglib.c
index 7a81332..75b6acd 100644
--- a/discident-glib/test-diglib.c
+++ b/discident-glib/test-diglib.c
@@ -11,6 +11,7 @@
 
 static gboolean option_async = FALSE;
 static gboolean option_file_list = FALSE;
+static gboolean option_lookup_ean = FALSE;
 static guint num_queries = 0;
 static GMainLoop *loop = NULL;
 
@@ -155,6 +156,39 @@ discident_gtin_print (GObject *source_object,
 static char **uris = NULL;
 
 static void
+handle_ean (const char *ean)
+{
+	DiscidentEan *object;
+	char *title, *img_url;
+	GError *error = NULL;
+	gboolean ret;
+
+	object = discident_ean_new ();
+	if (discident_ean_login (object, &error) == FALSE) {
+		g_message ("Failed to login: %s", error->message);
+		g_object_unref (object);
+		return;
+	}
+
+	ret = discident_ean_lookup (object, ean, &title, &img_url, &error);
+	if (ret == FALSE) {
+		g_message ("discident_ean_lookup() failed with: %s", error->message);
+		g_error_free (error);
+		g_object_unref (object);
+		return;
+	}
+	g_print ("EAN: %s\n", ean);
+	g_print ("Title: %s\n", title);
+	g_print ("Thumbnail: %s\n", img_url);
+	g_print ("\n");
+
+	g_free (title);
+	g_free (img_url);
+
+	g_object_unref (object);
+}
+
+static void
 handle_gtin_uri (const char *uri)
 {
 	GFile *file;
@@ -201,6 +235,7 @@ int main (int argc, char **argv)
 	const GOptionEntry entries[] = {
 		{ "async", 'a', 0, G_OPTION_ARG_NONE, &option_async, "Use the async API", NULL },
 		{ "file-list", 'f', 0, G_OPTION_ARG_NONE, &option_file_list, "Show the file list instead of the GTIN", NULL },
+		{ "ean", 'e', 0, G_OPTION_ARG_NONE, &option_lookup_ean, "Look up an EAN rather than a disc", NULL },
 		{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris, NULL, "[URI...]" },
 		{ NULL }
 	};
@@ -230,7 +265,10 @@ int main (int argc, char **argv)
 	}
 
 	for (i = 0; uris[i] != NULL; i++) {
-		handle_gtin_uri (uris[i]);
+		if (option_lookup_ean == FALSE)
+			handle_gtin_uri (uris[i]);
+		else
+			handle_ean (uris[i]);
 	}
 
 	if (option_async) {



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