/// <summary> /// Will call the Qualtric's Target Audience API createUser. /// </summary> /// <param name="member">The member.</param> /// <returns></returns> internal void CreateUserProcess(ASAMemberModel member) { const string logMethodName = ".CreateUserProcess(ASAMemberModel member) - "; Log.Debug(logMethodName + "Begin Method"); string QTA_Process = Common.Config.QTA_Process; if (QTA_Process.ToLower() == "on") { Log.Info(logMethodName + "Qualtrics TA Process on - request attempt will be made"); //https://survey.qualtrics.com/WRAPI/Contacts/api.php?Request=createContact&Format=JSON&Version=2.3&User=APIDevelopment&Token=ZyEeqfR9oFI9bTOu1tzWNWQ43my7elCNXBe6Ql8b&LibraryID=GR_6r0To7ELRwsmMfP&ListID=CG_dbUMDRYesJ0MCot&[email protected]&FirstName=Todd&LastName=Leslie&ExternalDataRef=Id12346&ED[Contact]=true&ED[Org0]=Org-99999&ED[Org1]=Org-77777&ED[Org2]=Org-55555&ED[Org3]=Org-33333&ED[Org4]=Org-11111&ED[Org5]=&ED[Org6]=&ED[Org7]=&ED[Org8]=&ED[Org9]= String urlToRequest = BuildUrlString("createContact"); urlToRequest += BuildDataString(member); Log.Debug(logMethodName + "Request - " + urlToRequest); HttpsRequestProvider httpsRequestProvider = new HttpsRequestProvider(); string responseString = httpsRequestProvider.sendRequestToQualtricsTA(urlToRequest); } else { Log.Info(logMethodName + "Qualtrics TA Process off - request not made"); } Log.Debug(logMethodName + "End Method"); }
public Stream submitChoicesToUnigo(UnigoChoicesModel choices) { //The WebRequest expects the "body" of the request as a stream //We need to convert the choices object passed in to an array of bytes, which can be written to the outgoing stream MemoryStream responseStream = null; try { String responseString; using (MemoryStream choicesStream = new MemoryStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(string[])); serializer.WriteObject(choicesStream, choices.choices); byte[] choicesAsBytes = choicesStream.ToArray(); // Get the stream containing content returned by the server. string urlToRequest = Config.ScholarshipApiURL + "scholarships?auth=" + Config.ScholarshipApiToken; HttpsRequestProvider httpsProvider = new HttpsRequestProvider(); responseString = httpsProvider.postChoicesToUnigo(choicesAsBytes, urlToRequest); } responseStream = new MemoryStream(Encoding.UTF8.GetBytes(responseString)); } catch (Exception ex) { _log.Error("ASA.Web.Services.SearchService.submitChoicesToUnigo(): Exception =>" + ex.ToString()); throw new Exception("Web Search Service - submitChoicesToUnigo()", ex); } if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.ContentType = "application/json"; } return(responseStream); }
/// <summary> /// Will call the Qualtric's Target Audience API getContactByInfoFields if user exists /// then updateContact will be call otherwise createContact will be called. /// </summary> /// <param name="member">The member.</param> /// <returns></returns> internal void UpdateUserProcess(ASAMemberModel member) { const string logMethodName = ".UpdateUserProcess(ASAMemberModel member) - "; Log.Debug(logMethodName + "Begin Method"); string QTA_Process = Common.Config.QTA_Process; if (QTA_Process.ToLower() == "on") { Log.Info(logMethodName + "Qualtrics TA Process on - request attempt will be made"); //"https://survey.qualtrics.com/WRAPI/Contacts/api.php?Request=getContactByInfoFields&Format=JSON&Version=2.3&User=APIDevelopment&Token=ZyEeqfR9oFI9bTOu1tzWNWQ43my7elCNXBe6Ql8b&ExternalDataRef=1934"; String urlToRequest = BuildUrlString("getContactByInfoFields"); String dataPart = String.Format("&ExternalDataRef={0}", member.MembershipId); urlToRequest += dataPart; Log.Debug(logMethodName + "Request - " + urlToRequest); HttpsRequestProvider httpsRequestProvider = new HttpsRequestProvider(); string responseString = httpsRequestProvider.sendRequestToQualtricsTA(urlToRequest); //covert response to JSON object JObject responseAsJSON = new JObject(); responseAsJSON = JObject.Parse(responseString); string returnStatus = responseAsJSON["Meta"].Any() ? (string)responseAsJSON["Meta"]["Status"] : String.Empty; string contactId = responseAsJSON["Result"].Any() ? (string)responseAsJSON["Result"][0]["ContactId"] : String.Empty; if (returnStatus == "Success" && contactId != String.Empty) //update existing user { //https://survey.qualtrics.com/WRAPI/Contacts/api.php?Request=updateContact&Format=JSON&Version=2.3&User=APIDevelopment&Token=ZyEeqfR9oFI9bTOu1tzWNWQ43my7elCNXBe6Ql8b&LibraryID=GR_6r0To7ELRwsmMfP&ListID=CG_dbUMDRYesJ0MCot&ContactID=_0HA3IIsMONMkCkR&Email=somename%2540example.com urlToRequest = BuildUrlString("updateContact"); dataPart = String.Format("&ContactID={0}", contactId); dataPart += BuildDataString(member); urlToRequest += dataPart; Log.Debug(logMethodName + "Request - " + urlToRequest); responseString = httpsRequestProvider.sendRequestToQualtricsTA(urlToRequest); } else { //no user found so insert/create one. CreateUserProcess(member); } } else { Log.Info(logMethodName + "Qualtrics TA Process off - request not made"); } Log.Debug(logMethodName + "End Method"); }
private static string MoodleServiceCall(string functionName, String postData) { const string logMethodName = ".MoodleServiceCall(string functionName, String postData) - "; _log.Debug(logMethodName + "Begin Method"); string restFormat = "json"; string coreParams = String.Format("?wstoken={0}&wsfunction={1}&moodlewsrestformat={2}", coursesServiceToken, functionName, restFormat); string requestUrl = string.Format(coursesServiceUrl + coreParams); string requestMethod = "POST"; //"GET"; string contentType = "application/x-www-form-urlencoded"; //"application/json"; // Encode the parameters as form data: byte[] formDataAsBytes = UTF8Encoding.UTF8.GetBytes(postData); bool bKeepAlive = false; string responseEncodingFormat = "UTF-8"; HttpsRequestProvider httpsProvider = new HttpsRequestProvider(); string responseString = httpsProvider.DoHttpsWebRequest(requestUrl, requestMethod, contentType, formDataAsBytes, bKeepAlive, responseEncodingFormat); _log.Debug(logMethodName + "End Method"); return(responseString); }
public Stream getIndividualScholarship(string id) { MemoryStream responseStream = null; string urlToRequest = Config.ScholarshipApiURL + "scholarship?scholarshipID=" + id + "&auth=" + Config.ScholarshipApiToken; try { HttpsRequestProvider httpsProvider = new HttpsRequestProvider(); String responseString = httpsProvider.getScholarshipData(urlToRequest); responseStream = new MemoryStream(Encoding.UTF8.GetBytes(responseString)); } catch (Exception ex) { _log.Error("ASA.Web.Services.SearchService.getIndividualScholarship(): Exception =>" + ex.ToString()); throw new Exception("Web Search Service - getIndividualScholarship()", ex); } if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.ContentType = "application/json"; } return(responseStream); }