Skip to content

Commit

Permalink
Add signature list to avoid duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Zawadzki committed Jun 16, 2016
1 parent 0848451 commit 4671027
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions LearnositySDK/Request/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,33 +403,23 @@ private void setServiceOptions()

JsonObject questionsApiActivity = new JsonObject();

string[] arrayToHash;
List<string> signatureList = new List<string>();

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"));
Expand Down

0 comments on commit 4671027

Please sign in to comment.