[discident-glib] test: Add ability to pass parameters for EAN lookups



commit 9cc26a2f2f9085d74b44706dcb92dc6b0a311add
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Apr 27 19:43:33 2013 +0200

    test: Add ability to pass parameters for EAN lookups
    
    So that we can test Amazon lookups.

 discident-glib/test-diglib.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/discident-glib/test-diglib.c b/discident-glib/test-diglib.c
index eda0cc4..9d721d1 100644
--- a/discident-glib/test-diglib.c
+++ b/discident-glib/test-diglib.c
@@ -14,6 +14,9 @@ static gboolean option_async = FALSE;
 static gboolean option_file_list = FALSE;
 static gboolean option_lookup_ean = FALSE;
 static char *ean_service = NULL;
+static char *access_key = NULL;
+static char *private_key = NULL;
+static char *associate_tag = NULL;
 static guint num_queries = 0;
 static GMainLoop *loop = NULL;
 
@@ -340,6 +343,24 @@ bail:
                g_main_loop_quit (loop);
 }
 
+static GHashTable *
+create_params (void)
+{
+       GHashTable *params;
+
+       if (!access_key &&
+           !private_key &&
+           !associate_tag)
+               return NULL;
+
+       params = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_insert (params, DISCIDENT_PARAM_ACCESS_KEY, access_key);
+       g_hash_table_insert (params, DISCIDENT_PARAM_PRIVATE_KEY, private_key);
+       g_hash_table_insert (params, DISCIDENT_PARAM_ASSOCIATE_TAG, associate_tag);
+
+       return params;
+}
+
 static void
 handle_ean (const char *ean)
 {
@@ -347,8 +368,12 @@ handle_ean (const char *ean)
        char *title, *img_url;
        GError *error = NULL;
        gboolean ret;
+       GHashTable *params;
 
-       object = discident_ean_new (ean_service);
+       params = create_params ();
+       object = discident_ean_new_full (ean_service, params);
+       if (params)
+               g_hash_table_destroy (params);
 
        if (!option_async) {
                ret = discident_ean_lookup_sync (object, ean, &title, &img_url, &error);
@@ -422,6 +447,9 @@ int main (int argc, char **argv)
                { "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 },
                { "ean-service", 's', 0, G_OPTION_ARG_STRING, &ean_service, "EAN lookup service to use", NULL 
},
+               { "access-key", 0, 0, G_OPTION_ARG_STRING, &access_key, "Access key", NULL },
+               { "private-key", 0, 0, G_OPTION_ARG_STRING, &private_key, "Private key", NULL },
+               { "associate-tag", 0, 0, G_OPTION_ARG_STRING, &associate_tag, "Associate Tag", NULL },
                { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris, NULL, "[URI...]" },
                { NULL }
        };


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