public WrappedData DataRequest(cleverRequestType requestType) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name + "_1"; ////////////////////////////////////////////////////////////// //// Example for "https://api.clever.com/v1.1/students" //// ////////////////////////////////////////////////////////////// string msg = string.Format("reqType: {0}", requestType); mLogger.Log(methodName, msg, 1); string cleverObjType = requestType.ToString().ToLower() + "s"; // toLower() used to handle Events WrappedData wrappedData = new WrappedData(); string url = string.Format(@"https://api.clever.com/v1.1/{0}s", requestType.ToString().ToLower()); // toLower() used to handle Events mLogger.Log(methodName, "url: " + url, 2); // Send built URl to Clever and hopefully, we get a message containing the expected data string rawData = GetRawDataFromClever(url); if (string.IsNullOrEmpty(rawData)) { mLogger.Log(methodName, "Unexpected Error !! The message from Clever appears to be empty or was not properly extracted from the stream.", 1); throw new System.ApplicationException("The message from Clever appears to be empty or was not properly extracted from the stream."); } // The parser will translate the JSON msg and generate the Clever objects (Students, Teachers, ect) all contained in the parent object - wrappedData Parser parser = new Parser(mLogger); wrappedData = parser.ParseJsonMsg(rawData, cleverObjType); return(wrappedData); }
public WrappedData DataRequest(cleverRequestType requestType) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name + "_1"; ////////////////////////////////////////////////////////////// //// Example for "https://api.clever.com/v1.1/students" //// ////////////////////////////////////////////////////////////// string msg = string.Format("reqType: {0}", requestType); mLogger.Log(methodName, msg, 1); string cleverObjType = requestType.ToString().ToLower() + "s"; // toLower() used to handle Events WrappedData wrappedData = new WrappedData(); string url = string.Format(@"https://api.clever.com/v1.1/{0}s", requestType.ToString().ToLower()); // toLower() used to handle Events mLogger.Log(methodName, "url: " + url, 2); // Send built URl to Clever and hopefully, we get a message containing the expected data string rawData = GetRawDataFromClever(url); if (string.IsNullOrEmpty(rawData)) { mLogger.Log(methodName, "Unexpected Error !! The message from Clever appears to be empty or was not properly extracted from the stream.", 1); throw new System.ApplicationException("The message from Clever appears to be empty or was not properly extracted from the stream."); } // The parser will translate the JSON msg and generate the Clever objects (Students, Teachers, ect) all contained in the parent object - wrappedData Parser parser = new Parser(mLogger); wrappedData = parser.ParseJsonMsg(rawData, cleverObjType); return wrappedData; }
public WrappedData DataRequest(cleverRequestType requestType, List <KeyValuePair <String, String> > kvpList) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// Example for "https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005?include=schools,teachers" //// //// Example for "https://api.clever.com/v1.1/students?limit=120" //// //// Example for "https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005" //// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name + "_2"; string cleverObjType = string.Empty; string url = string.Empty; string msg = string.Format("reqType: {0} :: List<string> count: {1}", requestType, kvpList.Count); mLogger.Log(methodName, msg, 1); WrappedData wrappedData = new WrappedData(); Tuple <string, string, bool> kvpStrTuple = mHelper.ConvertKvpToStringAndValidate(mLogger, kvpList); string kvpStr = kvpStrTuple.Item1; string id = kvpStrTuple.Item2; bool stringifySuccess = kvpStrTuple.Item3; // // Final Validation // if (!stringifySuccess) { mLogger.Log(methodName, "Error !! The list argument (Clever parameter items) contains at least one invalid value.", 1); throw new System.ArgumentException(string.Format("The list argument (Clever parameter items) contains at least one invalid value. For more details, see log at: {0}", mLogger.mLogFile)); } if (kvpList.Count < 1) { mLogger.Log(methodName, "Error !! The list argument (Clever parameter items) contains NO items.", 1); throw new System.ArgumentException(string.Format("The list argument (Clever parameter items) contains NO items.")); } if (string.IsNullOrEmpty(id)) { if (kvpStr.Contains("include=")) { mLogger.Log(methodName, "Error !! The 'id' value is empty and user attempted to use Clever include item (second-level endpoint). There must be an 'id' when using 'include'.", 1); throw new System.ArgumentException("The 'id' value is empty and user attempted to use Clever include item (second-level endpoint). There must be an 'id' when using 'include'."); } } if (!kvpStr.Contains("include=")) { // We know the return object should be reqType, so pass that along in case it is needed cleverObjType = requestType.ToString().ToLower() + "s"; } mLogger.Log(methodName, string.Format("Successfully validated list of KeyValuePairs and converted to a string: {0}", kvpStr), 1); if (string.IsNullOrEmpty(id)) { url = string.Format(@"https://api.clever.com/v1.1/{0}s?{1}", requestType.ToString().ToLower(), kvpStr); } else { if (string.IsNullOrEmpty(kvpStr)) { url = string.Format(@"https://api.clever.com/v1.1/{0}s/{1}", requestType.ToString().ToLower(), id); } else { url = string.Format(@"https://api.clever.com/v1.1/{0}s/{1}?{2}", requestType.ToString().ToLower(), id, kvpStr); } } mLogger.Log(methodName, "url: " + url, 2); // Send built URl to Clever and hopefully, we get a message containing the expected data string rawData = GetRawDataFromClever(url); if (string.IsNullOrEmpty(rawData)) { mLogger.Log(methodName, "Unexpected Error !! The message from Clever appears to be empty or was not properly extracted from the stream.", 1); throw new System.ApplicationException("The message from Clever appears to be empty or was not properly extracted from the stream."); } // The parser will translate the JSON msg and generate the Clever objects (Students, Teachers, ect) all contained in the parent object - wrappedData Parser parser = new Parser(mLogger); wrappedData = parser.ParseJsonMsg(rawData, cleverObjType); return(wrappedData); }
public WrappedData DataRequest(cleverRequestType requestType, List<KeyValuePair<String, String>> kvpList) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// Example for "https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005?include=schools,teachers" //// //// Example for "https://api.clever.com/v1.1/students?limit=120" //// //// Example for "https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005" //// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name + "_2"; string cleverObjType = string.Empty; string url = string.Empty; string msg = string.Format("reqType: {0} :: List<string> count: {1}", requestType, kvpList.Count); mLogger.Log(methodName, msg, 1); WrappedData wrappedData = new WrappedData(); Tuple<string, string, bool> kvpStrTuple = mHelper.ConvertKvpToStringAndValidate(mLogger, kvpList); string kvpStr = kvpStrTuple.Item1; string id = kvpStrTuple.Item2; bool stringifySuccess = kvpStrTuple.Item3; // // Final Validation // if (!stringifySuccess) { mLogger.Log(methodName, "Error !! The list argument (Clever parameter items) contains at least one invalid value.", 1); throw new System.ArgumentException(string.Format("The list argument (Clever parameter items) contains at least one invalid value. For more details, see log at: {0}", mLogger.mLogFile)); } if (kvpList.Count < 1) { mLogger.Log(methodName, "Error !! The list argument (Clever parameter items) contains NO items.", 1); throw new System.ArgumentException(string.Format("The list argument (Clever parameter items) contains NO items.")); } if (string.IsNullOrEmpty(id)) { if (kvpStr.Contains("include=")) { mLogger.Log(methodName, "Error !! The 'id' value is empty and user attempted to use Clever include item (second-level endpoint). There must be an 'id' when using 'include'.", 1); throw new System.ArgumentException("The 'id' value is empty and user attempted to use Clever include item (second-level endpoint). There must be an 'id' when using 'include'."); } } if (!kvpStr.Contains("include=")) { // We know the return object should be reqType, so pass that along in case it is needed cleverObjType = requestType.ToString().ToLower() + "s"; } mLogger.Log(methodName, string.Format("Successfully validated list of KeyValuePairs and converted to a string: {0}", kvpStr), 1); if (string.IsNullOrEmpty(id)) { url = string.Format(@"https://api.clever.com/v1.1/{0}s?{1}", requestType.ToString().ToLower(), kvpStr); } else { if (string.IsNullOrEmpty(kvpStr)) { url = string.Format(@"https://api.clever.com/v1.1/{0}s/{1}", requestType.ToString().ToLower(), id); } else { url = string.Format(@"https://api.clever.com/v1.1/{0}s/{1}?{2}", requestType.ToString().ToLower(), id, kvpStr); } } mLogger.Log(methodName, "url: " + url, 2); // Send built URl to Clever and hopefully, we get a message containing the expected data string rawData = GetRawDataFromClever(url); if (string.IsNullOrEmpty(rawData)) { mLogger.Log(methodName, "Unexpected Error !! The message from Clever appears to be empty or was not properly extracted from the stream.", 1); throw new System.ApplicationException("The message from Clever appears to be empty or was not properly extracted from the stream."); } // The parser will translate the JSON msg and generate the Clever objects (Students, Teachers, ect) all contained in the parent object - wrappedData Parser parser = new Parser(mLogger); wrappedData = parser.ParseJsonMsg(rawData, cleverObjType); return wrappedData; }