From 4671027d90f0da3b70dfa5f1ac84ddc84bb09aab Mon Sep 17 00:00:00 2001 From: Gonzalo Zawadzki Date: Thu, 16 Jun 2016 15:34:55 +0100 Subject: [PATCH] Add signature list to avoid duplicate code --- LearnositySDK/Request/Init.cs | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/LearnositySDK/Request/Init.cs b/LearnositySDK/Request/Init.cs index 25d8403..87695c1 100755 --- a/LearnositySDK/Request/Init.cs +++ b/LearnositySDK/Request/Init.cs @@ -403,33 +403,23 @@ private void setServiceOptions() JsonObject questionsApiActivity = new JsonObject(); - string[] arrayToHash; + List signatureList = new List(); + + signatureList.Add(this.securityPacket.getString("consumer_key")); + signatureList.Add(domain); + signatureList.Add(this.securityPacket.getString("timestamp")); if (Tools.array_key_exists("expires", this.securityPacket)) { - arrayToHash = new string[] { - this.securityPacket.getString("consumer_key"), - domain, - this.securityPacket.getString("timestamp"), - this.securityPacket.getString("expires"), - this.securityPacket.getString("user_id"), - this.secret - }; - + signatureList.Add(this.securityPacket.getString("expires")); questionsApiActivity.set("expires", this.securityPacket.getString("expires")); questionsApi.remove("expires"); } - else { - arrayToHash = new string[] { - this.securityPacket.getString("consumer_key"), - domain, - this.securityPacket.getString("timestamp"), - this.securityPacket.getString("user_id"), - this.secret - }; - } - - string signature = this.hashValue(arrayToHash); + + signatureList.Add(this.securityPacket.getString("user_id")); + signatureList.Add(this.secret); + + string signature = this.hashValue(signatureList.ToArray()); questionsApiActivity.set("consumer_key", this.securityPacket.getString("consumer_key")); questionsApiActivity.set("timestamp", this.securityPacket.getString("timestamp"));