[discident-glib] test: Allow loading Amazon parameters from config file
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [discident-glib] test: Allow loading Amazon parameters from config file
- Date: Mon, 21 Dec 2015 22:13:53 +0000 (UTC)
commit 53ba52df2ab24961acfaf37af95c4f2fad94a9fe
Author: Bastien Nocera <hadess hadess net>
Date: Mon Dec 21 20:26:41 2015 +0100
test: Allow loading Amazon parameters from config file
In ~/.config/discident-glib/amazon-config.ini :
[amz]
access-key=AKEXAMPLE
private-key=NANANANANANABatMan
associate-tag=example-01
If requests fail for you, verify that your credentials are correct in
the Amazon Product Advertising API Scratchpad:
http://webservices.amazon.fr/scratchpad/index.html
discident-glib/test-diglib.c | 36 +++++++++++++++++++++++++++++++++---
1 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/discident-glib/test-diglib.c b/discident-glib/test-diglib.c
index fcc8f6b..b57c6ba 100644
--- a/discident-glib/test-diglib.c
+++ b/discident-glib/test-diglib.c
@@ -345,14 +345,44 @@ bail:
g_main_loop_quit (loop);
}
+static void
+load_from_config (void)
+{
+ GKeyFile *key_file;
+ char *config_path;
+
+ config_path = g_build_filename (g_get_user_config_dir (),
+ "discident-glib",
+ "amazon-config.ini",
+ NULL);
+ key_file = g_key_file_new ();
+ if (!g_key_file_load_from_file (key_file, config_path, G_KEY_FILE_NONE, NULL)) {
+ g_test_skip ("Could not load Amazon config file");
+ g_free (config_path);
+ g_key_file_unref (key_file);
+ return;
+ }
+ g_free (config_path);
+
+ if (!access_key)
+ access_key = g_key_file_get_string (key_file, "amz", DISCIDENT_PARAM_ACCESS_KEY, NULL);
+ if (!private_key)
+ private_key = g_key_file_get_string (key_file, "amz", DISCIDENT_PARAM_PRIVATE_KEY, NULL);
+ if (!associate_tag)
+ associate_tag = g_key_file_get_string (key_file, "amz", DISCIDENT_PARAM_ASSOCIATE_TAG, NULL);
+
+ g_key_file_unref (key_file);
+}
+
static GHashTable *
create_params (void)
{
GHashTable *params;
- if (!access_key &&
- !private_key &&
- !associate_tag)
+ if (!access_key || !private_key || !associate_tag)
+ load_from_config ();
+
+ if (!access_key || !private_key || !associate_tag)
return NULL;
params = g_hash_table_new (g_str_hash, g_str_equal);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]