/// <summary> /// Generate the data necessary to make a request to quesetions service. /// </summary> /// <param name="output"></param> /// <returns></returns> private JsonObject generateQuestions(JsonObject output) { output = this.securityPacket; output.remove("domain"); if (!Tools.empty(this.requestPacket)) { output = JsonObjectFactory.merge(output, this.requestPacket, false, false); } return(output); }
/// <summary> /// Set any options for services that aren't generic /// </summary> private void setServiceOptions() { switch (this.service) { case "assess": // fall-through case "questions": this.signRequestData = false; if (this.service == "assess" && Tools.array_key_exists("questionsApiActivity", this.requestPacket)) { JsonObject questionsApi = this.requestPacket.getJsonObject("questionsApiActivity"); if (questionsApi == null) { throw new Exception("requestPacket['questionsApiActivity'] is not an array"); } string domain = "assess.learnosity.com"; if (Tools.array_key_exists("domain", this.securityPacket)) { domain = this.securityPacket.getString("domain"); } else if (Tools.array_key_exists("domain", questionsApi)) { domain = questionsApi.getString("domain"); } JsonObject questionsApiActivity = new JsonObject(); 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)) { signatureList.Add(this.securityPacket.getString("expires")); questionsApiActivity.set("expires", this.securityPacket.getString("expires")); questionsApi.remove("expires"); } 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")); questionsApiActivity.set("user_id", this.securityPacket.getString("user_id")); questionsApiActivity.set("signature", signature); questionsApi.remove("domain"); questionsApi.remove("consumer_key"); questionsApi.remove("timestamp"); questionsApi.remove("user_id"); questionsApi.remove("signature"); questionsApiActivity = JsonObjectFactory.merge(questionsApiActivity, questionsApi); this.requestPacket.set("questionsApiActivity", questionsApiActivity); } break; case "items": // fall-through case "reports": if (!Tools.array_key_exists("user_id", this.securityPacket) && Tools.array_key_exists("user_id", this.requestPacket)) { this.securityPacket.set("user_id", this.requestPacket.getString("user_id")); } break; case "events": string consumer_key = this.securityPacket.getString("consumer_key"); JsonObject hashedUsers; this.signRequestData = false; JsonObject requestPackageUsers = this.requestPacket.getJsonObject("users"); if (requestPackageUsers != null) { string[] users = requestPackageUsers.getValuesArray(); if (users != null && users.Length > 0) { hashedUsers = new JsonObject(); for (int i = 0; i < users.Length; i++) { string user_id = users[i]; hashedUsers.set(user_id, Tools.hash(this.algorithm, user_id + this.secret)); } this.requestPacket.set("users", hashedUsers); } } break; default: // do nothing break; } }